1
0
Fork 0

Codechange: Use std::find_if to find or assign a text effect slot.

This replaces an index-based loop.
pull/11278/head
Peter Nelson 2023-09-09 16:36:07 +01:00 committed by PeterN
parent 7bd019df90
commit 7519f7ad79
1 changed files with 4 additions and 7 deletions

View File

@ -42,13 +42,10 @@ TextEffectID AddTextEffect(StringID msg, int center, int y, uint8_t duration, Te
{ {
if (_game_mode == GM_MENU) return INVALID_TE_ID; if (_game_mode == GM_MENU) return INVALID_TE_ID;
TextEffectID i; auto it = std::find_if(std::begin(_text_effects), std::end(_text_effects), [](const TextEffect &te) { return te.string_id == INVALID_STRING_ID; });
for (i = 0; i < _text_effects.size(); i++) { if (it == std::end(_text_effects)) it = _text_effects.emplace(std::end(_text_effects));
if (_text_effects[i].string_id == INVALID_STRING_ID) break;
}
if (i == _text_effects.size()) _text_effects.emplace_back();
TextEffect &te = _text_effects[i]; TextEffect &te = *it;
/* Start defining this object */ /* Start defining this object */
te.string_id = msg; te.string_id = msg;
@ -60,7 +57,7 @@ TextEffectID AddTextEffect(StringID msg, int center, int y, uint8_t duration, Te
te.width_normal = 0; te.width_normal = 0;
te.UpdatePosition(center, y, msg); te.UpdatePosition(center, y, msg);
return i; return static_cast<TextEffectID>(it - std::begin(_text_effects));
} }
void UpdateTextEffect(TextEffectID te_id, StringID msg) void UpdateTextEffect(TextEffectID te_id, StringID msg)