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 hypertext tile modifier(again) #15182

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

Conversation

jingkaimori
Copy link

@jingkaimori jingkaimori commented Sep 18, 2024

Add compact, short information about your PR for easier understanding:
Add text modifier for texture file. This pr replaces #12084 and could be squashed.

  • Goal of the PR
    render a row of text on texture of object. The behavior of this api is the same as text displayed on formspec. Texture modifier is as similar as [fill modifier.

  • How does the PR work?
    This pr render string with RTT (Render To Texture) strategy.
    Modifier schema can be one of following:

    • [text:hypertext encoded with base64
    • [text:hypertext encoded with base64:WxH
    • [text:hypertext encoded with base64:WxH:X,Y

    Hypertext here must be convert to base64 encoding. WxH and X,Y can be integer pairs, e.g. 100x50 and 60,0 respectively. <global> tag in hypertext can control alignment of text.

  • Does it resolve any reported issue?

  • Does this relate to a goal in the roadmap?
    not yet

  • If not a bug fix, why is this PR needed? What using cases does it solve?
    Improve fps and reduce network traffic by render text directly at client instead of generate texture from "bitmap font" dynamically

  • Why use base64 to encode Hypertext?
    Because some special characters([:^,) cannot appears as regular field value in texture spec, described in Some special char cannot be used in filename of texture #15185.

To do

This pr is ready for review.

  • How to customlize font family of text? Default font is used currently, which may vary among clients. Waiting for Font media files #10416 solved
  • What should happen if driver cannot render to target?

How to test

See games/devtest/mods/testnodes/textures.lua. This pr must be test locally, because integration test on ci does not have irrlicht driver that can render to texture.

screenshot_20240920_141533
screenshot_20240920_141546
screenshot_20240920_141601

@jingkaimori jingkaimori changed the title feat: add text tile modifier feat: add text tile modifier(again) Sep 18, 2024
@appgurueu
Copy link
Contributor

I'm not sure how modders would use this feature in a reliable way when they don't know font dimensions, especially width. I think this needs an API which is reasonably "hard pixel"-independent. To use this properly, modders would also need [combine texture modifiers with some "layouting" capabilities beyond hard pixel coordinates.

@wsor4035 wsor4035 added @ Client / Audiovisuals Feature ✨ PRs that add or enhance a feature labels Sep 18, 2024
@Zughy Zughy added the Concept approved Approved by a core dev: PRs welcomed! label Sep 18, 2024
@cx384
Copy link
Contributor

cx384 commented Sep 19, 2024

Fonts are client side, the server doesn't know the actual size, so as appgurueu wrote you definitely need some kind of font size independent text size API.

I would prefer the texture modifier to use text escape sequences, to be consistent with other texts, but I'm not sure if they are compatible with the current texture modifier parsing.
(For fonts it could reuse the font escape sequence I introduced in #14968.)

@jingkaimori
Copy link
Author

I think this needs an API which is reasonably "hard pixel"-independent. To use this properly, modders would also need [combine texture modifiers with some "layouting" capabilities beyond hard pixel coordinates.

Facilities for hypertext is extracted and used here.

@jingkaimori jingkaimori changed the title feat: add text tile modifier(again) Add hypertext tile modifier(again) Sep 21, 2024
@jingkaimori
Copy link
Author

I would prefer the texture modifier to use text escape sequences, to be consistent with other texts, but I'm not sure if they are compatible with the current texture modifier parsing.

There are no "texts" in texture modifiers, only filenames, size specifications and several enumerated options. All of those is restricted to small set of character, thus the consistency requirements of texture modifier is more strict than formspec, name tags, etc.

(For fonts it could reuse the font escape sequence I introduced in #14968.)

This pr only provides font style selecter, no spec for font size and global alignment is provided, which is necessary for mods in display modpack.

@cx384
Copy link
Contributor

cx384 commented Sep 28, 2024

Ok, I guess hypertext can be used here, and encoding it as a number solves all parsing problems.

If I'm not wrong, the main use case for this feature is to display text on signs and similar, but with the current solution you can't dynamically specify the texture of a node.
Maybe it would make more sense to introduce reference based texture modifier for proper RTT things. E.g. #9999
and not just static textures with text.
Having static textures with text may still be a useful feature, but this PR does not solve the issue.

@jingkaimori
Copy link
Author

jingkaimori commented Sep 28, 2024

screenshot_20240928_224615

Text can also be rendered on entity, and texture of entity can be changed dynamically, thus signs can create an entity to carry texture, like display_modpack. If it is indeed necessary to dynamically render texture directly on node itself, #3528 should be finished, rather than a pass-by implement like #9999

@cx384
Copy link
Contributor

cx384 commented Sep 28, 2024

Isn't the whole purpose of this that you don't have to use an entity anymore?
I mean with the current API you can already draw static text to a texture if you have a font as pngs and use the overlay texture modifier to assemble the texture yourself.

@jingkaimori
Copy link
Author

Isn't the whole purpose of this that you don't have to use an entity anymore?

No, the purpose of this api is introduce text rendering in texture generation as modifier. Getting rid of entity is not the purpose of this pr.

I mean with the current API you can already draw static text to a texture if you have a font as pngs and use the overlay texture modifier to assemble the texture yourself.

That means font must be extract to bitmap first, and mod is responsible to typeset (assemble glyph). The pr can typeset text with mechanism from irrlicht, so typesetter is no longer need to be implemented by mod.

@jingkaimori jingkaimori force-pushed the jingkaimori/feat-text-texture-modifier branch 2 times, most recently from 00509df to 9324143 Compare October 18, 2024 12:31
@jingkaimori jingkaimori force-pushed the jingkaimori/feat-text-texture-modifier branch from 9324143 to 09c5778 Compare January 22, 2025 02:39
@jingkaimori
Copy link
Author

Bump. @appgurueu @cx384 Are you interested in reviewing this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@ Client / Audiovisuals Concept approved Approved by a core dev: PRs welcomed! Feature ✨ PRs that add or enhance a feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants