Text Cache

Mithran

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
404
Reaction score
213
First Language
English
Primarily Uses
Text Cache v 1.03
by Mithran​
Introduction
VX Ace is a huge improvement over VX in many different ways. However, although text processing has a number of new features, it has also introduced a number of new bugs.
- Text is squeezed when drawn to the rect given by text_size. Subsequent text shrinking also occurs long before needed.
- Bitmap#draw_text wraps around on itself after ~640 pixels.
- Individually drawn characters for certain fonts are drawn incorrectly

Features
- Implements a text cache. Trades a small amount of memory for a large amount of processing speed (~2 to 5x as fast for most strings).
- Draws each character with padding, accounting for its actual size when placed adjacent other characters. Each character is now drawn consistently whether it is drawn independently or not.
- Automatically uses original method when dealing with "squeezed" text (manually squeezing text looks terrible, so this was left in)

How to Use
Install on its own script page in the materials section of the script editor above main and below default scripts.

Script
http://pastebin.com/fRFFYgRt

FAQ
q. Any simpler way to handle this?
a. Add two pixels to width before attempting to draw text to its own text_size rect. Split up any string longer than 640 text_size width and draw each piece successively (or don't draw strings longer than 640 text_size width, you'd only need them for horizontally scrolling windows). Use a non-TrueType Font (like the default one, I believe). Following these three rules you'll likely never run into any of the bugs fixed by this script. This script will still allow faster text processing, if you choose to use it.

q. I'm using draw_text every frame, it still lags.
a. This script is not a substitute for poor procedures. draw_text is still very time consuming, and should be using sparingly as before.

Credit and Thanks
- Mithran

Author's Notes
May be distributed with a link to these forums, original unedited script, and with credit. May be used in any project, so long as the credit in the script remains intact (individual credit in the project as a whole is not required).

Bug Reporting
If you have a crashing bug, please provide the complete error code as well as a short description on how to reproduce. If you have a display bug, please include a screenshot and a short description.
 
Last edited by a moderator:

Mihel

Veteran
Veteran
Joined
Mar 13, 2012
Messages
384
Reaction score
45
Primarily Uses
Thanks for this! I though it was a problem with the font I was using.

You should put some pictures here, most people are gonna skip bug-fixes scripts if they don't see a visual example.

 

Dr.Yami

。◕‿◕。
Developer
Joined
Mar 5, 2012
Messages
994
Reaction score
741
First Language
Vietnamese
Primarily Uses
Other
Yeah, Awesome Bugfix XD
 

Nathanial

Veteran
Veteran
Joined
Feb 23, 2012
Messages
3,249
Reaction score
1,130
First Language
English
Primarily Uses
Very awesome fix! Thank you :)
 

Terumoc

Villager
Member
Joined
Mar 13, 2012
Messages
11
Reaction score
1
First Language
English
Primarily Uses
RMMV
This fixes so many instances of weirdness and annoyance I had with using different fonts, thank you so much for sharing this! This makes using VXAce even more enjoyable.

I still have one other issue with text, but I'll be putting up a separate thread regarding that... but this has fixed the biggest issue which was cut off beginnings of text and weirdness in spacing.
 

Mithran

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
404
Reaction score
213
First Language
English
Primarily Uses
Updated to v1.01, fixed a crashing error when using F12 to reset. (Thanks Archeia_Nessiah for the report)

Script has been updated at the link.
 

Indrah

