From c53b6438860985f10d3d5412b4e7e18a1d526190 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Thu, 17 Jun 2010 06:46:20 +0200 Subject: [PATCH] Fix liquids bug, added status checks to Maps (still not the real thing, but better) --- library/include/dfhack/DFError.h | 10 ++++ library/modules/Maps.cpp | 29 +++++++-- tools/playground/CMakeLists.txt | 2 +- tools/playground/incrementalsearch.cpp | 81 ++++++++++++++++++++++++++ tools/playground/typeblocks.cpp | 43 ++++++++++++++ tools/supported/liquids.cpp | 4 +- 6 files changed, 162 insertions(+), 7 deletions(-) create mode 100644 tools/playground/typeblocks.cpp diff --git a/library/include/dfhack/DFError.h b/library/include/dfhack/DFError.h index d838c5623..79823a9fa 100644 --- a/library/include/dfhack/DFError.h +++ b/library/include/dfhack/DFError.h @@ -297,6 +297,16 @@ namespace DFHack return "SHM ATTACH FAILURE"; } }; + class DFHACK_EXPORT ModuleNotInitialized : public std::exception + { + public: + ModuleNotInitialized() {} + virtual ~ModuleNotInitialized() throw(){}; + virtual const char* what() const throw() + { + return "Programmer error: module not initialized!"; + } + }; } } diff --git a/library/modules/Maps.cpp b/library/modules/Maps.cpp index af0a8be9b..b14b7f062 100644 --- a/library/modules/Maps.cpp +++ b/library/modules/Maps.cpp @@ -37,7 +37,7 @@ distribution. #define SHMCMD(num) ((shm_cmd *)d->d->shm_start)[num]->pingpong #define SHMHDR ((shm_core_hdr *)d->d->shm_start) #define SHMDATA(type) ((type *)(d->d->shm_start + SHM_HEADER)) - +#define MAPS_GUARD if(!d->Started) throw DFHack::Error::ModuleNotInitialized(); using namespace DFHack; struct Maps::Private @@ -101,9 +101,6 @@ Maps::Maps(DFContextShared* _d) off.world_size_x = mem->getAddress ("world_size_x"); off.world_size_y = mem->getAddress ("world_size_y"); - - - // these can fail and will be found when looking at the actual veins later // basically a cache off.vein_ice_vptr = 0; @@ -193,6 +190,7 @@ bool Maps::Start() // getter for map size void Maps::getSize (uint32_t& x, uint32_t& y, uint32_t& z) { + MAPS_GUARD x = d->x_block_count; y = d->y_block_count; z = d->z_block_count; @@ -216,6 +214,7 @@ bool Maps::Finish() bool Maps::isValidBlock (uint32_t x, uint32_t y, uint32_t z) { + MAPS_GUARD if ( x >= d->x_block_count || y >= d->y_block_count || z >= d->z_block_count) return false; return d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z] != 0; @@ -223,6 +222,7 @@ bool Maps::isValidBlock (uint32_t x, uint32_t y, uint32_t z) uint32_t Maps::getBlockPtr (uint32_t x, uint32_t y, uint32_t z) { + MAPS_GUARD if ( x >= d->x_block_count || y >= d->y_block_count || z >= d->z_block_count) return 0; return d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z]; @@ -230,6 +230,7 @@ uint32_t Maps::getBlockPtr (uint32_t x, uint32_t y, uint32_t z) bool Maps::ReadBlock40d(uint32_t x, uint32_t y, uint32_t z, mapblock40d * buffer) { + MAPS_GUARD Process *p = d->owner; if(d->d->shm_start && d->maps_module) // ACCELERATE! { @@ -268,6 +269,7 @@ bool Maps::ReadBlock40d(uint32_t x, uint32_t y, uint32_t z, mapblock40d * buffer bool Maps::ReadTileTypes (uint32_t x, uint32_t y, uint32_t z, tiletypes40d *buffer) { + MAPS_GUARD uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z]; if (addr) { @@ -279,6 +281,7 @@ bool Maps::ReadTileTypes (uint32_t x, uint32_t y, uint32_t z, tiletypes40d *buff bool Maps::WriteTileTypes (uint32_t x, uint32_t y, uint32_t z, tiletypes40d *buffer) { + MAPS_GUARD uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z]; if (addr) { @@ -294,6 +297,7 @@ bool Maps::WriteTileTypes (uint32_t x, uint32_t y, uint32_t z, tiletypes40d *buf bool Maps::ReadDirtyBit(uint32_t x, uint32_t y, uint32_t z, bool &dirtybit) { + MAPS_GUARD uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z]; if(addr) { @@ -307,6 +311,7 @@ bool Maps::ReadDirtyBit(uint32_t x, uint32_t y, uint32_t z, bool &dirtybit) bool Maps::WriteDirtyBit(uint32_t x, uint32_t y, uint32_t z, bool dirtybit) { + MAPS_GUARD uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z]; if (addr) { @@ -324,6 +329,7 @@ bool Maps::WriteDirtyBit(uint32_t x, uint32_t y, uint32_t z, bool dirtybit) /// read/write the block flags bool Maps::ReadBlockFlags(uint32_t x, uint32_t y, uint32_t z, t_blockflags &blockflags) { + MAPS_GUARD uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z]; if(addr) { @@ -336,6 +342,7 @@ bool Maps::ReadBlockFlags(uint32_t x, uint32_t y, uint32_t z, t_blockflags &bloc } bool Maps::WriteBlockFlags(uint32_t x, uint32_t y, uint32_t z, t_blockflags blockflags) { + MAPS_GUARD uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z]; if (addr) { @@ -353,6 +360,7 @@ bool Maps::WriteBlockFlags(uint32_t x, uint32_t y, uint32_t z, t_blockflags bloc bool Maps::ReadDesignations (uint32_t x, uint32_t y, uint32_t z, designations40d *buffer) { + MAPS_GUARD uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z]; if (addr) { @@ -364,6 +372,7 @@ bool Maps::ReadDesignations (uint32_t x, uint32_t y, uint32_t z, designations40d bool Maps::WriteDesignations (uint32_t x, uint32_t y, uint32_t z, designations40d *buffer) { + MAPS_GUARD uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z]; if (addr) { @@ -379,6 +388,7 @@ bool Maps::WriteDesignations (uint32_t x, uint32_t y, uint32_t z, designations40 bool Maps::ReadOccupancy (uint32_t x, uint32_t y, uint32_t z, occupancies40d *buffer) { + MAPS_GUARD uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z]; if (addr) { @@ -390,6 +400,7 @@ bool Maps::ReadOccupancy (uint32_t x, uint32_t y, uint32_t z, occupancies40d *bu bool Maps::WriteOccupancy (uint32_t x, uint32_t y, uint32_t z, occupancies40d *buffer) { + MAPS_GUARD uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z]; if (addr) { @@ -404,6 +415,7 @@ bool Maps::WriteOccupancy (uint32_t x, uint32_t y, uint32_t z, occupancies40d *b */ bool Maps::ReadTemperatures(uint32_t x, uint32_t y, uint32_t z, t_temperatures *temp1, t_temperatures *temp2) { + MAPS_GUARD uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z]; if (addr) { @@ -417,6 +429,7 @@ bool Maps::ReadTemperatures(uint32_t x, uint32_t y, uint32_t z, t_temperatures * } bool Maps::WriteTemperatures (uint32_t x, uint32_t y, uint32_t z, t_temperatures *temp1, t_temperatures *temp2) { + MAPS_GUARD uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z]; if (addr) { @@ -434,6 +447,7 @@ bool Maps::WriteTemperatures (uint32_t x, uint32_t y, uint32_t z, t_temperatures */ bool Maps::ReadRegionOffsets (uint32_t x, uint32_t y, uint32_t z, biome_indices40d *buffer) { + MAPS_GUARD uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z]; if (addr) { @@ -445,6 +459,7 @@ bool Maps::ReadRegionOffsets (uint32_t x, uint32_t y, uint32_t z, biome_indices4 bool Maps::ReadFeatures(uint32_t x, uint32_t y, uint32_t z, int16_t & local, int16_t & global) { + MAPS_GUARD uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z]; if (addr) { @@ -458,6 +473,7 @@ bool Maps::ReadFeatures(uint32_t x, uint32_t y, uint32_t z, int16_t & local, int bool Maps::WriteLocalFeature(uint32_t x, uint32_t y, uint32_t z, int16_t local) { + MAPS_GUARD uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z]; if (addr) { @@ -470,6 +486,7 @@ bool Maps::WriteLocalFeature(uint32_t x, uint32_t y, uint32_t z, int16_t local) bool Maps::WriteGlobalFeature(uint32_t x, uint32_t y, uint32_t z, int16_t global) { + MAPS_GUARD uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z]; if (addr) { @@ -485,6 +502,7 @@ bool Maps::WriteGlobalFeature(uint32_t x, uint32_t y, uint32_t z, int16_t global */ bool Maps::ReadVeins(uint32_t x, uint32_t y, uint32_t z, vector * veins, vector * ices, vector *splatter) { + MAPS_GUARD t_vein v; t_frozenliquidvein fv; t_spattervein sv; @@ -625,6 +643,7 @@ __int16 __userpurge GetGeologicalRegion(__int16 block_X, int X, __i */ bool Maps::ReadGeology (vector < vector >& assign) { + MAPS_GUARD memory_info * minfo = d->d->offset_descriptor; Process *p = d->owner; // get needed addresses and offsets. Now this is what I call crazy. @@ -694,6 +713,7 @@ bool Maps::ReadGeology (vector < vector >& assign) bool Maps::ReadLocalFeatures( std::map > & local_features ) { + MAPS_GUARD // can't be used without a map! if(!d->block) return false; @@ -792,6 +812,7 @@ bool Maps::ReadLocalFeatures( std::map > & bool Maps::ReadGlobalFeatures( std::vector & features) { + MAPS_GUARD // can't be used without a map! if(!d->block) return false; diff --git a/tools/playground/CMakeLists.txt b/tools/playground/CMakeLists.txt index ee43d8c20..749922a5a 100644 --- a/tools/playground/CMakeLists.txt +++ b/tools/playground/CMakeLists.txt @@ -55,4 +55,4 @@ TARGET_LINK_LIBRARIES(dfcatsplosion dfhack) # df directly # Author: belal #ADD_EXECUTABLE(dfrenamer renamer.cpp) -#TARGET_LINK_LIBRARIES(dfrenamer dfhack) \ No newline at end of file +#TARGET_LINK_LIBRARIES(dfrenamer dfhack) diff --git a/tools/playground/incrementalsearch.cpp b/tools/playground/incrementalsearch.cpp index 3c3014dca..ff3f5b592 100644 --- a/tools/playground/incrementalsearch.cpp +++ b/tools/playground/incrementalsearch.cpp @@ -20,6 +20,87 @@ using namespace std; #include #include "SegmentedFinder.h" +template +class holder +{ + public: + vector values; + SegmentedFinder & sf; + holder(SegmentedFinder& sff):sf(sff){}; + bool isValid(size_t idx) + { + + }; +}; + +class address +{ + public: + uint64_t addr_; + unsigned int valid : 1; + virtual void print(SegmentedFinder& sff) + { + cout << hex << "0x" << addr_ << endl; + }; + address(const uint64_t addr) + { + addr_ = addr; + valid = false; + } + address & operator=(const uint64_t in) + { + addr_ = in; + valid = false; + return *this; + } + bool isValid(SegmentedFinder& sff) + { + if(valid) return true; + if(sff.getSegmentForAddress(addr_)) + { + valid = 1; + } + } +}; + +class Cstr: public address +{ + void print(SegmentedFinder & sf) + { + cout << hex << "0x" << addr_ << ": \"" << sf.Translate(addr_) << "\"" << endl; + } +}; +// STL STRING +#ifdef LINUX_BUILD +class STLstr: public address +{ + +}; +#endif +#ifndef LINUX_BUILD +class STLstr: public address +{ + +}; +#endif + +// STL VECTOR +#ifdef LINUX_BUILD +class Vector: public address +{ + +}; +#endif +#ifndef LINUX_BUILD +class Vector: public address +{ + +}; +#endif +class Int64: public address{}; +class Int32: public address{}; +class Int16: public address{}; +class Int8: public address{}; inline void printRange(DFHack::t_memrange * tpr) { diff --git a/tools/playground/typeblocks.cpp b/tools/playground/typeblocks.cpp new file mode 100644 index 000000000..3a0b88f31 --- /dev/null +++ b/tools/playground/typeblocks.cpp @@ -0,0 +1,43 @@ +#include +#include +#include +#include +#include +#include +#include +using namespace std; + +#include +using namespace DFHack; + +namespace TBlocks +{ + +} + +int main (int numargs, const char ** args) +{ + DFHack::ContextManager DFMgr("Memory.xml"); + DFHack::Context * DF; + try + { + DF = DFMgr.getSingleContext(); + DF->Attach(); + } + catch (exception& e) + { + cerr << e.what() << endl; + #ifndef LINUX_BUILD + cin.ignore(); + #endif + return 1; + } + + // DO STUFF HERE + + #ifndef LINUX_BUILD + cout << "Done. Press any key to continue" << endl; + cin.ignore(); + #endif + return 0; +} diff --git a/tools/supported/liquids.cpp b/tools/supported/liquids.cpp index d125c7ad1..b93c6cc29 100644 --- a/tools/supported/liquids.cpp +++ b/tools/supported/liquids.cpp @@ -26,6 +26,8 @@ int main (void) DF=DFMgr.getSingleContext(); DF->Attach(); Maps = DF->getMaps(); + Maps->Start(); + Maps->getSize(x_max,y_max,z_max); Position = DF->getPosition(); } catch (exception& e) @@ -44,7 +46,6 @@ int main (void) int amount = 7; while(!end) { - Maps->getSize(x_max,y_max,z_max); DF->Resume(); string command = ""; cout <<"[" << mode << ":" << amount << ":" << flowmode << "]# "; @@ -71,7 +72,6 @@ int main (void) << endl << "Usage: point the DF cursor at a tile you want to modify" << endl << "and use the commands available :)" << endl; - } else if(command == "m") {