[Mod]Frame - lag-free non-entity item frames![frame]

sofar
Member
 
Posts: 781
Joined: Fri Jan 16, 2015 07:31
GitHub: sofar
IRC: sofar
In-game: sofar

[Mod]Frame - lag-free non-entity item frames![frame]

by sofar » Sat Feb 04, 2017 09:33

Similar to the flowerpot, I've made a new item frame that does not use entities. It should make it possible for multiplayer servers to use item frames without adding lag or much extra loading time, while still offering a large amount of item frame possibilities.

The item frame will either display the items put in them (nodes or craftitems) as block (including separate top/bottom/side textures) or as flat image (but not wielditem view, just flat).

The trick is that just like the flowerpot, there's just one mesh node with 5 different materials, and depending on what you put in there, you get a node with those textures changed from transparent to the item textures.

The downside is extra nodes. But, extra nodes are a lot more efficient than entities.

The nodes store itemstack metadata and wear, so written books will remain written books, and tools with wear will come out with the wear back.

This probably needs more testing, and it's likely missing nodes and not working with some (e.g. nodes that capture rightclick wrong).

Crafting recipe:

Image

Image

Download: https://github.com/minetest-mods/frame/ ... master.zip
Code: https://github.com/minetest-mods/frame
License(s): LGPL-2.1+, CC-BY-SA-3.0, Public-Domain
 

Hybrid Dog
Member
 
Posts: 2460
Joined: Thu Nov 01, 2012 12:46

by Hybrid Dog » Sat Feb 04, 2017 10:05

l think to keep toolwear, metadata, whatsoever, you could simply use stack:to_string() and save the result to meta.
 

User avatar
azekill_DIABLO
Member
 
Posts: 3458
Joined: Wed Oct 29, 2014 20:05
GitHub: azekillDIABLO
In-game: azekill_DIABLO

Re: [Mod]Frame - lag-free non-entity item frames![frame]

by azekill_DIABLO » Sat Feb 04, 2017 14:20

awesome! the fact this not 3d for items is not a problem at all!
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
Hi, my username is azekill_DIABLO and i'm an exelent bug-maker(yeah...i know...i have a bad reputation)

azekill_DIABLO said: Mineyoshi+ABJ+Baggins= TOPIC HIJACKED.
My Mods and Stuff | Voxellar | VoxBox on GITHUB | M.I.L.A Monster engine
WEIRD MODDING CONTEST !!!
 

User avatar
D00Med
Member
 
Posts: 712
Joined: Sat Feb 07, 2015 22:49
GitHub: D00Med

Re: [Mod]Frame - lag-free non-entity item frames![frame]

by D00Med » Sat Feb 04, 2017 20:17

extra nodes are a lot more efficient than entities.

Is it really more efficient to make lots of nodes rather than a few entities that can swap their textures? (I ask this in a general sense, not specifically for itemframes)
Look! I have a signature :]
My subgame: https://forum.minetest.net/viewtopic.php?f=15&t=14051#p207242
dmobs2 is coming...
 

sofar
Member
 
Posts: 781
Joined: Fri Jan 16, 2015 07:31
GitHub: sofar
IRC: sofar
In-game: sofar

Re: [Mod]Frame - lag-free non-entity item frames![frame]

by sofar » Sat Feb 04, 2017 21:14

D00Med wrote:
extra nodes are a lot more efficient than entities.

Is it really more efficient to make lots of nodes rather than a few entities that can swap their textures? (I ask this in a general sense, not specifically for itemframes)


entities have several major drawbacks:

- they're as heavy on a server as players, and thus consume a lot of lua memory, generate lag, require on_step() callbacks etc.
- they can get lost. /clearobjects kills them
- they can get punched by players or killed (making them immortal prevents most of this, but still)
- they can get lost if the mapblock saving goes wrong
- they don't appear immediately when you enter an area, it could take forever for them to show up
- they require lots of extra code (fragile) to work around all these issues, and then still there are issues (just ask the itemframe mod makers that have made one before).

So yes, a few mode nodedefs is a far more efficient and reliable way to do this. It entirely avoids all the problems that entity based frames have. And the cost per node is not that large, since we're only adding one nodedef which compresses to a single network packet, and we don't use any new textures.
 

User avatar
D00Med
Member
 
Posts: 712
Joined: Sat Feb 07, 2015 22:49
GitHub: D00Med

Re: [Mod]Frame - lag-free non-entity item frames![frame]

by D00Med » Sat Feb 04, 2017 22:09

Ok then, thanks for the explanation.
Look! I have a signature :]
My subgame: https://forum.minetest.net/viewtopic.php?f=15&t=14051#p207242
dmobs2 is coming...
 

sofar
Member
 
Posts: 781
Joined: Fri Jan 16, 2015 07:31
GitHub: sofar
IRC: sofar
In-game: sofar

Re:

by sofar » Sat Feb 11, 2017 06:09

Hybrid Dog wrote:l think to keep toolwear, metadata, whatsoever, you could simply use stack:to_string() and save the result to meta.


I've changed over to use this method, but somewhat different. I need an ItemStack table (not a string) to get the full metadata back with the new itemstack format, so I serialize it before storing it in nodemeta. This then allows me to get it back entirely.

strike that, that was not very thoughtful. I need to think some more to make the new item meta work well
 

User avatar
Wuzzy
Member
 
Posts: 2161
Joined: Mon Sep 24, 2012 15:01
GitHub: Wuzzy2
IRC: Wuzzy
In-game: Wuzzy

Re: [Mod]Frame - lag-free non-entity item frames![frame]

by Wuzzy » Sat Feb 11, 2017 11:51

Lag-free itemframes sounds really cool, especially important for servers. It's annoying that the items are invisible unless you stand 2 cm in front of the item frame. xD

Having not tested it so far, does this work with boats, carts, water buckets, lava buckets, wheat seed and cotton seed from Minetest Game? Because other item frames fail for these items.

I'm not really happy how the flat items look like on the frame. I actually like the design of items “popping” out of the frame. But I fear that's the price we have to pay. :-/

On the other hand, is it really a good idea to avoid entities at all costs? Maybe the real fix should be done in the engine, by making entities more efficient, less laggy and less buggy in general.

EDIT:
No, sorry. This mod is no alternative for MineClone 2 so far. Support for items is way too limited, so I wouldn't even use it on a server either. A good item frame mod should support as many items as possible (ideally all of them).

Many items are not supported:

  • Stairs
  • Slabs
  • Fences
  • Fence Gates
  • Beds
  • Seeds
  • Chests
  • Flower pots from [flowerpot]
  • Walls
  • Iron bar and glasspane (xpanes)
  • Cart
  • Boat
  • Key, Skeleton Key
  • Screwdriver (rotates item frame instead)

Bugs:
- The same grass drop bug as in your flowerpot mod
- Leaves are flat instead of cubic
- Placing a water source, lava source or river water source looks very weird. Probably because they're animated?
- The dropped item has a bad appearance (faces missing on the backside when it rotates)

Fun fact: The furnace is seen from the backside instead of the front. XD

EDIT 2:
For MineClone 2, I probably stick with the original mod for now. If you can find a way how to fix this rightclick issue, that would be a great help already.

Some suggestions:
- I would change the item name (“description” field) to “Item Frame”. This is the name which most players would recognize and understand. “Frame” sounds overly generic. Note: The mod name is OK.
- Add a inventory image. This also fixes the issue with the appearance of the dropped item
- Make the node wallmounted/attached (like a sign), so it doesn't float
- Make the node non-walkable, otherwise the player can use item frames to climb up walls. xD
- Use rightclick to make item pop out, intead of punching. I think this feels more natural. IMO I think rightclick should generally be seen as the “interaction” key by nodes, not punching, as this doesn't conflict with mining.
I'm creating MineClone 2, a Minecraft clone for Minetest.
I made the Help modpack, adding in-game help to Minetest.
 

sofar
Member
 
Posts: 781
Joined: Fri Jan 16, 2015 07:31
GitHub: sofar
IRC: sofar
In-game: sofar

Re: [Mod]Frame - lag-free non-entity item frames![frame]

by sofar » Sat Feb 11, 2017 19:46

No, sorry. This mod is no alternative for MineClone 2 so far. Support for items is way too limited, so I wouldn't even use it on a server either. A good item frame mod should support as many items as possible (ideally all of them).


You know, you write this in a fashion which is entirely demoralizing and fails to acknowledge all the work I do addressing concerns that people raise.
 

