Added base layer material support to map cache, material display to dfprobe.

develop
Petr Mrázek 2011-04-10 17:01:58 +02:00
parent 7876a42258
commit b630e93c5a
3 changed files with 69 additions and 6 deletions

@ -36,10 +36,29 @@ void SquashVeins (DFHack::Maps *m, DFHack::DFCoord bcoord, DFHack::mapblock40d &
}
}
void SquashRocks ( vector< vector <uint16_t> > * layerassign, DFHack::mapblock40d & mb, DFHack::t_blockmaterials & materials)
{
// get the layer materials
for(uint32_t xx = 0;xx<16;xx++)
{
for (uint32_t yy = 0; yy< 16;yy++)
{
uint8_t test = mb.designation[xx][yy].bits.biome;
if( test >= sizeof(mb.biome_indices))
{
materials[xx][yy] = -1;
continue;
}
materials[xx][yy] =
layerassign->at(mb.biome_indices[test])[mb.designation[xx][yy].bits.geolayer_index];
}
}
}
class Block
{
public:
Block(DFHack::Maps *_m, DFHack::DFCoord _bcoord)
Block(DFHack::Maps *_m, DFHack::DFCoord _bcoord, vector< vector <uint16_t> > * layerassign = 0)
{
m = _m;
dirty_designations = false;
@ -50,15 +69,23 @@ class Block
bcoord = _bcoord;
if(m->ReadBlock40d(bcoord.x,bcoord.y,bcoord.z,&raw))
{
m->ReadTemperatures(bcoord.x,bcoord.y, bcoord.z,&temp1,&temp2);
SquashVeins(m,bcoord,raw,veinmats);
if(layerassign)
SquashRocks(layerassign,raw,basemats);
else
memset(basemats,-1,sizeof(basemats));
valid = true;
}
m->ReadTemperatures(bcoord.x,bcoord.y, bcoord.z,&temp1,&temp2);
}
int16_t veinMaterialAt(DFHack::DFCoord p)
{
return veinmats[p.x][p.y];
}
int16_t baseMaterialAt(DFHack::DFCoord p)
{
return basemats[p.x][p.y];
}
void ClearMaterialAt(DFHack::DFCoord p)
{
veinmats[p.x][p.y] = -1;
@ -162,6 +189,7 @@ class Block
DFHack::mapblock40d raw;
DFHack::DFCoord bcoord;
DFHack::t_blockmaterials veinmats;
DFHack::t_blockmaterials basemats;
DFHack::t_temperatures temp1;
DFHack::t_temperatures temp2;
};
@ -174,6 +202,7 @@ class MapCache
valid = 0;
this->Maps = Maps;
Maps->getSize(x_bmax, y_bmax, z_max);
validgeo = Maps->ReadGeology( layerassign );
valid = true;
};
~MapCache()
@ -203,7 +232,11 @@ class MapCache
{
if(blockcoord.x < x_bmax && blockcoord.y < y_bmax && blockcoord.z < z_max)
{
Block * nblo = new Block(Maps,blockcoord);
Block * nblo;
if(validgeo)
nblo = new Block(Maps,blockcoord, &layerassign);
else
nblo = new Block(Maps,blockcoord);
blocks[blockcoord] = nblo;
return nblo;
}
@ -279,6 +312,15 @@ class MapCache
}
return 0;
}
int16_t baseMaterialAt (DFHack::DFCoord tilecoord)
{
Block * b= BlockAt(tilecoord / 16);
if(b && b->valid)
{
return b->baseMaterialAt(tilecoord % 16);
}
return 0;
}
bool clearMaterialAt (DFHack::DFCoord tilecoord)
{
Block * b= BlockAt(tilecoord / 16);
@ -331,11 +373,13 @@ class MapCache
}
private:
volatile bool valid;
volatile bool validgeo;
uint32_t x_bmax;
uint32_t y_bmax;
uint32_t x_tmax;
uint32_t y_tmax;
uint32_t z_max;
vector< vector <uint16_t> > layerassign;
DFHack::Maps * Maps;
map<DFHack::DFCoord, Block *> blocks;
};

@ -7,6 +7,7 @@
#include <sstream>
#include <ctime>
#include <cstdio>
using namespace std;
#define DFHACK_WANT_MISCUTILS 1
#define DFHACK_WANT_TILETYPES 1
@ -37,13 +38,15 @@ int main (int numargs, const char ** args)
DFHack::Gui *Gui = DF->getGui();
DFHack::Materials *Materials = DF->getMaterials();
DFHack::VersionInfo* mem = DF->getMemoryInfo();
DFHack::Maps *Maps = DF->getMaps();
DFHack::Process * p = DF->getProcess();
bool hasmats = Materials->ReadInorganicMaterials();
if(!Maps->Start())
{
cerr << "Unable to access map data!" << endl;
std::cerr << "Unable to access map data!" << std::endl;
}
else
{
@ -122,7 +125,24 @@ int main (int numargs, const char ** args)
// biome, geolayer
std::cout << "biome: " << des.biome << std::endl;
std::cout << "geolayer: " << des.geolayer_index << std::endl;
int16_t base_rock = mc.baseMaterialAt(cursor);
if(base_rock != -1)
{
cout << "Layer material: " << dec << base_rock;
if(hasmats)
cout << " / " << Materials->inorganic[base_rock].id << " / " << Materials->inorganic[base_rock].name << endl;
else
cout << endl;
}
int16_t vein_rock = mc.veinMaterialAt(cursor);
if(vein_rock != -1)
{
cout << "Vein material (final): " << dec << vein_rock;
if(hasmats)
cout << " / " << Materials->inorganic[vein_rock].id << " / " << Materials->inorganic[vein_rock].name << endl;
else
cout << endl;
}
// liquids
if(des.flow_size)
{

@ -167,7 +167,6 @@ int main (int argc, const char* argv[])
if(showbaselayers)
{
//Maps->ReadRegionOffsets(x,y,z, &regionoffsets);
// get the layer materials
for(uint32_t xx = 0;xx<16;xx++)
{