Skip to content

Commit

Permalink
butano: add config `BN_CFG_SPRITE_TEXT_MAX_UTF8_CHARACTERS_FOR_DUPLIC…
Browse files Browse the repository at this point in the history
…ATION_CHECK` to save compile time when building fonts with big charaset

Current implementation of _duplicated_utf8_characters() is inefficient
with time complexity of O(N^2). Project build process will hang for an untolerable long time when many characters exist.The duplication check for fonts with big
charaset can be done in font making or converting phase. It is
unnecessary to do it in assertion.
  • Loading branch information
laqieer committed Feb 9, 2022
1 parent 43df41a commit 93bca7e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
11 changes: 11 additions & 0 deletions butano/include/bn_config_sprite_text.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,15 @@
#define BN_CFG_SPRITE_TEXT_MAX_UTF8_CHARACTERS 4096
#endif

/**
* @def BN_CFG_SPRITE_TEXT_MAX_UTF8_CHARACTERS_FOR_DUPLICATION_CHECK
*
* Specifies the maximum number of UTF-8 characters for duplication check to save compile time.
*
* @ingroup text
*/
#ifndef BN_CFG_SPRITE_TEXT_MAX_UTF8_CHARACTERS_FOR_DUPLICATION_CHECK
#define BN_CFG_SPRITE_TEXT_MAX_UTF8_CHARACTERS_FOR_DUPLICATION_CHECK 100
#endif

#endif
3 changes: 2 additions & 1 deletion butano/include/bn_sprite_font.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ class sprite_font
BN_ASSERT(utf8_characters_ref.size() <= BN_CFG_SPRITE_TEXT_MAX_UTF8_CHARACTERS,
"Invalid UTF-8 characters count: ", utf8_characters_ref.size());
BN_ASSERT(_validate_utf8_characters(), "UTF-8 characters validation failed");
//BN_ASSERT(! _duplicated_utf8_characters(), "There's duplicated UTF-8 characters");
BN_ASSERT(BN_CFG_SPRITE_TEXT_MAX_UTF8_CHARACTERS > BN_CFG_SPRITE_TEXT_MAX_UTF8_CHARACTERS_FOR_DUPLICATION_CHECK ||
! _duplicated_utf8_characters(), "There's duplicated UTF-8 characters");
BN_ASSERT(character_widths_ref.empty() ||
character_widths_ref.size() == 1 + minimum_graphics + utf8_characters_ref.size(),
"Invalid character widths count: ", character_widths_ref.size(), " - ",
Expand Down

0 comments on commit 93bca7e

Please sign in to comment.