From caa482fbd124ca5fe0caedc422df9a8ae11e05e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sat, 17 Apr 2010 15:30:25 +0200 Subject: [PATCH] Support for reading/writing temperature, extended veinlook --- dfhack/include/modules/Maps.h | 5 ++ dfhack/modules/Maps.cpp | 44 +++++++++++-- dfhack/shm/mod-maps.h | 2 + examples/veinlook.cpp | 116 ++++++++++++++++++++++++++++++---- output/Memory.xml | 12 ++-- tools/liquids.cpp | 39 ++++++++++-- 6 files changed, 189 insertions(+), 29 deletions(-) diff --git a/dfhack/include/modules/Maps.h b/dfhack/include/modules/Maps.h index 1192baf6a..721227362 100644 --- a/dfhack/include/modules/Maps.h +++ b/dfhack/include/modules/Maps.h @@ -199,6 +199,7 @@ namespace DFHack typedef DFHack::t_designation designations40d [16][16]; typedef DFHack::t_occupancy occupancies40d [16][16]; typedef uint8_t biome_indices40d [16]; + typedef uint16_t t_temperatures [16][16]; typedef struct { @@ -290,6 +291,10 @@ namespace DFHack bool ReadDesignations(uint32_t blockx, uint32_t blocky, uint32_t blockz, designations40d *buffer); bool WriteDesignations (uint32_t blockx, uint32_t blocky, uint32_t blockz, designations40d *buffer); + /// read/write temperatures + bool ReadTemperatures(uint32_t blockx, uint32_t blocky, uint32_t blockz, t_temperatures *temp1, t_temperatures *temp2); + bool WriteTemperatures (uint32_t blockx, uint32_t blocky, uint32_t blockz, t_temperatures *temp1, t_temperatures *temp2); + /// read/write block occupancies bool ReadOccupancy(uint32_t blockx, uint32_t blocky, uint32_t blockz, occupancies40d *buffer); bool WriteOccupancy(uint32_t blockx, uint32_t blocky, uint32_t blockz, occupancies40d *buffer); diff --git a/dfhack/modules/Maps.cpp b/dfhack/modules/Maps.cpp index 7eb499d9a..8446e3322 100644 --- a/dfhack/modules/Maps.cpp +++ b/dfhack/modules/Maps.cpp @@ -70,12 +70,14 @@ Maps::Maps(APIPrivate* _d) off.x_count_offset = mem->getAddress ("x_count_block"); off.y_count_offset = mem->getAddress ("y_count_block"); off.z_count_offset = mem->getAddress ("z_count_block"); - off.tile_type_offset = mem->getOffset ("type"); - off.designation_offset = mem->getOffset ("designation"); - off.occupancy_offset = mem->getOffset("occupancy"); - off.biome_stuffs = mem->getOffset ("biome_stuffs"); - off.veinvector = mem->getOffset ("v_vein"); - + off.tile_type_offset = mem->getOffset ("map_data_type"); + off.designation_offset = mem->getOffset ("map_data_designation"); + off.occupancy_offset = mem->getOffset("map_data_occupancy"); + off.biome_stuffs = mem->getOffset ("map_data_biome_stuffs"); + off.veinvector = mem->getOffset ("map_data_vein_vector"); + off.temperature1_offset = mem->getOffset ("map_data_temperature1_offset"); + off.temperature2_offset = mem->getOffset ("map_data_temperature2_offset"); + // these can fail and will be found when looking at the actual veins later // basically a cache off.vein_ice_vptr = 0; @@ -357,6 +359,36 @@ bool Maps::WriteOccupancy (uint32_t x, uint32_t y, uint32_t z, occupancies40d *b return false; } +/* + * Temperatures + */ +bool Maps::ReadTemperatures(uint32_t x, uint32_t y, uint32_t z, t_temperatures *temp1, t_temperatures *temp2) +{ + uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z]; + if (addr) + { + if(temp1) + g_pProcess->read (addr + d->offsets.temperature1_offset, sizeof (t_temperatures), (uint8_t *) temp1); + if(temp2) + g_pProcess->read (addr + d->offsets.temperature2_offset, sizeof (t_temperatures), (uint8_t *) temp2); + return true; + } + return false; +} +bool Maps::WriteTemperatures (uint32_t x, uint32_t y, uint32_t z, t_temperatures *temp1, t_temperatures *temp2) +{ + uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z]; + if (addr) + { + if(temp1) + g_pProcess->write (addr + d->offsets.temperature1_offset, sizeof (t_temperatures), (uint8_t *) temp1); + if(temp2) + g_pProcess->write (addr + d->offsets.temperature2_offset, sizeof (t_temperatures), (uint8_t *) temp2); + return true; + } + return false; +} + /* * Region Offsets - used for layer geology */ diff --git a/dfhack/shm/mod-maps.h b/dfhack/shm/mod-maps.h index 8023be8bf..832c4e8c8 100644 --- a/dfhack/shm/mod-maps.h +++ b/dfhack/shm/mod-maps.h @@ -47,6 +47,8 @@ typedef struct uint32_t occupancy_offset;// = d->offset_descriptor->getOffset ("occupancy"); uint32_t biome_stuffs;// = d->offset_descriptor->getOffset ("biome_stuffs"); uint32_t veinvector;// = d->offset_descriptor->getOffset ("v_vein"); + uint32_t temperature1_offset; + uint32_t temperature2_offset; uint32_t vein_mineral_vptr; uint32_t vein_ice_vptr; uint32_t vein_spatter_vptr; diff --git a/examples/veinlook.cpp b/examples/veinlook.cpp index 9a08490a0..707eaf7b9 100644 --- a/examples/veinlook.cpp +++ b/examples/veinlook.cpp @@ -14,6 +14,7 @@ using namespace std; #include #include #include +#include #include #include @@ -30,6 +31,22 @@ string error; API * pDF = 0; +struct t_tempz +{ + int32_t limit; + int character; +}; + +t_tempz temp_limits[]= +{ + {50, '.'}, + {100, '+'}, + {500, '*'}, + {1000, '#'}, + {2000, '!'} +}; +#define NUM_LIMITS 5 + static void finish(int sig); int gotoxy(int x, int y) @@ -315,6 +332,8 @@ main(int argc, char *argv[]) vector veinVector; vector IceVeinVector; vector splatter; + t_temperatures b_temp1; + t_temperatures b_temp2; DFHack::Materials * Mats = 0; DFHack::Maps * Maps = 0; @@ -392,6 +411,13 @@ main(int argc, char *argv[]) uint32_t blockaddr2 = 0; t_blockflags bflags; bflags.whole = 0; + enum e_tempmode + { + TEMP_NO, + TEMP_1, + TEMP_2 + }; + e_tempmode temperature = TEMP_NO; // resume so we don't block DF while we wait for input DF.Resume(); @@ -451,6 +477,15 @@ main(int argc, char *argv[]) case 't': dotwiddle = true; break; + case 'b': + temperature = TEMP_NO; + break; + case 'n': + temperature = TEMP_1; + break; + case 'm': + temperature = TEMP_2; + break; default: break; } @@ -520,6 +555,9 @@ main(int argc, char *argv[]) } Maps->WriteDesignations(cursorX+i,cursorY+j,cursorZ, &(Block->designation)); } + + // read temperature data + Maps->ReadTemperatures(cursorX+i,cursorY+j,cursorZ,&b_temp1, &b_temp2 ); if(dotwiddle) { bitset<32> bs = Block->designation[0][0].whole; @@ -528,6 +566,7 @@ main(int argc, char *argv[]) Maps->WriteDesignations(cursorX+i,cursorY+j,cursorZ, &(Block->designation)); dotwiddle = false; } + // do a dump of the block data if(dump) { @@ -588,11 +627,11 @@ main(int argc, char *argv[]) } */ } - gotoxy(0,48); + gotoxy(50,0); cprintf("arrow keys, PGUP, PGDN = navigate"); - gotoxy(0,49); + gotoxy(50,1); cprintf("+,- = switch vein"); - gotoxy(0,50); + gotoxy(50,2); uint32_t mineralsize = veinVector.size(); uint32_t icesize = IceVeinVector.size(); uint32_t splattersize = splatter.size(); @@ -630,7 +669,7 @@ main(int argc, char *argv[]) } } } - gotoxy(0,51); + gotoxy(50,3); cprintf("Mineral: %s",stonetypes[veinVector[vein].type].id); } else if (vein < mineralsize + icesize) @@ -650,7 +689,7 @@ main(int argc, char *argv[]) attroff(A_STANDOUT); } } - gotoxy(0,51); + gotoxy(50,3); cprintf("ICE"); } else @@ -670,25 +709,78 @@ main(int argc, char *argv[]) } } } - gotoxy(0,51); + gotoxy(50,3); cprintf("Spatter: %s",PrintSplatterType(splatter[realvein].mat1,splatter[realvein].mat2,creature_types).c_str()); } } } mapblock40d * Block = &blocks[1][1]; - for(int x = 0; x < 16; x++) for(int y = 0; y < 16; y++) + t_temperatures * ourtemp; + if(temperature == TEMP_NO) { - if((Block->occupancy[x][y].whole & (1 << twiddle))) + for(int x = 0; x < 16; x++) for(int y = 0; y < 16; y++) { - putch(x + 16,y + 16,'@',COLOR_WHITE); + if((Block->occupancy[x][y].whole & (1 << twiddle))) + { + putch(x + 16,y + 16,'@',COLOR_WHITE); + } + } + } + else + { + if(temperature == TEMP_1) + ourtemp = &b_temp1; + else if(temperature == TEMP_2) + ourtemp = &b_temp2; + uint64_t sum = 0; + uint16_t min, max; + min = max = (*ourtemp)[0][0]; + for(int x = 0; x < 16; x++) for(int y = 0; y < 16; y++) + { + uint16_t temp = (*ourtemp)[x][y]; + if(temp < min) min = temp; + if(temp > max) max = temp; + sum += temp; + } + uint64_t average = sum/256; + gotoxy (50,8); + if(temperature == TEMP_1) + cprintf ("temperature1 [°U] (min,avg,max): %d,%d,%d", min, average, max); + else if(temperature == TEMP_2) + cprintf ("temperature2 [°U] (min,avg,max): %d,%d,%d", min, average, max); + + for(int x = 0; x < 16; x++) for(int y = 0; y < 16; y++) + { + int32_t temper = (int32_t) (*ourtemp)[x][y]; + temper -= average; + uint32_t abs_temp = abs(temper); + int color; + unsigned char character = ' '; + if(temper >= 0) + color = COLOR_RED; + else + color = COLOR_BLUE; + + for(int i = 0; i < NUM_LIMITS; i++) + { + if(temp_limits[i].limit < abs_temp) + character = temp_limits[i].character; + else break; + } + if( character != ' ') + { + putch(x + 16,y + 16,character,color); + } } } - gotoxy (0,52); + gotoxy (50,4); cprintf("block address 0x%x, flags 0x%08x",blockaddr, bflags.whole); - gotoxy (0,53); + gotoxy (50,5); cprintf("dirty bit: %d, twiddle: %d",dirtybit,twiddle); - gotoxy (0,54); + gotoxy (50,6); cprintf ("d - dig veins, o - dump map block, z - toggle dirty bit"); + gotoxy (50,7); + cprintf ("b - no temperature, n - temperature 1, m - temperature 2"); wrefresh(stdscr); } pDF = 0; diff --git a/output/Memory.xml b/output/Memory.xml index 4d50373c8..c3b2fa892 100644 --- a/output/Memory.xml +++ b/output/Memory.xml @@ -1053,11 +1053,13 @@ size=212 Map stuff =========
0x016AD718
- 0x08 - 0x009A - 0x029C - 0x069c - 0x1D9C + 0x08 + 0x009A + 0x029C + 0x069c + 0x159c + 0x179c + 0x1D9C