Codechange: Initialise specs with std::fill/std::copy instead of memset/memcpy.

This commit is contained in:
Peter Nelson 2023-01-08 01:36:07 +00:00 committed by PeterN
parent d0c71f2a9e
commit 087654501b
4 changed files with 14 additions and 18 deletions

View File

@ -76,21 +76,16 @@ IndustryBuildData _industry_builder; ///< In-game manager of industries.
*/
void ResetIndustries()
{
for (IndustryType i = 0; i < NUM_INDUSTRYTYPES; i++) {
/* Reset the spec to default */
if (i < lengthof(_origin_industry_specs)) {
_industry_specs[i] = _origin_industry_specs[i];
} else {
_industry_specs[i] = IndustrySpec{};
}
auto industry_insert = std::copy(std::begin(_origin_industry_specs), std::end(_origin_industry_specs), std::begin(_industry_specs));
std::fill(industry_insert, std::end(_industry_specs), IndustrySpec{});
for (IndustryType i = 0; i < lengthof(_origin_industry_specs); i++) {
/* Enable only the current climate industries */
_industry_specs[i].enabled = i < NEW_INDUSTRYOFFSET &&
HasBit(_origin_industry_specs[i].climate_availability, _settings_game.game_creation.landscape);
_industry_specs[i].enabled = HasBit(_industry_specs[i].climate_availability, _settings_game.game_creation.landscape);
}
memset(&_industry_tile_specs, 0, sizeof(_industry_tile_specs));
memcpy(&_industry_tile_specs, &_origin_industry_tile_specs, sizeof(_origin_industry_tile_specs));
auto industry_tile_insert = std::copy(std::begin(_origin_industry_tile_specs), std::end(_origin_industry_tile_specs), std::begin(_industry_tile_specs));
std::fill(industry_tile_insert, std::end(_industry_tile_specs), IndustryTileSpec{});
/* Reset any overrides that have been set. */
_industile_mngr.ResetOverride();

View File

@ -152,9 +152,10 @@ bool AirportSpec::IsWithinMapBounds(byte table, TileIndex tile) const
*/
void AirportSpec::ResetAirports()
{
extern const AirportSpec _origin_airport_specs[];
memset(&AirportSpec::specs, 0, sizeof(AirportSpec::specs));
memcpy(&AirportSpec::specs, &_origin_airport_specs, sizeof(AirportSpec) * NEW_AIRPORT_OFFSET);
extern const AirportSpec _origin_airport_specs[NEW_AIRPORT_OFFSET];
auto insert = std::copy(std::begin(_origin_airport_specs), std::end(_origin_airport_specs), std::begin(AirportSpec::specs));
std::fill(insert, std::end(AirportSpec::specs), AirportSpec{});
_airport_mngr.ResetOverride();
}

View File

@ -57,8 +57,8 @@ AirportTileOverrideManager _airporttile_mngr(NEW_AIRPORTTILE_OFFSET, NUM_AIRPORT
*/
void AirportTileSpec::ResetAirportTiles()
{
memset(&AirportTileSpec::tiles, 0, sizeof(AirportTileSpec::tiles));
memcpy(&AirportTileSpec::tiles, &_origin_airporttile_specs, sizeof(_origin_airporttile_specs));
auto insert = std::copy(std::begin(_origin_airporttile_specs), std::end(_origin_airporttile_specs), std::begin(AirportTileSpec::tiles));
std::fill(insert, std::end(AirportTileSpec::tiles), AirportTileSpec{});
/* Reset any overrides that have been set. */
_airporttile_mngr.ResetOverride();

View File

@ -3834,8 +3834,8 @@ HouseSpec _house_specs[NUM_HOUSES];
void ResetHouses()
{
memset(&_house_specs, 0, sizeof(_house_specs));
memcpy(&_house_specs, &_original_house_specs, sizeof(_original_house_specs));
auto insert = std::copy(std::begin(_original_house_specs), std::end(_original_house_specs), std::begin(_house_specs));
std::fill(insert, std::end(_house_specs), HouseSpec{});
/* Reset any overrides that have been set. */
_house_mngr.ResetOverride();