sofar
Member
 
Posts: 781
Joined: Fri Jan 16, 2015 07:31
GitHub: sofar
IRC: sofar
In-game: sofar

Re: [Mod]Frame - lag-free non-entity item frames![frame]

by sofar » Sat Feb 11, 2017 20:39

Lag-free itemframes sounds really cool, especially important for servers. It's annoying that the items are invisible unless you stand 2 cm in front of the item frame. xD


you mean, that was an issue with other itemframe mods?

Having not tested it so far, does this work with boats, carts, water buckets, lava buckets, wheat seed and cotton seed from Minetest Game? Because other item frames fail for these items.


This mod works with them just fine, but the boats and bed mods for instance do not properly propagate the on_rightclick to the node, so this is a minetest_game bug (which I obviously intend to fix).

/giveme frame:boats_boat

I'm not really happy how the flat items look like on the frame. I actually like the design of items “popping” out of the frame. But I fear that's the price we have to pay. :-/


I could fix this, but it would break 32px texture pack support and come at the cost of a *lot* of triangles (1500 or so for a 16px compatible frame, 12000 triangles for a 32px compatible one!). I'm not willing to do that just yet - maybe later.

On the other hand, is it really a good idea to avoid entities at all costs? Maybe the real fix should be done in the engine, by making entities more efficient, less laggy and less buggy in general.


While making entities more robust, they are always going to consume lua execution time and require globalstep maintenance.

Many items are not supported:

  • Stairs
  • Slabs
  • Fences
  • Fence Gates
  • Walls


