Use Binsearch for finding items.

develop
Japa 2016-10-29 08:54:27 +05:30
parent 0edce2b3ae
commit 148202bcba
1 changed files with 18 additions and 24 deletions

@ -964,13 +964,10 @@ map<int, uint16_t> itemHashes;
bool isItemChanged(int i) bool isItemChanged(int i)
{ {
uint16_t hash = 0; uint16_t hash = 0;
if (i >= 0 && i < world->items.all.size()) auto item = df::item::find(i);
if (item)
{ {
auto item = world->items.all[i]; hash = fletcher16((uint8_t*)item, sizeof(df::item));
if (item)
{
hash = fletcher16((uint8_t*)item, sizeof(df::item));
}
} }
if (itemHashes[i] != hash) if (itemHashes[i] != hash)
{ {
@ -1451,17 +1448,17 @@ void CopyBuildings(df::map_block * DfBlock, RemoteFortressReader::MapBlock * Net
continue; continue;
auto out_bld = NetBlock->add_buildings(); auto out_bld = NetBlock->add_buildings();
CopyBuilding(i, out_bld); CopyBuilding(i, out_bld);
df::building_actual* actualBuilding = strict_virtual_cast<df::building_actual>(bld); //df::building_actual* actualBuilding = strict_virtual_cast<df::building_actual>(bld);
if (actualBuilding) //if (actualBuilding)
{ //{
for (int i = 0; i < actualBuilding->contained_items.size(); i++) // for (int i = 0; i < actualBuilding->contained_items.size(); i++)
{ // {
if (isItemChanged(actualBuilding->contained_items[i]->item->id)) // if (isItemChanged(actualBuilding->contained_items[i]->item->id))
{ // {
CopyItem(NetBlock->add_items(), actualBuilding->contained_items[i]->item); // CopyItem(NetBlock->add_items(), actualBuilding->contained_items[i]->item);
} // }
} // }
} //}
} }
} }
@ -1530,13 +1527,10 @@ void CopyItems(df::map_block * DfBlock, RemoteFortressReader::MapBlock * NetBloc
{ {
int id = DfBlock->items[i]; int id = DfBlock->items[i];
if (id < 0)
continue;
if (id >= world->items.all.size())
continue;
auto item = world->items.all[id]; auto item = df::item::find(id);
CopyItem(NetBlock->add_items(), item); if(item)
CopyItem(NetBlock->add_items(), item);
} }
} }