Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add node texture variants #13811

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open

Add node texture variants #13811

wants to merge 9 commits into from

Conversation

sfence
Copy link
Contributor

@sfence sfence commented Sep 15, 2023

This is the adoption of #12928. Closes #9193

I have rebased the original @TurkeyMcMac code and tested it.
It looks to be working without some artifact on my Linux.

To do

This PR is Ready for Review.

How to test

There are test nodes in the developer test game. They can be used to test.
There is also the command /node_visual which allows to change variant_offset for the wanted node.
Example of command: /node_visual testnodes:variant_color variant_offset 2

@sfence
Copy link
Contributor Author

sfence commented Sep 15, 2023

According to this: https://irc.minetest.net/minetest-dev/2023-01-08#i_6046142

it seems that there is nothing left to be done.

Am I right?

@wsor4035 wsor4035 added @ Server / Client / Env. Feature ✨ PRs that add or enhance a feature Textures labels Sep 15, 2023
@rubenwardy rubenwardy added the Concept approved Approved by a core dev: PRs welcomed! label Sep 17, 2023
@Bituvo
Copy link
Contributor

Bituvo commented Nov 21, 2023

Would it be possible to add weights for each variant?

@sfence
Copy link
Contributor Author

sfence commented Nov 30, 2023

Would it be possible to add weights for each variant?

What do you mean by it?

@Bituvo
Copy link
Contributor

Bituvo commented Dec 1, 2023

What do you mean by it?

So that one texture is more likely to appear than another, for example. Like, dirt_1.png could have a 75% chance of appearing, but dirt_2.png could have a 25% chance.

@sfence
Copy link
Contributor Author

sfence commented Dec 1, 2023

What do you mean by it?

So that one texture is more likely to appear than another, for example. Like, dirt_1.png could have a 75% chance of appearing, but dirt_2.png could have a 25% chance.

So, I understand now.

This uses the node param2 value to choose the texture. So if the mod author wants to make some texture more common, he only needs to reflect in on_construct callback or/and in the mapgen generation code.

doc/lua_api.md Outdated Show resolved Hide resolved
doc/lua_api.md Outdated Show resolved Hide resolved
Copy link
Contributor

