Switching autotrade to use StockpileIterator.

This should speed it up a bit, and prevents it from marking a stream of empty bins.
develop
Eric Wald 2014-09-07 14:03:51 -06:00
parent 567397df85
commit 3c58bd3948
2 changed files with 15 additions and 10 deletions

@ -8,6 +8,7 @@
#include "df/viewscreen_dwarfmodest.h" #include "df/viewscreen_dwarfmodest.h"
#include "df/viewscreen_tradegoodsst.h" #include "df/viewscreen_tradegoodsst.h"
#include "df/building_stockpilest.h" #include "df/building_stockpilest.h"
#include "modules/Buildings.h"
#include "modules/Items.h" #include "modules/Items.h"
#include "df/building_tradedepotst.h" #include "df/building_tradedepotst.h"
#include "df/general_ref_building_holderst.h" #include "df/general_ref_building_holderst.h"
@ -202,8 +203,6 @@ static void mark_all_in_stockpiles(vector<PersistentStockpileInfo> &stockpiles)
if (!depot_info.findDepot()) if (!depot_info.findDepot())
return; return;
std::vector<df::item*> &items = world->items.other[items_other_id::IN_PLAY];
// Precompute a bitmask with the bad flags // Precompute a bitmask with the bad flags
df::item_flags bad_flags; df::item_flags bad_flags;
@ -218,18 +217,19 @@ static void mark_all_in_stockpiles(vector<PersistentStockpileInfo> &stockpiles)
size_t marked_count = 0; size_t marked_count = 0;
size_t error_count = 0; size_t error_count = 0;
for (size_t i = 0; i < items.size(); i++) for (auto it = stockpiles.begin(); it != stockpiles.end(); it++)
{ {
df::item *item = items[i]; if (!it->isValid())
if (item->flags.whole & bad_flags.whole)
continue;
if (!is_valid_item(item))
continue; continue;
for (auto it = stockpiles.begin(); it != stockpiles.end(); it++) Buildings::StockpileIterator stored;
for (stored.begin(it->getStockpile()); !stored.done(); ++stored)
{ {
if (!it->inStockpile(item)) df::item *item = *stored;
if (item->flags.whole & bad_flags.whole)
continue;
if (!is_valid_item(item))
continue; continue;
// In case of container, check contained items for mandates // In case of container, check contained items for mandates

@ -346,6 +346,11 @@ public:
return this->sp == sp; return this->sp == sp;
} }
df::building_stockpilest* getStockpile()
{
return sp;
}
protected: protected:
int32_t id; int32_t id;
df::building_stockpilest* sp; df::building_stockpilest* sp;