dfhack/examples/expbench.cpp

73 lines
1.9 KiB
C++

2009-09-13 18:02:46 -06:00
// This program exports the entire map from DF. Takes roughly 6.6 seconds for 1000 cycles on my Linux machine. ~px
#include <iostream>
#include <integers.h>
2009-09-13 18:02:46 -06:00
#include <vector>
2009-10-30 03:01:14 -06:00
#include <ctime>
2009-09-13 18:02:46 -06:00
using namespace std;
#include <DFTypes.h>
#include <DFHackAPI.h>
int main (void)
{
2009-10-30 03:01:14 -06:00
time_t start, end;
double time_diff;
2009-09-13 18:02:46 -06:00
uint32_t x_max,y_max,z_max;
uint32_t num_blocks = 0;
uint64_t bytes_read = 0;
2009-09-13 18:02:46 -06:00
uint16_t tiletypes[16][16];
2009-12-12 17:47:58 -07:00
DFHack::t_designation designations[16][16];
DFHack::t_occupancy occupancies[16][16];
2009-09-13 18:02:46 -06:00
2009-11-10 20:37:28 -07:00
DFHack::API DF("Memory.xml");
2009-09-13 18:02:46 -06:00
if(!DF.Attach())
{
cerr << "DF not found" << endl;
return 1;
}
2009-10-30 03:01:14 -06:00
time(&start);
2009-09-13 18:02:46 -06:00
for(uint32_t i = 0; i< 1000;i++)
{
2010-01-10 23:27:59 -07:00
if(!DF.InitMap())
2010-01-11 11:57:57 -07:00
break;
DF.getSize(x_max,y_max,z_max);
2009-10-28 16:40:21 -06:00
if((i % 10) == 0)
2009-09-13 18:02:46 -06:00
{
2009-10-28 16:40:21 -06:00
int percentage = i / 10;
cout << percentage << endl;
}
for(uint32_t x = 0; x< x_max;x++)
{
for(uint32_t y = 0; y< y_max;y++)
2009-09-13 18:02:46 -06:00
{
2009-10-28 16:40:21 -06:00
for(uint32_t z = 0; z< z_max;z++)
2009-09-13 18:02:46 -06:00
{
2009-10-28 16:40:21 -06:00
if(DF.isValidBlock(x,y,z))
{
DF.ReadTileTypes(x,y,z, (uint16_t *) tiletypes);
DF.ReadDesignations(x,y,z, (uint32_t *) designations);
DF.ReadOccupancy(x,y,z, (uint32_t *) occupancies);
num_blocks ++;
bytes_read += 256 * (4 + 4 + 2);
}
2009-09-13 18:02:46 -06:00
}
}
}
DF.DestroyMap();
2009-09-13 18:02:46 -06:00
}
2009-10-31 12:18:59 -06:00
DF.Detach();
2009-10-30 03:01:14 -06:00
time(&end);
time_diff = difftime(end, start);
2009-09-13 18:02:46 -06:00
cout << num_blocks << " blocks read" << endl;
cout << bytes_read / (1024 * 1024) << " MB" << endl;
2009-10-30 03:01:14 -06:00
cout << "map export tests done in " << time_diff << " seconds." << endl;
#ifndef LINUX_BUILD
cout << "Done. Press any key to continue" << endl;
2009-10-30 03:01:14 -06:00
cin.ignore();
#endif
2009-09-13 18:02:46 -06:00
return 0;
}