@doxygen-spammer doxygen-spammer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here Github frustrates me again, as it refuses to expand the C++ diffs. :(

I left comments in the code.

Maybe it should be made clear if you need to override the same set of properties in each variant, or if it is allowed to e. g. add an overlay tile only to variants 3 and 6.

@sfence
Copy link
Contributor Author

sfence commented Dec 21, 2023

Here Github frustrates me again, as it refuses to expand the C++ diffs. :(

I left comments in the code.

Maybe it should be made clear if you need to override the same set of properties in each variant, or if it is allowed to e. g. add an overlay tile only to variants 3 and 6.

So, It should be documented now as well.

There is probably a bug in overlay_tiles which uses color. I will look at it later.

@doxygen-spammer
Copy link
Contributor

doxygen-spammer commented Dec 24, 2023 via email

@sfence
Copy link
Contributor Author

sfence commented Dec 29, 2023

With the last commit, this PR should be able to fix issue #13417 as well and possibly make issue #13112 obsolete.

@doxygen-spammer
Copy link
Contributor

doxygen-spammer commented Dec 29, 2023 via email

@doxygen-spammer
Copy link
Contributor

doxygen-spammer commented Dec 29, 2023 via email

@sfence
Copy link
Contributor Author

sfence commented Dec 30, 2023

@doxygen-spammer
I have rebased this. It includes lua_doc.md update, so the set/get_node_visual methods are documented now.

@doxygen-spammer
Copy link
Contributor

doxygen-spammer commented Dec 30, 2023 via email

@kromka-chleba
Copy link
Contributor

With the last commit, this PR should be able to fix issue #13417 as well and possibly make issue #13112 obsolete.

It would indeed fix the first issue but not the second one. ABMs and LBMs do more stuff than simply swapping textures. Sometimes you want to remove the node completely, move the nodes or maybe spawn a structure. Not being able to change ABMs/LBMs after they are created makes them inflexible while hitting performance.

@Zughy Zughy added Action / change needed Code still needs changes (PR) / more information requested (Issues) Rebase needed The PR needs to be rebased by its author and removed Action / change needed Code still needs changes (PR) / more information requested (Issues) labels Jan 21, 2024
@Zughy
Copy link
Contributor

Zughy commented Jan 21, 2024

@sfence rebase needed

@sfence
Copy link
Contributor Author

sfence commented Aug 18, 2024

Wouldn't it be better to make it so metadata can modify the image texture. And the param2 can be used for facedir, or color instead ?

it is possible to do it that way. However, it will probably be a controversial solution because it can result in many metadata reading during rendering.
Using metadata sounds acceptable for some nodes, where we can expect sporadic occurrence.

@sfence sfence force-pushed the variant branch 2 times, most recently from b3ed6c6 to e57b43a Compare August 18, 2024 09:52
@DragonWrangler1
Copy link
Contributor

Once I get some time later I’ll test this out again.

@DragonWrangler1
Copy link
Contributor

Ok. So after some playing around I made a node that uses player:set_node_visual in an on_construct function, and it seems that it force closes mt (unless I made a mistake in the function), but here's what I get in the debug log.

2024-08-18 08:37:41: ERROR[Server]: In thread 743b937fe6c0:
2024-08-18 08:37:41: ERROR[Server]: /home/user/minetest-variant/src/server/clientiface.cpp:306: void ClientInterface::send(session_t, NetworkPacket*): A fatal error occurred: packet type missing in table

@Zughy
Copy link
Contributor

Zughy commented Sep 23, 2024

@sfence rebase needed

@sfan5 sfan5 self-requested a review September 29, 2024 18:31
@sfan5 sfan5 removed the Rebase needed The PR needs to be rebased by its author label Sep 29, 2024
@cx384
Copy link
Contributor

cx384 commented Dec 21, 2024

It's a little late, and maybe I'm the only one who thinks this way, but wouldn't it be way better to put this feature into the tile definition instead of polluting the node definition table even more. This way, you would also avoid problems with future tile features.
It would for example look like this.

tiles = {{
    name = "mod_grass1.png",
    color="green",
    variants = {"mod_grass2.png", {name = "mod_grass3.png"}, {name = "mod_grass4.png", color="red"}},
}}

I like this feature very much, but I don't like how the API looks like.

@Zughy Zughy added the Rebase needed The PR needs to be rebased by its author label Dec 22, 2024
@Zughy
Copy link
Contributor

Zughy commented Dec 22, 2024

@sfence rebase needed

@doxygen-spammer
Copy link
Contributor

doxygen-spammer commented Dec 22, 2024 via email

@cx384
Copy link
Contributor

cx384 commented Dec 23, 2024

I think it would be more pollution if node variants are expanded to cover
sounds, description, etc.

I get where you're coming from, but being able to override arbitrary node def fields with param2 is nonsense.
In most cases, it is better to just register a new node (also for textures), and when you want to make something dynamically changeable, param2 is the last thing you would use if nothing else works, since it has only 8 bits.
E.g. for sounds it is better to use node meta and the description is only for the item and can already be changed with item meta.
(being able to dynamically change a node attribute in multiple ways (param2 & meta) would create a mess, and make it unnecessary complicated to figure out which one is actually used.)

Also, for a feature to occupy such a limited resource like param2 bits, you need sufficient use cases. It is not worth maintaining useless features that nobody uses.
Texture variants with param2 is more of an exception, it is like you would define your own paramtype2. Maybe other node fields will be changeable with param2 in the future, but in this case, I still think it would be better to put it into the corresponding node def field.

Edit:
I don't want to hold back this PR too much, because of bikeshedding. So keep the API if you insist, it's not that important.

@sfan5
Copy link
Collaborator

sfan5 commented Dec 23, 2024

Feel free to wait for my review before rebasing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Concept approved Approved by a core dev: PRs welcomed! Feature ✨ PRs that add or enhance a feature Rebase needed The PR needs to be rebased by its author @ Server / Client / Env. Textures
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add paramtype2 for node texture variants