(svn r18635) -Codechange: store TextEffects in a SmallVector

replace/41b28d7194a279bdc17475d4fbe2ea6ec885a466
smatz 15 years ago
parent 69f1db204e
commit e6d6704f32

@ -17,13 +17,10 @@
#include "transparency.h"
#include "strings_func.h"
#include "core/alloc_func.hpp"
#include "core/smallvec_type.hpp"
#include "viewport_func.h"
#include "settings_type.h"
enum {
INIT_NUM_TEXT_EFFECTS = 20,
};
/** Container for all information about a text effect */
struct TextEffect : public ViewportSign{
StringID string_id; ///< String to draw for the text effect, if INVALID_STRING_ID then it's not valid
@ -40,31 +37,20 @@ struct TextEffect : public ViewportSign{
}
};
/* used for text effects */
static TextEffect *_text_effect_list = NULL;
static uint16 _num_text_effects = INIT_NUM_TEXT_EFFECTS;
static SmallVector<struct TextEffect, 32> _text_effects; ///< Text effects are stored there
/* Text Effects */
TextEffectID AddTextEffect(StringID msg, int center, int y, uint16 duration, TextEffectMode mode)
{
TextEffectID i;
if (_game_mode == GM_MENU) return INVALID_TE_ID;
/* Look for a free spot in the text effect array */
for (i = 0; i < _num_text_effects; i++) {
if (_text_effect_list[i].string_id == INVALID_STRING_ID) break;
}
/* If there is none found, we grow the array */
if (i == _num_text_effects) {
_num_text_effects += 25;
_text_effect_list = ReallocT<TextEffect>(_text_effect_list, _num_text_effects);
for (; i < _num_text_effects; i++) _text_effect_list[i].string_id = INVALID_STRING_ID;
i = _num_text_effects - 1;
TextEffectID i;
for (i = 0; i < _text_effects.Length(); i++) {
if (_text_effects[i].string_id == INVALID_STRING_ID) break;
}
if (i == _text_effects.Length()) _text_effects.Append();
TextEffect *te = &_text_effect_list[i];
TextEffect *te = _text_effects.Get(i);
/* Start defining this object */
te->string_id = msg;
@ -81,10 +67,8 @@ TextEffectID AddTextEffect(StringID msg, int center, int y, uint16 duration, Tex
void UpdateTextEffect(TextEffectID te_id, StringID msg)
{
assert(te_id < _num_text_effects);
/* Update details */
TextEffect *te = &_text_effect_list[te_id];
TextEffect *te = _text_effects.Get(te_id);
te->string_id = msg;
te->params_1 = GetDParam(0);
@ -93,8 +77,7 @@ void UpdateTextEffect(TextEffectID te_id, StringID msg)
void RemoveTextEffect(TextEffectID te_id)
{
assert(te_id < _num_text_effects);
_text_effect_list[te_id].Reset();
_text_effects[te_id].Reset();
}
static void MoveTextEffect(TextEffect *te)
@ -113,17 +96,15 @@ static void MoveTextEffect(TextEffect *te)
void MoveAllTextEffects()
{
for (TextEffectID i = 0; i < _num_text_effects; i++) {
TextEffect *te = &_text_effect_list[i];
const TextEffect *end = _text_effects.End();
for (TextEffect *te = _text_effects.Begin(); te != end; te++) {
if (te->string_id != INVALID_STRING_ID && te->mode == TE_RISING) MoveTextEffect(te);
}
}
void InitTextEffects()
{
if (_text_effect_list == NULL) _text_effect_list = MallocT<TextEffect>(_num_text_effects);
for (TextEffectID i = 0; i < _num_text_effects; i++) _text_effect_list[i].string_id = INVALID_STRING_ID;
_text_effects.Reset();
}
void DrawTextEffects(DrawPixelInfo *dpi)
@ -131,10 +112,9 @@ void DrawTextEffects(DrawPixelInfo *dpi)
/* Don't draw the text effects when zoomed out a lot */
if (dpi->zoom > ZOOM_LVL_OUT_2X) return;
for (TextEffectID i = 0; i < _num_text_effects; i++) {
const TextEffect *te = &_text_effect_list[i];
const TextEffect *end = _text_effects.End();
for (TextEffect *te = _text_effects.Begin(); te != end; te++) {
if (te->string_id == INVALID_STRING_ID) continue;
if (te->mode == TE_RISING || (_settings_client.gui.loading_indicators && !IsTransparencySet(TO_LOADING))) {
ViewportAddString(dpi, ZOOM_LVL_OUT_2X, te, te->string_id, te->string_id - 1, 0, te->params_1);
}

Loading…
Cancel
Save