mirror of https://github.com/OpenTTD/OpenTTD.git
Codechange: Make use of the improved C++17 emplace_back function.
This commit is contained in:
parent
cc1679e317
commit
79240eab1e
|
@ -433,8 +433,7 @@ void ShowBuildBridgeWindow(TileIndex start, TileIndex end, TransportType transpo
|
|||
type_check = CheckBridgeAvailability(brd_type, bridge_len);
|
||||
if (type_check.Succeeded()) {
|
||||
/* bridge is accepted, add to list */
|
||||
/*C++17: BuildBridgeData &item = */ bl->emplace_back();
|
||||
BuildBridgeData &item = bl->back();
|
||||
BuildBridgeData &item = bl->emplace_back();
|
||||
item.index = brd_type;
|
||||
item.spec = GetBridgeSpec(brd_type);
|
||||
/* Add to terraforming & bulldozing costs the cost of the
|
||||
|
|
|
@ -142,8 +142,7 @@ struct SmallMap : std::vector<std::pair<T, U> > {
|
|||
for (uint i = 0; i < std::vector<Pair>::size(); i++) {
|
||||
if (key == std::vector<Pair>::operator[](i).first) return std::vector<Pair>::operator[](i).second;
|
||||
}
|
||||
/*C++17: Pair &n = */ std::vector<Pair>::emplace_back();
|
||||
Pair &n = std::vector<Pair>::back();
|
||||
Pair &n = std::vector<Pair>::emplace_back();
|
||||
n.first = key;
|
||||
return n.second;
|
||||
}
|
||||
|
|
|
@ -486,8 +486,7 @@ void EngineOverrideManager::ResetToDefaultMapping()
|
|||
this->clear();
|
||||
for (VehicleType type = VEH_TRAIN; type <= VEH_AIRCRAFT; type++) {
|
||||
for (uint internal_id = 0; internal_id < _engine_counts[type]; internal_id++) {
|
||||
/*C++17: EngineIDMapping &eid = */ this->emplace_back();
|
||||
EngineIDMapping &eid = this->back();
|
||||
EngineIDMapping &eid = this->emplace_back();
|
||||
eid.type = type;
|
||||
eid.grfid = INVALID_GRFID;
|
||||
eid.internal_id = internal_id;
|
||||
|
|
|
@ -119,8 +119,7 @@ public:
|
|||
*/
|
||||
inline FiosItem *Append()
|
||||
{
|
||||
/*C++17: return &*/ this->files.emplace_back();
|
||||
return &this->files.back();
|
||||
return &this->files.emplace_back();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2625,8 +2625,7 @@ struct IndustryCargoesWindow : public Window {
|
|||
_displayed_industries.set(it);
|
||||
|
||||
this->fields.clear();
|
||||
/*C++17: CargoesRow &row = */ this->fields.emplace_back();
|
||||
CargoesRow &row = this->fields.back();
|
||||
CargoesRow &row = this->fields.emplace_back();
|
||||
row.columns[0].MakeHeader(STR_INDUSTRY_CARGOES_PRODUCERS);
|
||||
row.columns[1].MakeEmpty(CFT_SMALL_EMPTY);
|
||||
row.columns[2].MakeEmpty(CFT_SMALL_EMPTY);
|
||||
|
@ -2641,8 +2640,7 @@ struct IndustryCargoesWindow : public Window {
|
|||
int num_cust = CountMatchingAcceptingIndustries(central_sp->produced_cargo, lengthof(central_sp->produced_cargo)) + houses_accept;
|
||||
int num_indrows = max(3, max(num_supp, num_cust)); // One is needed for the 'it' industry, and 2 for the cargo labels.
|
||||
for (int i = 0; i < num_indrows; i++) {
|
||||
/*C++17: CargoesRow &row = */ this->fields.emplace_back();
|
||||
CargoesRow &row = this->fields.back();
|
||||
CargoesRow &row = this->fields.emplace_back();
|
||||
row.columns[0].MakeEmpty(CFT_EMPTY);
|
||||
row.columns[1].MakeCargo(central_sp->accepts_cargo, lengthof(central_sp->accepts_cargo));
|
||||
row.columns[2].MakeEmpty(CFT_EMPTY);
|
||||
|
@ -2705,8 +2703,7 @@ struct IndustryCargoesWindow : public Window {
|
|||
_displayed_industries.reset();
|
||||
|
||||
this->fields.clear();
|
||||
/*C++17: CargoesRow &row = */ this->fields.emplace_back();
|
||||
CargoesRow &row = this->fields.back();
|
||||
CargoesRow &row = this->fields.emplace_back();
|
||||
row.columns[0].MakeHeader(STR_INDUSTRY_CARGOES_PRODUCERS);
|
||||
row.columns[1].MakeEmpty(CFT_SMALL_EMPTY);
|
||||
row.columns[2].MakeHeader(STR_INDUSTRY_CARGOES_CUSTOMERS);
|
||||
|
@ -2719,8 +2716,7 @@ struct IndustryCargoesWindow : public Window {
|
|||
int num_cust = CountMatchingAcceptingIndustries(&cid, 1) + houses_accept;
|
||||
int num_indrows = max(num_supp, num_cust);
|
||||
for (int i = 0; i < num_indrows; i++) {
|
||||
/*C++17: CargoesRow &row = */ this->fields.emplace_back();
|
||||
CargoesRow &row = this->fields.back();
|
||||
CargoesRow &row = this->fields.emplace_back();
|
||||
row.columns[0].MakeEmpty(CFT_EMPTY);
|
||||
row.columns[1].MakeCargo(&cid, 1);
|
||||
row.columns[2].MakeEmpty(CFT_EMPTY);
|
||||
|
|
|
@ -1916,8 +1916,7 @@ static ChangeInfoResult StationChangeInfo(uint stid, int numinfo, int prop, Byte
|
|||
tmp_layout.clear();
|
||||
for (;;) {
|
||||
/* no relative bounding box support */
|
||||
/*C++17: DrawTileSeqStruct &dtss = */ tmp_layout.emplace_back();
|
||||
DrawTileSeqStruct &dtss = tmp_layout.back();
|
||||
DrawTileSeqStruct &dtss = tmp_layout.emplace_back();
|
||||
MemSetT(&dtss, 0);
|
||||
|
||||
dtss.delta_x = buf->ReadByte();
|
||||
|
@ -5020,8 +5019,7 @@ static void NewSpriteGroup(ByteReader *buf)
|
|||
/* Loop through the var adjusts. Unfortunately we don't know how many we have
|
||||
* from the outset, so we shall have to keep reallocing. */
|
||||
do {
|
||||
/*C++17: DeterministicSpriteGroupAdjust &adjust = */ adjusts.emplace_back();
|
||||
DeterministicSpriteGroupAdjust &adjust = adjusts.back();
|
||||
DeterministicSpriteGroupAdjust &adjust = adjusts.emplace_back();
|
||||
|
||||
/* The first var adjust doesn't have an operation specified, so we set it to add. */
|
||||
adjust.operation = adjusts.size() == 1 ? DSGA_OP_ADD : (DeterministicSpriteGroupAdjustOperation)buf->ReadByte();
|
||||
|
|
|
@ -664,8 +664,7 @@ uint32 NewGRFSpriteLayout::PrepareLayout(uint32 orig_offset, uint32 newgrf_groun
|
|||
|
||||
/* Create a copy of the spritelayout, so we can modify some values.
|
||||
* Also include the groundsprite into the sequence for easier processing. */
|
||||
/*C++17: DrawTileSeqStruct *result = &*/ result_seq.emplace_back();
|
||||
DrawTileSeqStruct *result = &result_seq.back();
|
||||
DrawTileSeqStruct *result = &result_seq.emplace_back();
|
||||
result->image = ground;
|
||||
result->delta_x = 0;
|
||||
result->delta_y = 0;
|
||||
|
@ -675,8 +674,7 @@ uint32 NewGRFSpriteLayout::PrepareLayout(uint32 orig_offset, uint32 newgrf_groun
|
|||
foreach_draw_tile_seq(dtss, this->seq) {
|
||||
result_seq.push_back(*dtss);
|
||||
}
|
||||
result_seq.emplace_back() /*C++17: .MakeTerminator()*/;
|
||||
result_seq.back().MakeTerminator();
|
||||
result_seq.emplace_back().MakeTerminator();
|
||||
/* Determine the var10 values the action-1-2-3 chains needs to be resolved for,
|
||||
* and apply the default sprite offsets (unless disabled). */
|
||||
const TileLayoutRegisters *regs = this->registers;
|
||||
|
|
|
@ -2924,8 +2924,7 @@ bool AfterLoadGame()
|
|||
cur_skip = prev_tile_skip;
|
||||
}
|
||||
|
||||
/*C++17: uint &this_skip = */ skip_frames.push_back(prev_tile_skip);
|
||||
uint &this_skip = skip_frames.back();
|
||||
uint &this_skip = skip_frames.emplace_back(prev_tile_skip);
|
||||
|
||||
/* The following 3 curves now take longer than before */
|
||||
switch (u->state) {
|
||||
|
|
|
@ -191,8 +191,7 @@ static void Load_EIDS()
|
|||
_engine_mngr.clear();
|
||||
|
||||
while (SlIterateArray() != -1) {
|
||||
/*C++17: EngineIDMapping *eid = &*/ _engine_mngr.emplace_back();
|
||||
EngineIDMapping *eid = &_engine_mngr.back();
|
||||
EngineIDMapping *eid = &_engine_mngr.emplace_back();
|
||||
SlObject(eid, _engine_id_mapping_desc);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -192,8 +192,7 @@ static void Load_WAYP()
|
|||
int index;
|
||||
|
||||
while ((index = SlIterateArray()) != -1) {
|
||||
/*C++17: OldWaypoint *wp = &*/ _old_waypoints.emplace_back();
|
||||
OldWaypoint *wp = &_old_waypoints.back();
|
||||
OldWaypoint *wp = &_old_waypoints.emplace_back();
|
||||
|
||||
wp->index = index;
|
||||
SlObject(wp, _old_waypoint_desc);
|
||||
|
|
|
@ -118,8 +118,7 @@ public:
|
|||
text += stored_size;
|
||||
}
|
||||
while (length > 0) {
|
||||
/*C++17: OutputBuffer &block =*/ this->output_buffer.emplace_back();
|
||||
OutputBuffer &block = this->output_buffer.back();
|
||||
OutputBuffer &block = this->output_buffer.emplace_back();
|
||||
block.Clear(); // Initialize the new block.
|
||||
size_t stored_size = block.Add(text, length);
|
||||
length -= stored_size;
|
||||
|
|
|
@ -74,8 +74,7 @@ void StringFilter::SetFilterTerm(const char *str)
|
|||
|
||||
/* Add to word */
|
||||
if (word == nullptr) {
|
||||
/*C++17: word = &*/ this->word_index.push_back({dest, false});
|
||||
word = &this->word_index.back();
|
||||
word = &this->word_index.emplace_back(WordState{ dest, false });
|
||||
}
|
||||
|
||||
memcpy(dest, pos, len);
|
||||
|
|
|
@ -710,8 +710,7 @@ CommandCost CmdBuildTunnel(TileIndex start_tile, DoCommandFlag flags, uint32 p1,
|
|||
* Do this for all tiles (like trees), not only objects. */
|
||||
ClearedObjectArea *coa = FindClearedObject(end_tile);
|
||||
if (coa == nullptr) {
|
||||
/*C++17: coa = &*/ _cleared_object_areas.push_back({end_tile, TileArea(end_tile, 1, 1)});
|
||||
coa = &_cleared_object_areas.back();
|
||||
coa = &_cleared_object_areas.emplace_back(ClearedObjectArea{ end_tile, TileArea(end_tile, 1, 1) });
|
||||
}
|
||||
|
||||
/* Hide the tile from the terraforming command */
|
||||
|
|
|
@ -498,8 +498,7 @@ static void AddTileSpriteToDraw(SpriteID image, PaletteID pal, int32 x, int32 y,
|
|||
{
|
||||
assert((image & SPRITE_MASK) < MAX_SPRITES);
|
||||
|
||||
/*C++17: TileSpriteToDraw &ts = */ _vd.tile_sprites_to_draw.emplace_back();
|
||||
TileSpriteToDraw &ts = _vd.tile_sprites_to_draw.back();
|
||||
TileSpriteToDraw &ts = _vd.tile_sprites_to_draw.emplace_back();
|
||||
ts.image = image;
|
||||
ts.pal = pal;
|
||||
ts.sub = sub;
|
||||
|
@ -708,8 +707,7 @@ void AddSortableSpriteToDraw(SpriteID image, PaletteID pal, int x, int y, int w,
|
|||
return;
|
||||
}
|
||||
|
||||
/*C++17: ParentSpriteToDraw &ps = */ _vd.parent_sprites_to_draw.emplace_back();
|
||||
ParentSpriteToDraw &ps = _vd.parent_sprites_to_draw.back();
|
||||
ParentSpriteToDraw &ps = _vd.parent_sprites_to_draw.emplace_back();
|
||||
ps.x = tmp_x;
|
||||
ps.y = tmp_y;
|
||||
|
||||
|
@ -827,8 +825,7 @@ void AddChildSpriteScreen(SpriteID image, PaletteID pal, int x, int y, bool tran
|
|||
|
||||
*_vd.last_child = (uint)_vd.child_screen_sprites_to_draw.size();
|
||||
|
||||
/*C++17: ChildScreenSpriteToDraw &cs = */ _vd.child_screen_sprites_to_draw.emplace_back();
|
||||
ChildScreenSpriteToDraw &cs = _vd.child_screen_sprites_to_draw.back();
|
||||
ChildScreenSpriteToDraw &cs = _vd.child_screen_sprites_to_draw.emplace_back();
|
||||
cs.image = image;
|
||||
cs.pal = pal;
|
||||
cs.sub = sub;
|
||||
|
@ -847,8 +844,7 @@ void AddChildSpriteScreen(SpriteID image, PaletteID pal, int x, int y, bool tran
|
|||
static void AddStringToDraw(int x, int y, StringID string, uint64 params_1, uint64 params_2, Colours colour, uint16 width)
|
||||
{
|
||||
assert(width != 0);
|
||||
/*C++17: StringSpriteToDraw &ss = */ _vd.string_sprites_to_draw.emplace_back();
|
||||
StringSpriteToDraw &ss = _vd.string_sprites_to_draw.back();
|
||||
StringSpriteToDraw &ss = _vd.string_sprites_to_draw.emplace_back();
|
||||
ss.string = string;
|
||||
ss.x = x;
|
||||
ss.y = y;
|
||||
|
|
Loading…
Reference in New Issue