AngelFont.LoadPlain() -- faster Android loader

Monkey Targets Forums/Android/AngelFont.LoadPlain() -- faster Android loader

Nobuyuki(Posted 2013) [#1]
Hello,

This routine was written to speed up the loading of .fnt files on Android. Since the old LoadFont() is now depreciated, the only official solution for AngelFont is to use LoadFontXML(), which utilizes skn3's config.monkey. Unfortunately, the amount of string thrash that occurs when loading an XML-encoded .FNT file causes the GC on my device (and probably yours, too!) to go absolutely bonkers. I measured loading times on my device to be an average of 26 seconds per font when using LoadXML(), which is completely unacceptable.

I tried to make heads-or-tails of config.monkey, hoping to maybe find if there was an easy way to fix this, but I'm afraid I'm not familiar enough with the code to know where would be the best place to optimize it. Since I don't have a lot of time to deal with it, and my project has to be out the door as soon as possible, I opted to write a new routine instead, for plain text .FNT files, and forego XML entirely.

This routine should speed up the loading of AngelFont .FNT files from >20 seconds to less than a second per font on your Android device.



Simply add this routine inside of Class AngelFont, instance a new AngelFont() using the default constructor, and call LoadPlain() from your instance. You all probably know the drill here. Finally, LoadPlain() does not currently support channel packing; perhaps someone else can hack that in?


erebel55(Posted 2014) [#2]
Does this support changing the color of the font within the .fnt? I tried changing the redChnl, greenChnl, and blueChnl and loading with your LoadPlain function but my font still shows up as white.