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

sofar
Developer
Posts: 2146
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 » Post

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

User avatar
Hybrid Dog
Member
Posts: 2828
Joined: Thu Nov 01, 2012 12:46
GitHub: HybridDog

by Hybrid Dog » Post

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: 7507
Joined: Wed Oct 29, 2014 20:05
GitHub: azekillDIABLO
In-game: azekill_DIABLO
Location: OMICRON
Contact:

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

by azekill_DIABLO » Post

awesome! the fact this not 3d for items is not a problem at all!
Gone, but not dead. Contact me on discord: azekill_DIABLO#6565
DMs are always open if you want to get in touch!

User avatar
D00Med
Member
Posts: 949
Joined: Sat Feb 07, 2015 22:49
GitHub: D00Med
Location: Australia...somewhere

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

by D00Med » Post

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: viewtopic.php?f=15&t=14051#p207242

sofar
Developer
Posts: 2146
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 » Post

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: 949
Joined: Sat Feb 07, 2015 22:49
GitHub: D00Med
Location: Australia...somewhere

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

by D00Med » Post

Ok then, thanks for the explanation.
Look! I have a signature :]
My subgame: viewtopic.php?f=15&t=14051#p207242

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

Re:

by sofar » Post

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: 4778
Joined: Mon Sep 24, 2012 15:01
GitHub: Wuzzy2
IRC: Wuzzy
In-game: Wuzzy
Contact:

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

by Wuzzy » Post

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.

sofar
Developer
Posts: 2146
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 » Post

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
Developer
Posts: 2146
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 » Post

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)[/list]
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
Developer
Posts: 2146
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 » Post

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
Developer
Posts: 2146
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 » Post

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: 4778
Joined: Mon Sep 24, 2012 15:01
GitHub: Wuzzy2
IRC: Wuzzy
In-game: Wuzzy
Contact:

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

by Wuzzy » Post

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). :-)

sofar
Developer
Posts: 2146
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 » Post

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
Developer
Posts: 2146
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 » Post

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: 4778
Joined: Mon Sep 24, 2012 15:01
GitHub: Wuzzy2
IRC: Wuzzy
In-game: Wuzzy
Contact:

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

by Wuzzy » Post

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.

sofar
Developer
Posts: 2146
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 » Post

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: 4276
Joined: Sun Sep 09, 2012 17:31
GitHub: Sokomine
IRC: Sokomine
In-game: Sokomine

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

by Sokomine » Post

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
Developer
Posts: 2146
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 » Post

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: 818
Joined: Tue Apr 14, 2015 01:59
GitHub: raymoo
IRC: Hijiri
In-game: Raymoo + Clownpiece

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

by Byakuren » Post

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
Developer
Posts: 2146
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 » Post

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: 818
Joined: Tue Apr 14, 2015 01:59
GitHub: raymoo
IRC: Hijiri
In-game: Raymoo + Clownpiece

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

by Byakuren » Post

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.

User avatar
bosapara
Member
Posts: 637
Joined: Fri Apr 07, 2017 08:49

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

by bosapara » Post

Firstly congrats with this mod, really nothing lags

Is it possible to make sword/picks etc at frame more "3d" (1px depth) like at usual frames?

Image

___

frame texture from gif
frame_frame.png
frame_frame.png (504 Bytes) Viewed 4178 times

sofar
Developer
Posts: 2146
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 » Post

bosapara wrote:Is it possible to make sword/picks etc at frame more "3d" (1px depth) like at usual frames?
yes, but you'd get back the lag again, because that can only be done by using entities again, which is what this mod avoids.

User avatar
bosapara
Member
Posts: 637
Joined: Fri Apr 07, 2017 08:49

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

by bosapara » Post

sofar wrote:
bosapara wrote:Is it possible to make sword/picks etc at frame more "3d" (1px depth) like at usual frames?
yes, but you'd get back the lag again, because that can only be done by using entities again, which is what this mod avoids.
understood, thanx

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 11 guests