Megane Berserker
Veteran
Joined
Mar 5, 2012
Messages
2,079
Reaction score
2,047
First Language
Spanish
Primarily Uses
RMMV
Great, I was about to report the F12 crash. Love this (Georgia, Imma use your fonty ass no matter how you complain >[)
 

Kenen

Veteran
Veteran
Joined
Apr 3, 2012
Messages
261
Reaction score
155
First Language
English
Primarily Uses
RMMV
This just made my day. I haven't been able to use my favorite typeface because of the missing character bug. Problem solved! Thanks so much, Mithran.
 

Knightmare

Knight of the Night
Veteran
Joined
Mar 14, 2012
Messages
1,112
Reaction score
197
First Language
English
Primarily Uses
RMMV
Yo Myth! (brofist) I was wondering what happened to you. Haven't seen you in the community for a while. Nice to see you. Thanks for the bug fix also.
 

Galenmereth

I thought what I'd do was
Veteran
Joined
May 15, 2013
Messages
2,208
Reaction score
1,943
First Language
English
Primarily Uses
RMMV
I know it's been a while, but just thought I'd pop in and mention a problem. A tester got the following crash using an Intel chipset:

http://pastebin.com/XKNmNNsy

Crash happened on windows like the default Shop Sell window, Items, and so forth. Not normal message dialogues, and other menus.

This does not happen with all Intel chipsets, nor most other GPU's I've tested, which is weird. But when I removed the script, the problem was gone :)
 

Mithran

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
404
Reaction score
213
First Language
English
Primarily Uses
Looks like something was trying to print either a null character, or something else that is reporting a zero-height. I had no handling for this, so I updated the script to skip any character reporting a 0 height as it would prevent the cached bitmap from being created. Let me know if that works.
 

Napoleon

Veteran
Veteran
Joined
Dec 29, 2012
Messages
869
Reaction score
96
First Language
Dutch
Primarily Uses
The pastebin still links the old 1.01 version. Where can we find the new version with the '0-height-fix'? Or is it not yet released and is it still awaiting 'testing from Galenmereth'?
 

Mithran

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
404
Reaction score
213
First Language
English
Primarily Uses
Actually I fixed it right before I posted last time (it was a one line change).  I've now updated the version numbers and changelog to match.
 
Last edited by a moderator:

Mithran

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
404
Reaction score
213
First Language
English
Primarily Uses
Hey Mithran, just an inquiry. I was using this commercial font named Bookmania. Here's the kicker though. On certain PCs, it displays perfectly fine. But on my pc, it will draw it like this. Do you have any idea of the cause?
That is odd.  Does it happen both with and without Text Cache?  Is it an OpenType font or TrueType?  I read somewhere that OpenType may have issues with RGSS3, but those issues were glyphing or outright crashes with certain fonts, I've never seen the above described issue.  Perhaps you are loading a corrupted copy of the font?  If installed, I'm not sure if the one in the game folder takes precedence or if the system one does.  I assume the garbage pixels only get drawn in RM and don't show up in a font viewer?  Depending on how each letter is constructed internally, it could also be an issue with different windows versions not scaling the font correctly.  RGSS3 uses automatic anti-aliasing when drawing text, so it could also be an internal error.
 

Archeia

Level 99 Demi-fiend
Developer
Joined
Mar 1, 2012
Messages
14,880
Reaction score
15,034
First Language
Filipino
Primarily Uses
VNM
That is odd.  Does it happen both with and without Text Cache?  Is it an OpenType font or TrueType?  I read somewhere that OpenType may have issues with RGSS3, but those issues were glyphing or outright crashes with certain fonts, I've never seen the above described issue.  Perhaps you are loading a corrupted copy of the font?  If installed, I'm not sure if the one in the game folder takes precedence or if the system one does.  I assume the garbage pixels only get drawn in RM and don't show up in a font viewer?  Depending on how each letter is constructed internally, it could also be an issue with different windows versions not scaling the font correctly.  RGSS3 uses automatic anti-aliasing when drawing text, so it could also be an internal error.
It happens both with and without Text Cache. Only in this PC though. It is an OTF though.

I noticed that the reason for it is that RM squishes letter. If you added a lot of space, it will appear properly. But that does make me question how it will appear on other Computers since if it displays perfectly fine for others, then I did this so it would display text properly in mine, wouldn't that be a huge problem o_o

The font is definitely not corrupted since it works perfectly on everything else like websites and my word document files and other pcs that loads the same font. 
 

