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
 
@@ -186,8 +186,7 @@ static uint32 GetNearbyObjectTileInforma
 
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));
src/object_base.h
Show inline comments
 
@@ -78,9 +78,6 @@ 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.
 
 */
src/object_cmd.cpp
Show inline comments
 
@@ -173,8 +173,7 @@ void UpdateCompanyHQ(TileIndex tile, uin
 
 */
 
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;
src/saveload/afterload.cpp
Show inline comments
 
@@ -253,8 +253,7 @@ static void InitializeWindowsAndCaches()
 
	}
 

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

	
 
@@ -2474,8 +2473,7 @@ 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;
 
		}
src/saveload/object_sl.cpp
Show inline comments
 
@@ -31,10 +31,8 @@ static const SaveLoad _object_desc[] = {
 

	
 
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);
 
	}
 
@@ -51,8 +49,7 @@ static void Load_OBJS()
 

	
 
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. */
src/town_cmd.cpp
Show inline comments
 
@@ -115,8 +115,7 @@ Town::~Town()
 
	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) {
 
@@ -159,8 +158,7 @@ void Town::PostDestructor(size_t index)
 
	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);
 
	}
 
}
0 comments (0 inline, 0 general)