would require me to make another *mesh* to support those shapes. That means more modelling work, and at this time I don't think that it's reasonable. It also means even more registered nodes, I just don't think that's important right now (yet).

  • Beds
  • Seeds
  • Chests
  • Cart
  • Boat
  • Key, Skeleton Key


  • These work but all need mtg to be fixed (/giveme ..)

  • Flower pots from [flowerpot]
  • Iron bar and glasspane (xpanes)


  • Added, these were just forgotten (I'm fairly sure there's more I have not included yet)

  • Screwdriver (rotates item frame instead)


  • half of these are bugs. Cart, boat are supported, but minetest_game doesn't pass the on_rightclick through, as I said above (and I will attempt to fix this)

    You don't want your itemframe rotated? I thought that was pretty neat that it could. Obviously shift-right click may be something we need to implement on some items.

    Bugs:
    - The same grass drop bug as in your flowerpot mod


    I'll fix that up to stay in the spirit of minetest_game

    - Leaves are flat instead of cubic


    I can probably fix that

    - Placing a water source, lava source or river water source looks very weird. Probably because they're animated?


    yes, the current texture selection algorithm doesn't handle it yet, but I think I can actually make it look like an animated water cube, except that the transparency would be an issue, so I'm not sure what I'll do with this.

    - The dropped item has a bad appearance (faces missing on the backside when it rotates)


    Yes, and an inventory image is trivial, so this will be fixed in a sec.

    Fun fact: The furnace is seen from the backside instead of the front. XD


    spotted that, sadly the "front" texture is tile number 6, not 3. Yet more complex tile handling code coming.


    - I would change the item name (“description” field) to “Item Frame”. This is the name which most players would recognize and understand. “Frame” sounds overly generic. Note: The mod name is OK.


    sure

    - Add a inventory image. This also fixes the issue with the appearance of the dropped item


    done, it's the same as the mesh texture anyway

    - Make the node wallmounted/attached (like a sign), so it doesn't float


    I Can't make it attached_node, since then it can't hang on a wall. Making it wallmounted would make it not rotatable! I don't like either of these options. I agree it should fall if the node backing it disappears, but I don't see how I can do that without sacrificing something else yet.

    - Make the node non-walkable, otherwise the player can use item frames to climb up walls. xD


    This... I don't know. This is more of a personal taste thing if you ask me. For 99% of the time, the frames are probably going to be inside peoples houses as decoration, and this won't be a concern.

    - Use rightclick to make item pop out, intead of punching. I think this feels more natural. IMO I think rightclick should generally be seen as the “interaction” key by nodes, not punching, as this doesn't conflict with mining.


    This... I also don't know about. To me, digging means "getting something out" and right clicking means "putting something out/in". You didn't comment on this with the flowerpot, which also uses left/dig right/place controls, so I'm not convinced.

    As usual, thanks for the review, this is really useful and I think I can address most of the comments really quickly.
     

    sofar
    Member
     
    Posts: 781
    Joined: Fri Jan 16, 2015 07:31
    GitHub: sofar
    IRC: sofar
    In-game: sofar

    Re: [Mod]Frame - lag-free non-entity item frames![frame]

    by sofar » Sat Feb 11, 2017 20:43

    FYI, If `meta set nodedef` ever makes it into minetest_game, It will solve so many issues that remain, and things like stairs, slabs, walls and fences become very reasonable to include in this mod.

    https://github.com/minetest/minetest/pull/1118

    Having that PR will allow me to use ONE node for all itemframes and vary mesh and tiles from metedata. Since at that point the amount of nodes drops to 3, 2 or even 1 total for all frames, it wouldn't be horrible to include 5-6 different meshes that capture all the other node shapes...
     

    sofar
    Member
     
    Posts: 781
    Joined: Fri Jan 16, 2015 07:31
    GitHub: sofar
    IRC: sofar
    In-game: sofar

    Re: [Mod]Frame - lag-free non-entity item frames![frame]

    by sofar » Sun Feb 12, 2017 00:26

    https://github.com/minetest/minetest_game/pull/1563

    Fix for minetest_game's issues with right click. I omitted the screwdriver, but this fixes boats, beds, seeds, carts and keys.
     

    User avatar
    Wuzzy
    Member
     
    Posts: 2161
    Joined: Mon Sep 24, 2012 15:01
    GitHub: Wuzzy2
    IRC: Wuzzy
    In-game: Wuzzy

    Re: [Mod]Frame - lag-free non-entity item frames![frame]

    by Wuzzy » Sun Feb 12, 2017 01:35

    FYI, If `meta set nodedef` ever makes it into minetest_game, It will solve so many issues that remain, and things like stairs, slabs, walls and fences become very reasonable to include in this mod.

    YES! This is definitely the right way to go. This issue is on my watchlist.

    I start to think that the real problem does not lie in the mod, but in Minetest which makes it very hard to make an item frame mod without rightclicking mess. meta set nodedef, and a fix for the rightclick stuff in the engine, then it's green light for item frames. :-)

    https://github.com/minetest/minetest_game/pull/1563

    Fix for minetest_game's issues with right click. I omitted the screwdriver, but this fixes boats, beds, seeds, carts and keys.

    Thx for taking your time, I posted a lenghty reply there.

    Also thanks for all the other bugfixes and improvements so far. :-)

    I Can't make it attached_node, since then it can't hang on a wall. Making it wallmounted would make it not rotatable! I don't like either of these options. I agree it should fall if the node backing it disappears, but I don't see how I can do that without sacrificing something else yet.

    Oh boy. I haven't thought of this. Good points.

    Screwdriver (rotates item frame instead)

    half of these are bugs. Cart, boat are supported, but minetest_game doesn't pass the on_rightclick through, as I said above (and I will attempt to fix this)

    You don't want your itemframe rotated? I thought that was pretty neat that it could. Obviously shift-right click may be something we need to implement on some items.

    Well, if screwdriver rotates an item frame on rightclick, then how do you put the screwdriver into the item frame?
    Shift-click seems like a solution on the surface, but too bad that shift-click is ALSO already used by the screwdriver. Boy, Minetest's controls are a mess! :D

    Many items are not supported:

    Stairs
    Slabs
    Fences
    Fence Gates
    Walls



    would require me to make another *mesh* to support those shapes. That means more modelling work, and at this time I don't think that it's reasonable. It also means even more registered nodes, I just don't think that's important right now (yet).

    Well, I already feared it would boil down to this. Entities are the answer to this, but then there's the lag issue again …
    What do you think about this idea? Making a mixed model. For flat or cube-shaped items, the current default meshes are used (and efficient), but for any other shape with no mesh, an entity is spawned. It's a trade-off between performance and trying to support as many items as possible.

    I'm probably just talking crazy here. The real fix would be the new Lua API function (set meta nodedef). :-)
    I'm creating MineClone 2, a Minecraft clone for Minetest.
    I made the Help modpack, adding in-game help to Minetest.
     

    sofar
    Member
     
    Posts: 781
    Joined: Fri Jan 16, 2015 07:31
    GitHub: sofar
    IRC: sofar
    In-game: sofar

    Re: [Mod]Frame - lag-free non-entity item frames![frame]

    by sofar » Sun Feb 12, 2017 03:15

    I Can't make it attached_node, since then it can't hang on a wall. Making it wallmounted would make it not rotatable! I don't like either of these options. I agree it should fall if the node backing it disappears, but I don't see how I can do that without sacrificing something else yet.

    Oh boy. I haven't thought of this. Good points.


    I actually ended up making it wallmounted+attached_node after all. We lose the screwdriver option but I prefer it popping off the wall.
     

    sofar
    Member
     
    Posts: 781
    Joined: Fri Jan 16, 2015 07:31
    GitHub: sofar
    IRC: sofar
    In-game: sofar

    Re: [Mod]Frame - lag-free non-entity item frames![frame]

    by sofar » Sun Feb 12, 2017 03:22

    Wuzzy wrote:
    Many items are not supported:

    Stairs
    Slabs
    Fences
    Fence Gates
    Walls

    would require me to make another *mesh* to support those shapes. That means more modelling work, and at this time I don't think that it's reasonable. It also means even more registered nodes, I just don't think that's important right now (yet).

    Well, I already feared it would boil down to this. Entities are the answer to this, but then there's the lag issue again …
    What do you think about this idea? Making a mixed model. For flat or cube-shaped items, the current default meshes are used (and efficient), but for any other shape with no mesh, an entity is spawned. It's a trade-off between performance and trying to support as many items as possible.

    I'm probably just talking crazy here. The real fix would be the new Lua API function (set meta nodedef). :-)


    So, from a practical point of view, the mod currently adds 251 nodes to the game (250 without flowerpot), and that's already outrageous (of course, they do look pretty good thus far).

    But stairs and slabs would add another 52. 10 for fences, 3 walls. 5 gates. Plus it would need much more complex mesh nodes, and custom code to handle all of those.

    Right now I can do 251 nodes in a single mesh (ok, maybe not 100% flawless), but it's extremely robust so far. I'd like to iron out the kinks before I add more meshes... I haven't heard from anyone yet who has actually deployed this or the flowerpot on a server, for instance.
     

    User avatar
    Wuzzy
    Member
     
    Posts: 2161
    Joined: Mon Sep 24, 2012 15:01
    GitHub: Wuzzy2
    IRC: Wuzzy
    In-game: Wuzzy

    Re: [Mod]Frame - lag-free non-entity item frames![frame]

    by Wuzzy » Sun Feb 12, 2017 09:28

    Right ...
    I totally forgot that for every item, a new node would be needed, because of the textures. Which essentially doubles the number of nodes. Holy cow!

    I guess I just wait until Minetest has some better Lua API support, then.
    Thanks for your time anyway.
    I'm creating MineClone 2, a Minecraft clone for Minetest.
    I made the Help modpack, adding in-game help to Minetest.
     

    sofar
    Member
     
    Posts: 781
    Joined: Fri Jan 16, 2015 07:31
    GitHub: sofar
    IRC: sofar
    In-game: sofar

    Re: [Mod]Frame - lag-free non-entity item frames![frame]

    by sofar » Sun Feb 12, 2017 20:57

    Wuzzy wrote:Right ...
    I totally forgot that for every item, a new node would be needed, because of the textures. Which essentially doubles the number of nodes. Holy cow!

    I guess I just wait until Minetest has some better Lua API support, then.
    Thanks for your time anyway.


    Remember, even with 250 node registrations, this is still far more reliable and performant than entity based item frames :)
     

    Sokomine
    Member
     
    Posts: 2980
    Joined: Sun Sep 09, 2012 17:31

    Re: [Mod]Frame - lag-free non-entity item frames![frame]

    by Sokomine » Sat Apr 01, 2017 04:24

    sofar wrote:Remember, even with 250 node registrations, this is still far more reliable and performant than entity based item frames :)

    Thanks for the mod. Reducing the amount of entities will certainly help. Admittedly, the more 3dish appearance of the older itemframe mod also looks very good. Maybe they can be combined? Use your version for the cubic nodes and whatever gets displayed well and the old one for other drawtypes?

    There's also the smartshop mod that offers up to four items in a shop. Probably too many possible combinations for thsi approach? I didn't take a look at the implementation yet.
    A list of my mods can be found here.
     

    sofar
    Member
     
    Posts: 781
    Joined: Fri Jan 16, 2015 07:31
    GitHub: sofar
    IRC: sofar
    In-game: sofar

    Re: [Mod]Frame - lag-free non-entity item frames![frame]

    by sofar » Sat Apr 01, 2017 06:33

    Sokomine wrote:Thanks for the mod. Reducing the amount of entities will certainly help. Admittedly, the more 3dish appearance of the older itemframe mod also looks very good. Maybe they can be combined?


    No, that view can currently only be obtained by using an entity to draw the "wieldmesh" appearance, and then you'd lose the benefit of the non-entity item frame entirely.

    Sokomine wrote:Use your version for the cubic nodes and whatever gets displayed well and the old one for other drawtypes?

    There's also the smartshop mod that offers up to four items in a shop. Probably too many possible combinations for thsi approach? I didn't take a look at the implementation yet.


    Once `node setmeta` is merged in core, that should be possible as well. With texture compositing, you could draw many nodes on a surface as long as it's smartly UV mapped and the texture string doesn't become too long.
     

    Byakuren
    Member
     
    Posts: 441
    Joined: Tue Apr 14, 2015 01:59
    GitHub: raymoo
    IRC: Hijiri

    Re: [Mod]Frame - lag-free non-entity item frames![frame]

    by Byakuren » Sat Apr 01, 2017 08:45

    From what I know about Minetest, Lua entity ticking just calls the on_step of every live lua entity. Wouldn't it be really cheap then (in terms of Lua execution time only) to have ten thousand entities with no on_step callbacks, since it just adds (a loop iteration + a few table accesses) times ten thousand, all in Lua?

    I feel that at least for the case of inert (does no API calls or other expensive operations in on_step) entities, Lua execution time is not the bottleneck. A bigger issue might be the 16-bit entity ID.

    EDIT: To reduce entity Lua cost even further, the code handling lua entities could keep a separate table for entities with non-nil on_step and only iterate on those. I don't think that is necessary though, because of my previous points.
    Every time a mod API is left undocumented, a koala dies.
     

    sofar
    Member
     
    Posts: 781
    Joined: Fri Jan 16, 2015 07:31
    GitHub: sofar
    IRC: sofar
    In-game: sofar

    Re: [Mod]Frame - lag-free non-entity item frames![frame]

    by sofar » Sat Apr 01, 2017 18:51

    Byakuren wrote:From what I know about Minetest, Lua entity ticking just calls the on_step of every live lua entity. Wouldn't it be really cheap then (in terms of Lua execution time only) to have ten thousand entities with no on_step callbacks, since it just adds (a loop iteration + a few table accesses) times ten thousand, all in Lua?


    The engine still needs to render all the entities separately, whereas the nodes are part of the mapblock mesh, and are rendered as one big mesh.

    So no matter what, nodes are far more efficient to render.
     

    Byakuren
    Member
     
    Posts: 441
    Joined: Tue Apr 14, 2015 01:59
    GitHub: raymoo
    IRC: Hijiri

    Re: [Mod]Frame - lag-free non-entity item frames![frame]

    by Byakuren » Sat Apr 01, 2017 23:03

    sofar wrote:
    Byakuren wrote:From what I know about Minetest, Lua entity ticking just calls the on_step of every live lua entity. Wouldn't it be really cheap then (in terms of Lua execution time only) to have ten thousand entities with no on_step callbacks, since it just adds (a loop iteration + a few table accesses) times ten thousand, all in Lua?


    The engine still needs to render all the entities separately, whereas the nodes are part of the mapblock mesh, and are rendered as one big mesh.

    So no matter what, nodes are far more efficient to render.

    Alright, that makes sense. I was just responding to your
    sofar wrote:While making entities more robust, they are always going to consume lua execution time and require globalstep maintenance.

    Which was implied to be a reason that improving entities in the engine would not make it worth using entities for item frames.
    Every time a mod API is left undocumented, a koala dies.
     


    Return to WIP Mods

    Who is online

    Users browsing this forum: No registered users and 10 guests

    cron