Mithran

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
404
Reaction score
213
First Language
English
Primarily Uses
Are you using Bitmap#text_size to determine the area that the text should draw to for that example window?  When not using this script, any text drawn to a rect equal to the size of the text will "squeeze" it, but with this script, it adds 2 pixels of padding that is supposed[\i] to prevent the squeeze.  Maybe OTFs have a different size estimation and it differs based on system?  The size estimation should[\i] be uniform from system to system, and if not, it should at least be consistent[\i] enough that you can draw it to it's own text_size rect (after the 2 pixels buffer this script allows).  Beyond that, the actual squeezing is all internal RM, which makes me further question this odd behavior.

 

Squeezed characters won't be cached and vice-versa, because I have no way to determine the actual dimensions of the "squeezed" character without having the script examine by pixel, and there are too many variations of squeezing for me to reliably keep in memory using the methods I am now.  When a text draw for the cache does take place, there is always plenty of empty space to draw the character, so no squeeze ever takes place there.

 

Right now this script allows the default "squishing" algorithm to take over only in cases where the entire drawn text is determined to not have enough room to draw in the selected area.  However, that seems to be more and more a thing there should at least be a way around.  Does the text appear like the above in game for windows that it looks like it should be drawn correctly, like the message window, which already draws by character, or areas that it *looks* like there is plenty of room, like names in the menu screen, or is it everywhere in your game?  If its just the "squished" areas, how does it appear to other people for those areas?  None of the text in the image you posted looks particularly squeezed, which makes it seem like the squeezing isn't working at all.

 

I'll take another look at this and at least add a flag to have the system completely ignore "squishing".  Altering the text myself via RGSS bitmap methods looks even worse than squishing it, though, so there isn't much I can do there.
 

Mithran

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
404
Reaction score
213
First Language
English
Primarily Uses
Update: 1.03


Added various stuff relating to giving a bit more control over when and if the script turns off and allows the default text draw "squeezing" to take place instead of the cached draw and cleaned up the code a bit. Link is the same as in original description.
 

Archeia

Level 99 Demi-fiend
Developer
Joined
Mar 1, 2012
Messages
14,880
Reaction score
15,034
First Language
Filipino
Primarily Uses
VNM
Mithran I was just wondering, is it possible for us to decrease the spacing in some fonts. Like instead of a letter spacing, half letter? Just an example:

 

Mithran

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
404
Reaction score
213
First Language
English
Primarily Uses
I've experimented with this some and can't quite get it right (eg., to the point where setting one variable for spacing, either as a ratio of the default amount of spacing or a specific pixel offset for pacing looks good for all letters in a given size for a specific font). In the case of the above example, though, is the top window a Window_Help or something inheriting from it? Those use draw_text_ex, which space the text a certain way no matter what the cached draw does. You would need separate adjustments for the character-by-character (draw_text_ex) drawing sections and the all-at-once (draw_text) drawing methods. It is true that my script makes everything draw character-by-character, but uses a completely different method to do so and does so using a slight amount of overdraw buffer on either side to prevent the cut-off letter glitch.


Proper spacing is something that can be very finicky because each character has a specific way it is supposed to be spaced based on the font, but text_size only tells you the space the character is supposed to take up with spacing (supposedly) already considered, and that is the only thing you really have to go off of if you are trying to automatically space things. Without access to a full kerning table, that is.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

It's raining non stop since yesterday. The sound of the rain is so soothing.
I really miss the old style disney animated movies. I guess the last one was The Princess and the Frog from 2009. Now I am trying to collect every single one I can get on BD or DVD.
What I've seen from the MZ tiles looks pretty inconsistent, bleh. Every plant seems to be drawn in a different style.
Recently posted a demo of my game online. Now I have no idea what to do with myself o_O What is the reason for my existence now...
I'm feeling a lot better this week. Some of the rules in my country for isolation changed a little, so I was able to see friends in person again, which was a huge relief. Thanks everyone for giving me some sympathy last week when I was having a rough time!

Forum statistics

Threads
99,286
Messages
963,872
Members
130,896
Latest member
Mosi3c
Top