mirror of https://github.com/OpenTTD/OpenTTD
(svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
parent
208dd15c91
commit
7957bdde13
|
@ -2271,6 +2271,10 @@
|
||||||
RelativePath=".\..\src\misc\hashtable.hpp"
|
RelativePath=".\..\src\misc\hashtable.hpp"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\..\src\misc\smallveh.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath=".\..\src\misc\str.hpp"
|
RelativePath=".\..\src\misc\str.hpp"
|
||||||
>
|
>
|
||||||
|
|
|
@ -2268,6 +2268,10 @@
|
||||||
RelativePath=".\..\src\misc\hashtable.hpp"
|
RelativePath=".\..\src\misc\hashtable.hpp"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\..\src\misc\smallveh.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath=".\..\src\misc\str.hpp"
|
RelativePath=".\..\src\misc\str.hpp"
|
||||||
>
|
>
|
||||||
|
|
|
@ -515,6 +515,7 @@ misc/dbg_helpers.cpp
|
||||||
misc/dbg_helpers.h
|
misc/dbg_helpers.h
|
||||||
misc/fixedsizearray.hpp
|
misc/fixedsizearray.hpp
|
||||||
misc/hashtable.hpp
|
misc/hashtable.hpp
|
||||||
|
misc/smallveh.h
|
||||||
misc/str.hpp
|
misc/str.hpp
|
||||||
misc/strapi.hpp
|
misc/strapi.hpp
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,44 @@
|
||||||
|
/* $Id$ */
|
||||||
|
|
||||||
|
/* @file smallvec.h */
|
||||||
|
|
||||||
|
#ifndef SMALLVEC_H
|
||||||
|
#define SMALLVEC_H
|
||||||
|
|
||||||
|
template <typename T, uint S> struct SmallVector {
|
||||||
|
T *data;
|
||||||
|
uint items;
|
||||||
|
uint capacity;
|
||||||
|
|
||||||
|
SmallVector() : data(NULL), items(0), capacity(0) { }
|
||||||
|
|
||||||
|
~SmallVector()
|
||||||
|
{
|
||||||
|
free(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Append an item and return it.
|
||||||
|
*/
|
||||||
|
T *Append()
|
||||||
|
{
|
||||||
|
if (items == capacity) {
|
||||||
|
capacity += S;
|
||||||
|
data = ReallocT(data, capacity);
|
||||||
|
}
|
||||||
|
|
||||||
|
return &data[items++];
|
||||||
|
}
|
||||||
|
|
||||||
|
const T *Begin() const
|
||||||
|
{
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
const T *End() const
|
||||||
|
{
|
||||||
|
return &data[items];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* SMALLVEC_H */
|
|
@ -28,8 +28,7 @@
|
||||||
#include "settings_type.h"
|
#include "settings_type.h"
|
||||||
#include "station_func.h"
|
#include "station_func.h"
|
||||||
#include "core/alloc_type.hpp"
|
#include "core/alloc_type.hpp"
|
||||||
|
#include "misc/smallvec.h"
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "table/sprites.h"
|
#include "table/sprites.h"
|
||||||
#include "table/strings.h"
|
#include "table/strings.h"
|
||||||
|
@ -139,8 +138,8 @@ enum FoundationPart {
|
||||||
FOUNDATION_PART_END
|
FOUNDATION_PART_END
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::vector<TileSpriteToDraw> TileSpriteToDrawVector;
|
typedef SmallVector<TileSpriteToDraw, 64> TileSpriteToDrawVector;
|
||||||
typedef std::vector<StringSpriteToDraw> StringSpriteToDrawVector;
|
typedef SmallVector<StringSpriteToDraw, 4> StringSpriteToDrawVector;
|
||||||
|
|
||||||
struct ViewportDrawer {
|
struct ViewportDrawer {
|
||||||
DrawPixelInfo dpi;
|
DrawPixelInfo dpi;
|
||||||
|
@ -488,15 +487,13 @@ void DrawGroundSpriteAt(SpriteID image, SpriteID pal, int32 x, int32 y, byte z,
|
||||||
{
|
{
|
||||||
assert((image & SPRITE_MASK) < MAX_SPRITES);
|
assert((image & SPRITE_MASK) < MAX_SPRITES);
|
||||||
|
|
||||||
TileSpriteToDraw ts;
|
TileSpriteToDraw *ts = _cur_vd->tile_sprites_to_draw.Append();
|
||||||
ts.image = image;
|
ts->image = image;
|
||||||
ts.pal = pal;
|
ts->pal = pal;
|
||||||
ts.sub = sub;
|
ts->sub = sub;
|
||||||
ts.x = x;
|
ts->x = x;
|
||||||
ts.y = y;
|
ts->y = y;
|
||||||
ts.z = z;
|
ts->z = z;
|
||||||
|
|
||||||
_cur_vd->tile_sprites_to_draw.push_back(ts);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -787,16 +784,14 @@ void AddChildSpriteScreen(SpriteID image, SpriteID pal, int x, int y, bool trans
|
||||||
/* Returns a StringSpriteToDraw */
|
/* Returns a StringSpriteToDraw */
|
||||||
void AddStringToDraw(int x, int y, StringID string, uint64 params_1, uint64 params_2, uint16 color, uint16 width)
|
void AddStringToDraw(int x, int y, StringID string, uint64 params_1, uint64 params_2, uint16 color, uint16 width)
|
||||||
{
|
{
|
||||||
StringSpriteToDraw ss;
|
StringSpriteToDraw *ss = _cur_vd->string_sprites_to_draw.Append();
|
||||||
ss.string = string;
|
ss->string = string;
|
||||||
ss.x = x;
|
ss->x = x;
|
||||||
ss.y = y;
|
ss->y = y;
|
||||||
ss.params[0] = params_1;
|
ss->params[0] = params_1;
|
||||||
ss.params[1] = params_2;
|
ss->params[1] = params_2;
|
||||||
ss.width = width;
|
ss->width = width;
|
||||||
ss.color = color;
|
ss->color = color;
|
||||||
|
|
||||||
_cur_vd->string_sprites_to_draw.push_back(ss);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1333,7 +1328,8 @@ void UpdateViewportSignPos(ViewportSign *sign, int left, int top, StringID str)
|
||||||
|
|
||||||
static void ViewportDrawTileSprites(const TileSpriteToDrawVector *tstdv)
|
static void ViewportDrawTileSprites(const TileSpriteToDrawVector *tstdv)
|
||||||
{
|
{
|
||||||
for (TileSpriteToDrawVector::const_iterator ts = tstdv->begin(); ts != tstdv->end(); ts++) {
|
const TileSpriteToDraw *tsend = tstdv->End();
|
||||||
|
for (const TileSpriteToDraw *ts = tstdv->Begin(); ts != tsend; ++ts) {
|
||||||
Point pt = RemapCoords(ts->x, ts->y, ts->z);
|
Point pt = RemapCoords(ts->x, ts->y, ts->z);
|
||||||
DrawSprite(ts->image, ts->pal, pt.x, pt.y, ts->sub);
|
DrawSprite(ts->image, ts->pal, pt.x, pt.y, ts->sub);
|
||||||
}
|
}
|
||||||
|
@ -1444,7 +1440,8 @@ static void ViewportDrawStrings(DrawPixelInfo *dpi, const StringSpriteToDrawVect
|
||||||
dp.width = UnScaleByZoom(dp.width, zoom);
|
dp.width = UnScaleByZoom(dp.width, zoom);
|
||||||
dp.height = UnScaleByZoom(dp.height, zoom);
|
dp.height = UnScaleByZoom(dp.height, zoom);
|
||||||
|
|
||||||
for (StringSpriteToDrawVector::const_iterator ss = sstdv->begin(); ss != sstdv->end(); ss++) {
|
const StringSpriteToDraw *ssend = sstdv->End();
|
||||||
|
for (const StringSpriteToDraw *ss = sstdv->Begin(); ss != ssend; ++ss) {
|
||||||
uint16 colour;
|
uint16 colour;
|
||||||
|
|
||||||
if (ss->width != 0) {
|
if (ss->width != 0) {
|
||||||
|
@ -1541,7 +1538,7 @@ void ViewportDoDraw(const ViewPort *vp, int left, int top, int right, int bottom
|
||||||
* is checked) */
|
* is checked) */
|
||||||
assert(vd.parent_list <= endof(parent_list));
|
assert(vd.parent_list <= endof(parent_list));
|
||||||
|
|
||||||
if (!vd.tile_sprites_to_draw.empty()) ViewportDrawTileSprites(&vd.tile_sprites_to_draw);
|
if (vd.tile_sprites_to_draw.items != 0) ViewportDrawTileSprites(&vd.tile_sprites_to_draw);
|
||||||
|
|
||||||
/* null terminate parent sprite list */
|
/* null terminate parent sprite list */
|
||||||
*vd.parent_list = NULL;
|
*vd.parent_list = NULL;
|
||||||
|
@ -1551,7 +1548,7 @@ void ViewportDoDraw(const ViewPort *vp, int left, int top, int right, int bottom
|
||||||
|
|
||||||
if (_draw_bounding_boxes) ViewportDrawBoundingBoxes(parent_list);
|
if (_draw_bounding_boxes) ViewportDrawBoundingBoxes(parent_list);
|
||||||
|
|
||||||
if (!vd.string_sprites_to_draw.empty()) ViewportDrawStrings(&vd.dpi, &vd.string_sprites_to_draw);
|
if (vd.string_sprites_to_draw.items != 0) ViewportDrawStrings(&vd.dpi, &vd.string_sprites_to_draw);
|
||||||
|
|
||||||
_cur_dpi = old_dpi;
|
_cur_dpi = old_dpi;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue