added Maps_ReadLocalFeatures

develop
doomchild 2011-03-14 14:59:22 -05:00
parent b1ed423f98
commit 5cbc9e5918
2 changed files with 52 additions and 2 deletions

@ -39,6 +39,7 @@ DFHACK_EXPORT int Maps_Finish(DFHackObject* maps);
DFHACK_EXPORT uint16_t* Maps_ReadGeology(DFHackObject* maps);
DFHACK_EXPORT t_feature* Maps_ReadGlobalFeatures(DFHackObject* maps);
DFHACK_EXPORT c_featuremap_node* Maps_ReadLocalFeatures(DFHackObject* maps);
DFHACK_EXPORT void Maps_getSize(DFHackObject* maps, uint32_t* x, uint32_t* y, uint32_t* z);
DFHACK_EXPORT int Maps_isValidBlock(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z);

@ -24,6 +24,7 @@ distribution.
#include "dfhack/DFPragma.h"
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
@ -74,7 +75,7 @@ uint16_t* Maps_ReadGeology(DFHackObject* maps)
}
}
(*alloc_ushort_buffer_callback)(buf, geoLength);
((*alloc_ushort_buffer_callback)(buf, geoLength));
if(buf != NULL)
{
@ -110,7 +111,7 @@ t_feature* Maps_ReadGlobalFeatures(DFHackObject* maps)
t_feature** buf = NULL;
(*alloc_feature_buffer_callback)(buf, featureVec.size());
((*alloc_feature_buffer_callback)(buf, featureVec.size()));
if(buf != NULL)
{
@ -128,6 +129,54 @@ t_feature* Maps_ReadGlobalFeatures(DFHackObject* maps)
return NULL;
}
c_featuremap_node* Maps_ReadLocalFeatures(DFHackObject* maps)
{
if(maps != NULL)
{
std::map <DFCoord, std::vector<t_feature *> > local_features;
std::map <DFCoord, std::vector<t_feature *> >::iterator iterate;
uint32_t i;
if(((DFHack::Maps*)maps)->ReadLocalFeatures(local_features))
{
if(local_features.empty() == true)
return NULL;
c_featuremap_node* featuremap;
uint32_t* featuremap_size = (uint32_t*)calloc(local_features.size(), sizeof(uint32_t));
for(i = 0, iterate = local_features.begin(); iterate != local_features.end(); i++, iterate++)
featuremap_size[i] = (*iterate).second.size();
((*alloc_featuremap_buffer_callback)(&featuremap, featuremap_size, local_features.size()));
free(featuremap_size);
if(featuremap == NULL)
return NULL;
for(i = 0, iterate = local_features.begin(); iterate != local_features.end(); i++, iterate++)
{
uint32_t j;
featuremap[i].coordinate.comparate = (*iterate).first.comparate;
for(j = 0; j < (*iterate).second.size(); j++)
featuremap[i].features[j] = *((*iterate).second[j]);
//copy((*iterate).second.begin(), (*iterate).second.end(), featuremap[i].features);
featuremap[i].feature_length = (*iterate).second.size();
}
return featuremap;
}
else
return NULL;
}
return NULL;
}
void Maps_getSize(DFHackObject* maps, uint32_t* x, uint32_t* y, uint32_t* z)
{
if(maps != NULL)