Changeset - r27134:d8d895cb8380
[Not reviewed]
master
0 4 0
Peter Nelson - 23 months ago 2023-01-08 01:36:07
peter1138@openttd.org
Codechange: Initialise specs with std::fill/std::copy instead of memset/memcpy.
4 files changed with 15 insertions and 19 deletions:
0 comments (0 inline, 0 general)
src/industry_cmd.cpp
Show inline comments
 
@@ -76,21 +76,16 @@ IndustryBuildData _industry_builder; ///
 
 */
 
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();
src/newgrf_airport.cpp
Show inline comments
 
@@ -152,9 +152,10 @@ bool AirportSpec::IsWithinMapBounds(byte
 
 */
 
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();
 
}
src/newgrf_airporttiles.cpp
Show inline comments
 
@@ -57,8 +57,8 @@ AirportTileOverrideManager _airporttile_
 
 */
 
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();
src/town_cmd.cpp
Show inline comments
 
@@ -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();
0 comments (0 inline, 0 general)