MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / AddTextEffect

Function AddTextEffect

src/texteff.cpp:42–65  ·  view source on GitHub ↗

Text Effects */

Source from the content-addressed store, hash-verified

40
41/* Text Effects */
42TextEffectID AddTextEffect(EncodedString &&msg, int center, int y, uint8_t duration, TextEffectMode mode)
43{
44 if (_game_mode == GM_MENU) return INVALID_TE_ID;
45
46 auto it = std::ranges::find_if(_text_effects, [](const TextEffect &te) { return !te.IsValid(); });
47 if (it == std::end(_text_effects)) {
48 /* _text_effects.size() is the maximum ID + 1 that has been allocated. We should not allocate INVALID_TE_ID or beyond. */
49 if (_text_effects.size() >= INVALID_TE_ID) return INVALID_TE_ID;
50 it = _text_effects.emplace(std::end(_text_effects));
51 }
52
53 TextEffect &te = *it;
54
55 /* Start defining this object */
56 te.msg = std::move(msg);
57 te.duration = duration;
58 te.mode = mode;
59
60 /* Make sure we only dirty the new area */
61 te.width_normal = 0;
62 te.UpdatePosition(center, y, te.msg.GetDecodedString());
63
64 return static_cast<TextEffectID>(it - std::begin(_text_effects));
65}
66
67void UpdateTextEffect(TextEffectID te_id, EncodedString &&msg)
68{

Callers 4

ShowFillingPercentFunction · 0.85
CcStartStopVehicleFunction · 0.85

Calls 6

GetDecodedStringMethod · 0.80
endFunction · 0.50
beginFunction · 0.50
IsValidMethod · 0.45
sizeMethod · 0.45
UpdatePositionMethod · 0.45

Tested by

no test coverage detected