Changeset - r23968:689ddfd1479d
[Not reviewed]
master
0 6 0
glx - 4 years ago 2019-12-17 18:05:46
glx@openttd.org
Codechange: Replace FOR_ALL_OBJECTS with range-based for loops
6 files changed with 8 insertions and 20 deletions:
0 comments (0 inline, 0 general)
src/newgrf_object.cpp
Show inline comments
 
@@ -183,14 +183,13 @@ static uint32 GetNearbyObjectTileInforma
 
 * @param current The current object (to ignore).
 
 * @return The distance to the closest object.
 
 */
 
static uint32 GetClosestObject(TileIndex tile, ObjectType type, const Object *current)
 
{
 
	uint32 best_dist = UINT32_MAX;
 
	const Object *o;
 
	FOR_ALL_OBJECTS(o) {
 
	for (const Object *o : Object::Iterate()) {
 
		if (o->type != type || o == current) continue;
 

	
 
		best_dist = min(best_dist, DistanceManhattan(tile, o->location.tile));
 
	}
 

	
 
	return best_dist;
src/object_base.h
Show inline comments
 
@@ -75,15 +75,12 @@ struct Object : ObjectPool::PoolItem<&_o
 
	}
 

	
 
protected:
 
	static uint16 counts[NUM_OBJECTS]; ///< Number of objects per type ingame
 
};
 

	
 
#define FOR_ALL_OBJECTS_FROM(var, start) FOR_ALL_ITEMS_FROM(Object, object_index, var, start)
 
#define FOR_ALL_OBJECTS(var) FOR_ALL_OBJECTS_FROM(var, 0)
 

	
 
/**
 
 * Keeps track of removed objects during execution/testruns of commands.
 
 */
 
struct ClearedObjectArea {
 
	TileIndex first_tile;  ///< The first tile being cleared, which then causes the whole object to be cleared.
 
	TileArea area;         ///< The area of the object.
src/object_cmd.cpp
Show inline comments
 
@@ -170,14 +170,13 @@ void UpdateCompanyHQ(TileIndex tile, uin
 
/**
 
 * Updates the colour of the object whenever a company changes.
 
 * @param c The company the company colour changed of.
 
 */
 
void UpdateObjectColours(const Company *c)
 
{
 
	Object *obj;
 
	FOR_ALL_OBJECTS(obj) {
 
	for (Object *obj : Object::Iterate()) {
 
		Owner owner = GetTileOwner(obj->location.tile);
 
		/* Not the current owner, so colour doesn't change. */
 
		if (owner != c->index) continue;
 

	
 
		const ObjectSpec *spec = ObjectSpec::GetByTile(obj->location.tile);
 
		/* Using the object colour callback, so not using company colour. */
src/saveload/afterload.cpp
Show inline comments
 
@@ -250,14 +250,13 @@ static void InitializeWindowsAndCaches()
 
		if (_file_to_saveload.abstract_ftype == FT_SCENARIO && c->inaugurated_year != MIN_YEAR) {
 
			c->inaugurated_year = _cur_year;
 
		}
 
	}
 

	
 
	/* Count number of objects per type */
 
	Object *o;
 
	FOR_ALL_OBJECTS(o) {
 
	for (Object *o : Object::Iterate()) {
 
		Object::IncTypeCount(o->type);
 
	}
 

	
 
	/* Identify owners of persistent storage arrays */
 
	for (Industry *i : Industry::Iterate()) {
 
		if (i->psa != nullptr) {
 
@@ -2471,14 +2470,13 @@ bool AfterLoadGame()
 
			}
 
		}
 
	}
 

	
 
	/* Add (random) colour to all objects. */
 
	if (IsSavegameVersionBefore(SLV_148)) {
 
		Object *o;
 
		FOR_ALL_OBJECTS(o) {
 
		for (Object *o : Object::Iterate()) {
 
			Owner owner = GetTileOwner(o->location.tile);
 
			o->colour = (owner == OWNER_NONE) ? Random() & 0xF : Company::Get(owner)->livery->colour1;
 
		}
 
	}
 

	
 
	if (IsSavegameVersionBefore(SLV_149)) {
src/saveload/object_sl.cpp
Show inline comments
 
@@ -28,16 +28,14 @@ static const SaveLoad _object_desc[] = {
 

	
 
	SLE_END()
 
};
 

	
 
static void Save_OBJS()
 
{
 
	Object *o;
 

	
 
	/* Write the objects */
 
	FOR_ALL_OBJECTS(o) {
 
	for (Object *o : Object::Iterate()) {
 
		SlSetArrayIndex(o->index);
 
		SlObject(o, _object_desc);
 
	}
 
}
 

	
 
static void Load_OBJS()
 
@@ -48,14 +46,13 @@ static void Load_OBJS()
 
		SlObject(o, _object_desc);
 
	}
 
}
 

	
 
static void Ptrs_OBJS()
 
{
 
	Object *o;
 
	FOR_ALL_OBJECTS(o) {
 
	for (Object *o : Object::Iterate()) {
 
		SlObject(o, _object_desc);
 
		if (IsSavegameVersionBefore(SLV_148) && !IsTileType(o->location.tile, MP_OBJECT)) {
 
			/* Due to a small bug stale objects could remain. */
 
			delete o;
 
		}
 
	}
src/town_cmd.cpp
Show inline comments
 
@@ -112,14 +112,13 @@ Town::~Town()
 
	DeleteWindowById(WC_TOWN_VIEW, this->index);
 

	
 
	/* Check no industry is related to us. */
 
	for (const Industry *i : Industry::Iterate()) assert(i->town != this);
 

	
 
	/* ... and no object is related to us. */
 
	const Object *o;
 
	FOR_ALL_OBJECTS(o) assert(o->town != this);
 
	for (const Object *o : Object::Iterate()) assert(o->town != this);
 

	
 
	/* Check no tile is related to us. */
 
	for (TileIndex tile = 0; tile < MapSize(); ++tile) {
 
		switch (GetTileType(tile)) {
 
			case MP_HOUSE:
 
				assert(GetTownIndex(tile) != this->index);
 
@@ -156,14 +155,13 @@ Town::~Town()
 
void Town::PostDestructor(size_t index)
 
{
 
	InvalidateWindowData(WC_TOWN_DIRECTORY, 0, 0);
 
	UpdateNearestTownForRoadTiles(false);
 

	
 
	/* Give objects a new home! */
 
	Object *o;
 
	FOR_ALL_OBJECTS(o) {
 
	for (Object *o : Object::Iterate()) {
 
		if (o->town == nullptr) o->town = CalcClosestTownFromTile(o->location.tile, UINT_MAX);
 
	}
 
}
 

	
 
/**
 
 * Assigns town layout. If Random, generates one based on TileHash.
0 comments (0 inline, 0 general)