From cc510a2c4b9887b885c939419bf67147ee997ac6 Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Fri, 20 Jan 2012 14:28:00 +0400 Subject: [PATCH] Replace DFCoord with df::coord and df::coord2d. --- .../block_square_event_mineralst.methods.inc | 4 +- library/include/modules/MapCache.h | 32 ++++----- library/include/modules/Maps.h | 72 +------------------ library/modules/Maps.cpp | 4 +- plugins/filltraffic.cpp | 2 +- plugins/probe.cpp | 2 +- plugins/prospector.cpp | 6 +- 7 files changed, 27 insertions(+), 95 deletions(-) diff --git a/library/include/df/custom/block_square_event_mineralst.methods.inc b/library/include/df/custom/block_square_event_mineralst.methods.inc index 732eeaa1d..e01d22f72 100644 --- a/library/include/df/custom/block_square_event_mineralst.methods.inc +++ b/library/include/df/custom/block_square_event_mineralst.methods.inc @@ -1,4 +1,4 @@ -inline bool getassignment( DFCoord & xy ) +inline bool getassignment( const df::coord2d &xy ) { return getassignment(xy.x,xy.y); } @@ -6,7 +6,7 @@ inline bool getassignment( int x, int y ) { return (tile_bitmask[y] & (1 << x)); } -inline void setassignment( DFCoord & xy, bool bit ) +inline void setassignment( const df::coord2d &xy, bool bit ) { return setassignment(xy.x,xy.y, bit); } diff --git a/library/include/modules/MapCache.h b/library/include/modules/MapCache.h index dab57523b..953a7ed00 100644 --- a/library/include/modules/MapCache.h +++ b/library/include/modules/MapCache.h @@ -105,24 +105,24 @@ class Block valid = true; } } - int16_t veinMaterialAt(DFHack::DFCoord p) + int16_t veinMaterialAt(df::coord2d p) { return veinmats[p.x][p.y]; } - int16_t baseMaterialAt(DFHack::DFCoord p) + int16_t baseMaterialAt(df::coord2d p) { return basemats[p.x][p.y]; } - void ClearMaterialAt(DFHack::DFCoord p) + void ClearMaterialAt(df::coord2d p) { veinmats[p.x][p.y] = -1; } - uint16_t TileTypeAt(DFHack::DFCoord p) + uint16_t TileTypeAt(df::coord2d p) { return raw.tiletypes[p.x][p.y]; } - bool setTiletypeAt(DFHack::DFCoord p, uint16_t tiletype) + bool setTiletypeAt(df::coord2d p, uint16_t tiletype) { if(!valid) return false; dirty_tiletypes = true; @@ -131,11 +131,11 @@ class Block return true; } - uint16_t temperature1At(DFHack::DFCoord p) + uint16_t temperature1At(df::coord2d p) { return temp1[p.x][p.y]; } - bool setTemp1At(DFHack::DFCoord p, uint16_t temp) + bool setTemp1At(df::coord2d p, uint16_t temp) { if(!valid) return false; dirty_temperatures = true; @@ -143,11 +143,11 @@ class Block return true; } - uint16_t temperature2At(DFHack::DFCoord p) + uint16_t temperature2At(df::coord2d p) { return temp2[p.x][p.y]; } - bool setTemp2At(DFHack::DFCoord p, uint16_t temp) + bool setTemp2At(df::coord2d p, uint16_t temp) { if(!valid) return false; dirty_temperatures = true; @@ -155,11 +155,11 @@ class Block return true; } - df::tile_designation DesignationAt(DFHack::DFCoord p) + df::tile_designation DesignationAt(df::coord2d p) { return raw.designation[p.x][p.y]; } - bool setDesignationAt(DFHack::DFCoord p, df::tile_designation des) + bool setDesignationAt(df::coord2d p, df::tile_designation des) { if(!valid) return false; dirty_designations = true; @@ -173,11 +173,11 @@ class Block return true; } - df::tile_occupancy OccupancyAt(DFHack::DFCoord p) + df::tile_occupancy OccupancyAt(df::coord2d p) { return raw.occupancy[p.x][p.y]; } - bool setOccupancyAt(DFHack::DFCoord p, df::tile_occupancy des) + bool setOccupancyAt(df::coord2d p, df::tile_occupancy des) { if(!valid) return false; dirty_occupancies = true; @@ -295,7 +295,7 @@ class MapCache } return 0; } - bool setTiletypeAt(DFHack::DFCoord& tilecoord, uint16_t tiletype) + bool setTiletypeAt(DFHack::DFCoord tilecoord, uint16_t tiletype) { Block * b= BlockAt(tilecoord / 16); if(b && b->valid) @@ -315,7 +315,7 @@ class MapCache } return 0; } - bool setTemp1At(DFHack::DFCoord& tilecoord, uint16_t temperature) + bool setTemp1At(DFHack::DFCoord tilecoord, uint16_t temperature) { Block * b= BlockAt(tilecoord / 16); if(b && b->valid) @@ -335,7 +335,7 @@ class MapCache } return 0; } - bool setTemp2At(DFHack::DFCoord& tilecoord, uint16_t temperature) + bool setTemp2At(DFHack::DFCoord tilecoord, uint16_t temperature) { Block * b= BlockAt(tilecoord / 16); if(b && b->valid) diff --git a/library/include/modules/Maps.h b/library/include/modules/Maps.h index cfb9d142d..72dd45ea2 100644 --- a/library/include/modules/Maps.h +++ b/library/include/modules/Maps.h @@ -67,75 +67,7 @@ namespace DFHack */ extern DFHACK_EXPORT const char * sa_feature(df::feature_type index); -/** - * Class for holding a world coordinate. Can do math with coordinates and can be used as an index for std::map - * \ingroup grp_maps - */ -class DFCoord -{ - public: - DFCoord(uint16_t _x, uint16_t _y, uint16_t _z = 0): x(_x), y(_y), z(_z) {} - DFCoord() - { - comparate = 0; - } - bool operator==(const DFCoord &other) const - { - return (other.comparate == comparate); - } - bool operator!=(const DFCoord &other) const - { - return (other.comparate != comparate); - } - // FIXME: peterix_: you could probably get away with not defining operator< if you defined a std::less specialization for Vertex. - bool operator<(const DFCoord &other) const - { - return comparate < other.comparate; - } - DFCoord operator/(int number) const - { - return DFCoord(x/number, y/number, z); - } - DFCoord operator*(int number) const - { - return DFCoord(x*number, y*number, z); - } - DFCoord operator%(int number) const - { - return DFCoord(x%number, y%number, z); - } - DFCoord operator-(int number) const - { - return DFCoord(x,y,z-number); - } - DFCoord operator+(int number) const - { - return DFCoord(x,y,z+number); - } - // this is a hack. beware. - // x,y,z share the same space with comparate. comparate can be used for fast comparisons - union - { - // new shiny DFCoord struct. notice the ludicrous space for Z-levels - struct - { - uint16_t x; - uint16_t y; - uint32_t z; - }; - // old planeccord struct for compatibility - struct - { - uint16_t x; - uint16_t y; - } dim; - // comparing thing - uint64_t comparate; - }; -}; -/** - * \ingroup grp_maps - */ +typedef df::coord DFCoord; typedef DFCoord planecoord; /** @@ -323,7 +255,7 @@ extern DFHACK_EXPORT bool ReadFeatures(mapblock40d * block, t_feature * local, t * Read a specific global or local feature directly */ extern DFHACK_EXPORT bool GetGlobalFeature(t_feature &feature, int32_t index); -extern DFHACK_EXPORT bool GetLocalFeature(t_feature &feature, DFCoord coord, int32_t index); +extern DFHACK_EXPORT bool GetLocalFeature(t_feature &feature, df::coord2d coord, int32_t index); /* * BLOCK DATA diff --git a/library/modules/Maps.cpp b/library/modules/Maps.cpp index 875bbb6cf..b121aa9f0 100644 --- a/library/modules/Maps.cpp +++ b/library/modules/Maps.cpp @@ -337,7 +337,7 @@ bool Maps::GetGlobalFeature(t_feature &feature, int32_t index) return true; } -bool Maps::GetLocalFeature(t_feature &feature, DFCoord coord, int32_t index) +bool Maps::GetLocalFeature(t_feature &feature, df::coord2d coord, int32_t index) { feature.type = (df::feature_type)-1; if (!world->world_data) @@ -416,7 +416,7 @@ bool Maps::ReadFeatures(uint32_t x, uint32_t y, uint32_t z, t_feature *local, t_ { if (loc != -1) { - DFCoord coord(x,y,0); + df::coord2d coord(x,y); result &= GetLocalFeature(*local, coord, loc); } else diff --git a/plugins/filltraffic.cpp b/plugins/filltraffic.cpp index b7853b1ba..c87b50165 100644 --- a/plugins/filltraffic.cpp +++ b/plugins/filltraffic.cpp @@ -300,7 +300,7 @@ DFhackCExport command_result setAllMatching(DFHack::Core * c, checkTile checkPro //Ensure maximum coordinate is within map. Truncate to map edge. maxCoord.x = std::min((uint32_t) maxCoord.x, tx_max); maxCoord.y = std::min((uint32_t) maxCoord.y, ty_max); - maxCoord.z = std::min(maxCoord.z, z_max); + maxCoord.z = std::min((uint32_t) maxCoord.z, z_max); //Check minimum co-ordinates against maximum map size if (minCoord.x > maxCoord.x) diff --git a/plugins/probe.cpp b/plugins/probe.cpp index 878dbb126..637cf3b6f 100644 --- a/plugins/probe.cpp +++ b/plugins/probe.cpp @@ -246,7 +246,7 @@ DFhackCExport command_result df_probe (Core * c, vector & parameters) PRINT_FLAG( bits.water_table ); PRINT_FLAG( bits.rained ); - DFCoord pc(blockX, blockY); + df::coord2d pc(blockX, blockY); t_feature local; t_feature global; diff --git a/plugins/prospector.cpp b/plugins/prospector.cpp index a81e5986a..334d4fff3 100644 --- a/plugins/prospector.cpp +++ b/plugins/prospector.cpp @@ -270,7 +270,7 @@ DFhackCExport command_result prospector (DFHack::Core * c, vector & par for(uint32_t b_x = 0; b_x < x_max; b_x++) { // Get the map block - DFHack::DFCoord blockCoord(b_x, b_y); + df::coord2d blockCoord(b_x, b_y); MapExtras::Block *b = map.BlockAt(DFHack::DFCoord(b_x, b_y, z)); if (!b || !b->valid) { @@ -294,7 +294,7 @@ DFhackCExport command_result prospector (DFHack::Core * c, vector & par { for(uint32_t x = 0; x < 16; x++) { - DFHack::DFCoord coord(x, y); + df::coord2d coord(x, y); df::tile_designation des = b->DesignationAt(coord); df::tile_occupancy occ = b->OccupancyAt(coord); @@ -398,7 +398,7 @@ DFhackCExport command_result prospector (DFHack::Core * c, vector & par for (PlantList::const_iterator it = plants->begin(); it != plants->end(); it++) { const DFHack::df_plant & plant = *(*it); - DFHack::DFCoord loc(plant.x, plant.y); + df::coord2d loc(plant.x, plant.y); loc = loc % 16; if (showHidden || !b->DesignationAt(loc).bits.hidden) {