mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-12 18:40:29 +00:00
(svn r24180) -Codechange/feature-ish: add cache checker for the town's cache
This commit is contained in:
parent
41e5c839e0
commit
b926277caf
@ -59,6 +59,7 @@
|
|||||||
#include "misc/getoptdata.h"
|
#include "misc/getoptdata.h"
|
||||||
#include "game/game.hpp"
|
#include "game/game.hpp"
|
||||||
#include "game/game_config.hpp"
|
#include "game/game_config.hpp"
|
||||||
|
#include "town.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -1134,6 +1135,24 @@ static void CheckCaches()
|
|||||||
* always to aid testing of caches. */
|
* always to aid testing of caches. */
|
||||||
if (_debug_desync_level <= 1) return;
|
if (_debug_desync_level <= 1) return;
|
||||||
|
|
||||||
|
/* Check the town caches. */
|
||||||
|
SmallVector<TownCache, 4> old_town_caches;
|
||||||
|
Town *t;
|
||||||
|
FOR_ALL_TOWNS(t) {
|
||||||
|
MemCpyT(old_town_caches.Append(), &t->cache);
|
||||||
|
}
|
||||||
|
|
||||||
|
extern void RebuildTownCaches();
|
||||||
|
RebuildTownCaches();
|
||||||
|
|
||||||
|
uint i = 0;
|
||||||
|
FOR_ALL_TOWNS(t) {
|
||||||
|
if (MemCmpT(old_town_caches.Get(i), &t->cache) != 0) {
|
||||||
|
DEBUG(desync, 2, "town cache mismatch: town %i", (int)t->index);
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
/* Check company infrastructure cache. */
|
/* Check company infrastructure cache. */
|
||||||
SmallVector<CompanyInfrastructure, 4> old_infrastructure;
|
SmallVector<CompanyInfrastructure, 4> old_infrastructure;
|
||||||
Company *c;
|
Company *c;
|
||||||
@ -1142,7 +1161,7 @@ static void CheckCaches()
|
|||||||
extern void AfterLoadCompanyStats();
|
extern void AfterLoadCompanyStats();
|
||||||
AfterLoadCompanyStats();
|
AfterLoadCompanyStats();
|
||||||
|
|
||||||
uint i = 0;
|
i = 0;
|
||||||
FOR_ALL_COMPANIES(c) {
|
FOR_ALL_COMPANIES(c) {
|
||||||
if (MemCmpT(old_infrastructure.Get(i), &c->infrastructure) != 0) {
|
if (MemCmpT(old_infrastructure.Get(i), &c->infrastructure) != 0) {
|
||||||
DEBUG(desync, 2, "infrastructure cache mismatch: company %i", (int)c->index);
|
DEBUG(desync, 2, "infrastructure cache mismatch: company %i", (int)c->index);
|
||||||
|
@ -13,10 +13,47 @@
|
|||||||
#include "../newgrf_house.h"
|
#include "../newgrf_house.h"
|
||||||
#include "../town.h"
|
#include "../town.h"
|
||||||
#include "../landscape.h"
|
#include "../landscape.h"
|
||||||
|
#include "../subsidy_func.h"
|
||||||
|
|
||||||
#include "saveload.h"
|
#include "saveload.h"
|
||||||
#include "newgrf_sl.h"
|
#include "newgrf_sl.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rebuild all the cached variables of towns.
|
||||||
|
*/
|
||||||
|
void RebuildTownCaches()
|
||||||
|
{
|
||||||
|
Town *town;
|
||||||
|
InitializeBuildingCounts();
|
||||||
|
|
||||||
|
/* Reset town population and num_houses */
|
||||||
|
FOR_ALL_TOWNS(town) {
|
||||||
|
town->cache.population = 0;
|
||||||
|
town->cache.num_houses = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (TileIndex t = 0; t < MapSize(); t++) {
|
||||||
|
if (!IsTileType(t, MP_HOUSE)) continue;
|
||||||
|
|
||||||
|
HouseID house_id = GetCleanHouseType(t);
|
||||||
|
town = Town::GetByTile(t);
|
||||||
|
IncreaseBuildingCount(town, house_id);
|
||||||
|
if (IsHouseCompleted(t)) town->cache.population += HouseSpec::Get(house_id)->population;
|
||||||
|
|
||||||
|
/* Increase the number of houses for every house, but only once. */
|
||||||
|
if (GetHouseNorthPart(house_id) == 0) town->cache.num_houses++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Update the population and num_house dependant values */
|
||||||
|
FOR_ALL_TOWNS(town) {
|
||||||
|
UpdateTownRadius(town);
|
||||||
|
UpdateTownCargoes(town);
|
||||||
|
}
|
||||||
|
UpdateTownCargoBitmap();
|
||||||
|
|
||||||
|
RebuildSubsidisedSourceAndDestinationCache();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check and update town and house values.
|
* Check and update town and house values.
|
||||||
*
|
*
|
||||||
@ -27,15 +64,6 @@
|
|||||||
*/
|
*/
|
||||||
void UpdateHousesAndTowns()
|
void UpdateHousesAndTowns()
|
||||||
{
|
{
|
||||||
Town *town;
|
|
||||||
InitializeBuildingCounts();
|
|
||||||
|
|
||||||
/* Reset town population and num_houses */
|
|
||||||
FOR_ALL_TOWNS(town) {
|
|
||||||
town->cache.population = 0;
|
|
||||||
town->cache.num_houses = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (TileIndex t = 0; t < MapSize(); t++) {
|
for (TileIndex t = 0; t < MapSize(); t++) {
|
||||||
if (!IsTileType(t, MP_HOUSE)) continue;
|
if (!IsTileType(t, MP_HOUSE)) continue;
|
||||||
|
|
||||||
@ -82,24 +110,7 @@ void UpdateHousesAndTowns()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (TileIndex t = 0; t < MapSize(); t++) {
|
RebuildTownCaches();
|
||||||
if (!IsTileType(t, MP_HOUSE)) continue;
|
|
||||||
|
|
||||||
HouseID house_id = GetCleanHouseType(t);
|
|
||||||
town = Town::GetByTile(t);
|
|
||||||
IncreaseBuildingCount(town, house_id);
|
|
||||||
if (IsHouseCompleted(t)) town->cache.population += HouseSpec::Get(house_id)->population;
|
|
||||||
|
|
||||||
/* Increase the number of houses for every house, but only once. */
|
|
||||||
if (GetHouseNorthPart(house_id) == 0) town->cache.num_houses++;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Update the population and num_house dependant values */
|
|
||||||
FOR_ALL_TOWNS(town) {
|
|
||||||
UpdateTownRadius(town);
|
|
||||||
UpdateTownCargoes(town);
|
|
||||||
}
|
|
||||||
UpdateTownCargoBitmap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Save and load of towns. */
|
/** Save and load of towns. */
|
||||||
|
Loading…
Reference in New Issue
Block a user