Skip to content

Commit

Permalink
Replace many includes with forward declarations in modules/Maps.h
Browse files Browse the repository at this point in the history
  • Loading branch information
lethosor committed Aug 14, 2016
1 parent 576174e commit e965f53
Show file tree
Hide file tree
Showing 28 changed files with 390 additions and 317 deletions.
1 change: 1 addition & 0 deletions library/LuaApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ distribution.
#include "df/proj_itemst.h"
#include "df/itemdef.h"
#include "df/enabler.h"
#include "df/feature_init.h"

#include <lua.h>
#include <lauxlib.h>
Expand Down
59 changes: 6 additions & 53 deletions library/include/modules/Buildings.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,20 @@ distribution.
#include "Export.h"
#include "DataDefs.h"
#include "Types.h"
#include "modules/Items.h"
#include "modules/Maps.h"

#include "df/building.h"
#include "df/building_stockpilest.h"
#include "df/building_type.h"
#include "df/civzone_type.h"
#include "df/construction_type.h"
#include "df/furnace_type.h"
#include "df/item.h"
#include "df/workshop_type.h"
#include "df/construction_type.h"
#include "df/shop_type.h"
#include "df/siegeengine_type.h"
#include "df/trap_type.h"
#include "modules/Items.h"
#include "modules/Maps.h"
#include "df/workshop_type.h"

namespace df
{
Expand Down Expand Up @@ -220,55 +221,7 @@ class DFHACK_EXPORT StockpileIterator : public std::iterator<std::input_iterator
item = NULL;
}

StockpileIterator& operator++() {
while (stockpile) {
if (block) {
// Check the next item in the current block.
++current;
} else {
// Start with the top-left block covering the stockpile.
block = Maps::getTileBlock(stockpile->x1, stockpile->y1, stockpile->z);
current = 0;
}

while (current >= block->items.size()) {
// Out of items in this block; find the next block to search.
if (block->map_pos.x + 16 < stockpile->x2) {
block = Maps::getTileBlock(block->map_pos.x + 16, block->map_pos.y, stockpile->z);
current = 0;
} else if (block->map_pos.y + 16 < stockpile->y2) {
block = Maps::getTileBlock(stockpile->x1, block->map_pos.y + 16, stockpile->z);
current = 0;
} else {
// All items in all blocks have been checked.
block = NULL;
item = NULL;
return *this;
}
}

// If the current item isn't properly stored, move on to the next.
item = df::item::find(block->items[current]);
if (!item->flags.bits.on_ground) {
continue;
}

if (!Buildings::containsTile(stockpile, item->pos, false)) {
continue;
}

// Ignore empty bins, barrels, and wheelbarrows assigned here.
if (item->isAssignedToThisStockpile(stockpile->id)) {
auto ref = Items::getGeneralRef(item, df::general_ref_type::CONTAINS_ITEM);
if (!ref) continue;
}

// Found a valid item; yield it.
break;
}

return *this;
}
StockpileIterator& operator++();

void begin(df::building_stockpilest* sp) {
stockpile = sp;
Expand Down
39 changes: 25 additions & 14 deletions library/include/modules/Maps.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,33 @@ distribution.
#include "BitArray.h"
#include "modules/Materials.h"

#include "df/world.h"
#include "df/world_data.h"
#include "df/map_block.h"
#include "df/block_square_event.h"
#include "df/block_square_event_mineralst.h"
#include "df/block_square_event_frozen_liquidst.h"
#include "df/block_square_event_world_constructionst.h"
#include "df/block_square_event_material_spatterst.h"
#include "df/block_square_event_grassst.h"
#include "df/block_square_event_spoorst.h"
#include "df/block_square_event_item_spatterst.h"
#include "df/tile_liquid.h"
#include "df/block_flags.h"
#include "df/feature_type.h"
#include "df/flow_type.h"
#include "df/tile_dig_designation.h"
#include "df/tile_liquid.h"
#include "df/tile_traffic.h"
#include "df/feature_init.h"
#include "df/flow_type.h"
#include "df/tiletype.h"

namespace df {
struct block_square_event;
struct block_square_event_frozen_liquidst;
struct block_square_event_grassst;
struct block_square_event_item_spatterst;
struct block_square_event_material_spatterst;
struct block_square_event_mineralst;
struct block_square_event_spoorst;
struct block_square_event_world_constructionst;
struct feature_init;
struct map_block;
struct map_block_column;
struct region_map_entry;
struct world;
struct world_data;
struct world_geo_biome;
union tile_designation;
union tile_occupancy;
}

/**
* \defgroup grp_maps Maps module and its types
Expand Down
55 changes: 55 additions & 0 deletions library/modules/Buildings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ using namespace std;
using namespace DFHack;

#include "DataDefs.h"

#include "df/building_axle_horizontalst.h"
#include "df/building_bars_floorst.h"
#include "df/building_bars_verticalst.h"
Expand All @@ -74,6 +75,8 @@ using namespace DFHack;
#include "df/item.h"
#include "df/job.h"
#include "df/job_item.h"
#include "df/map_block.h"
#include "df/tile_occupancy.h"
#include "df/ui.h"
#include "df/ui_look_list.h"
#include "df/unit.h"
Expand Down Expand Up @@ -1290,3 +1293,55 @@ df::building* Buildings::findPenPitAt(df::coord coord)
}
return NULL;
}

using Buildings::StockpileIterator;
StockpileIterator& StockpileIterator::operator++() {
while (stockpile) {
if (block) {
// Check the next item in the current block.
++current;
} else {
// Start with the top-left block covering the stockpile.
block = Maps::getTileBlock(stockpile->x1, stockpile->y1, stockpile->z);
current = 0;
}

while (current >= block->items.size()) {
// Out of items in this block; find the next block to search.
if (block->map_pos.x + 16 < stockpile->x2) {
block = Maps::getTileBlock(block->map_pos.x + 16, block->map_pos.y, stockpile->z);
current = 0;
} else if (block->map_pos.y + 16 < stockpile->y2) {
block = Maps::getTileBlock(stockpile->x1, block->map_pos.y + 16, stockpile->z);
current = 0;
} else {
// All items in all blocks have been checked.
block = NULL;
item = NULL;
return *this;
}
}

// If the current item isn't properly stored, move on to the next.
item = df::item::find(block->items[current]);
if (!item->flags.bits.on_ground) {
continue;
}

if (!Buildings::containsTile(stockpile, item->pos, false)) {
continue;
}

// Ignore empty bins, barrels, and wheelbarrows assigned here.
if (item->isAssignedToThisStockpile(stockpile->id)) {
auto ref = Items::getGeneralRef(item, df::general_ref_type::CONTAINS_ITEM);
if (!ref) continue;
}

// Found a valid item; yield it.
break;
}

return *this;
}

13 changes: 7 additions & 6 deletions library/modules/Burrows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,21 @@ distribution.
#include <cstdlib>
using namespace std;

#include "Error.h"
#include "Core.h"
#include "DataDefs.h"
#include "Error.h"
#include "MiscUtils.h"

#include "modules/Burrows.h"
#include "modules/Maps.h"
#include "modules/Units.h"

#include "MiscUtils.h"

#include "DataDefs.h"
#include "df/ui.h"
#include "df/burrow.h"
#include "df/block_burrow.h"
#include "df/block_burrow_link.h"
#include "df/burrow.h"
#include "df/map_block.h"
#include "df/ui.h"
#include "df/world.h"

using namespace DFHack;
using namespace df::enums;
Expand Down
16 changes: 8 additions & 8 deletions library/modules/Constructions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,21 @@ distribution.
using namespace std;


#include "VersionInfo.h"
#include "Core.h"
#include "MemAccess.h"
#include "TileTypes.h"
#include "Types.h"
#include "Core.h"
#include "VersionInfo.h"

#include "modules/Constructions.h"
#include "modules/Buildings.h"
#include "modules/Constructions.h"
#include "modules/Maps.h"

#include "TileTypes.h"

#include "df/world.h"
#include "df/job_item.h"
#include "df/building_type.h"
#include "df/building_constructionst.h"
#include "df/building_type.h"
#include "df/job_item.h"
#include "df/map_block.h"
#include "df/world.h"

using namespace DFHack;
using namespace df::enums;
Expand Down
38 changes: 20 additions & 18 deletions library/modules/MapCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,39 +33,41 @@ distribution.
#include <iostream>
using namespace std;

#include "modules/Maps.h"
#include "modules/MapCache.h"
#include "ColorText.h"
#include "Core.h"
#include "DataDefs.h"
#include "Error.h"
#include "VersionInfo.h"
#include "MemAccess.h"
#include "ModuleFactory.h"
#include "Core.h"
#include "MiscUtils.h"
#include "ModuleFactory.h"
#include "VersionInfo.h"

#include "modules/Buildings.h"
#include "modules/MapCache.h"
#include "modules/Maps.h"
#include "modules/Materials.h"

#include "DataDefs.h"
#include "df/world_data.h"
#include "df/world_underground_region.h"
#include "df/world_geo_biome.h"
#include "df/world_geo_layer.h"
#include "df/feature_init.h"
#include "df/world_data.h"
#include "df/burrow.h"
#include "df/block_burrow.h"
#include "df/block_burrow_link.h"
#include "df/world_region_details.h"
#include "df/builtin_mats.h"
#include "df/block_square_event_grassst.h"
#include "df/z_level_flags.h"
#include "df/region_map_entry.h"
#include "df/block_square_event_frozen_liquidst.h"
#include "df/building_type.h"
#include "df/builtin_mats.h"
#include "df/burrow.h"
#include "df/feature_init.h"
#include "df/flow_info.h"
#include "df/plant.h"
#include "df/plant_tree_info.h"
#include "df/plant_tree_tile.h"
#include "df/building_type.h"
#include "df/region_map_entry.h"
#include "df/world.h"
#include "df/world_data.h"
#include "df/world_data.h"
#include "df/world_geo_biome.h"
#include "df/world_geo_layer.h"
#include "df/world_region_details.h"
#include "df/world_underground_region.h"
#include "df/z_level_flags.h"

using namespace DFHack;
using namespace MapExtras;
Expand Down
37 changes: 19 additions & 18 deletions library/modules/Maps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,36 +33,37 @@ distribution.
#include <iostream>
using namespace std;

#include "modules/Maps.h"
#include "modules/MapCache.h"
#include "ColorText.h"
#include "Core.h"
#include "DataDefs.h"
#include "Error.h"
#include "VersionInfo.h"
#include "MemAccess.h"
#include "ModuleFactory.h"
#include "Core.h"
#include "MiscUtils.h"
#include "ModuleFactory.h"
#include "VersionInfo.h"

#include "modules/Buildings.h"
#include "modules/MapCache.h"
#include "modules/Maps.h"

#include "DataDefs.h"
#include "df/world_data.h"
#include "df/world_underground_region.h"
#include "df/world_geo_biome.h"
#include "df/world_geo_layer.h"
#include "df/feature_init.h"
#include "df/world_data.h"
#include "df/burrow.h"
#include "df/block_burrow.h"
#include "df/block_burrow_link.h"
#include "df/world_region_details.h"
#include "df/builtin_mats.h"
#include "df/block_square_event_grassst.h"
#include "df/z_level_flags.h"
#include "df/region_map_entry.h"
#include "df/flow_info.h"
#include "df/building_type.h"
#include "df/builtin_mats.h"
#include "df/burrow.h"
#include "df/feature_init.h"
#include "df/flow_info.h"
#include "df/plant.h"
#include "df/region_map_entry.h"
#include "df/world.h"
#include "df/world_data.h"
#include "df/world_data.h"
#include "df/world_geo_biome.h"
#include "df/world_geo_layer.h"
#include "df/world_region_details.h"
#include "df/world_underground_region.h"
#include "df/z_level_flags.h"

using namespace DFHack;
using namespace df::enums;
Expand Down
Loading

0 comments on commit e965f53

Please sign in to comment.