Added a function to do a hash check on the entire fortress. It's not overly useful yet, other than benching.

develop
JapaMala 2014-07-03 08:35:45 +05:30
parent e04ab11659
commit 829ad945ea
1 changed files with 17 additions and 1 deletions

@ -37,8 +37,8 @@
#include "modules/Materials.h" #include "modules/Materials.h"
#include "TileTypes.h" #include "TileTypes.h"
//Needed for writing the protobuff stuff to a file.
#include <vector> #include <vector>
#include <time.h>
#include "RemoteFortressReader.pb.h" #include "RemoteFortressReader.pb.h"
@ -54,6 +54,7 @@ using namespace std;
static command_result GetMaterialList(color_ostream &stream, const EmptyMessage *in, MaterialList *out); static command_result GetMaterialList(color_ostream &stream, const EmptyMessage *in, MaterialList *out);
static command_result GetBlockList(color_ostream &stream, const BlockRequest *in, BlockList *out); static command_result GetBlockList(color_ostream &stream, const BlockRequest *in, BlockList *out);
static command_result CheckHashes(color_ostream &stream, const EmptyMessage *in);
void CopyBlock(df::map_block * DfBlock, RemoteFortressReader::MapBlock * NetBlock); void CopyBlock(df::map_block * DfBlock, RemoteFortressReader::MapBlock * NetBlock);
void FindChangedBlocks(); void FindChangedBlocks();
@ -84,6 +85,7 @@ DFhackCExport RPCService *plugin_rpcconnect(color_ostream &)
RPCService *svc = new RPCService(); RPCService *svc = new RPCService();
svc->addFunction("GetMaterialList", GetMaterialList); svc->addFunction("GetMaterialList", GetMaterialList);
svc->addFunction("GetBlockList", GetBlockList); svc->addFunction("GetBlockList", GetBlockList);
svc->addFunction("CheckHashes", CheckHashes);
return svc; return svc;
} }
@ -115,6 +117,20 @@ uint16_t fletcher16(uint8_t const *data, size_t bytes)
return sum2 << 8 | sum1; return sum2 << 8 | sum1;
} }
static command_result CheckHashes(color_ostream &stream, const EmptyMessage *in)
{
clock_t start = clock();
for (int i = 0; i < df::global::world->map.map_blocks.size(); i++)
{
df::map_block * block = df::global::world->map.map_blocks[i];
fletcher16((uint8_t*)(block->tiletype), 16 * 16 * sizeof(df::enums::tiletype::tiletype));
}
clock_t end = clock();
double elapsed_secs = double(end - start) / CLOCKS_PER_SEC;
stream.print("Checking all hashes took %f seconds.", elapsed_secs);
return CR_OK;
}
df::matter_state GetState(df::material * mat, uint16_t temp = 10015) df::matter_state GetState(df::material * mat, uint16_t temp = 10015)
{ {
df::matter_state state = matter_state::Solid; df::matter_state state = matter_state::Solid;