changed vein readers to return a pointer to a buffer of just one kind of vein at a time

develop
doomchild 2010-07-06 13:45:15 -05:00
parent 9ef7a74a44
commit e7751f8fd9
3 changed files with 24 additions and 89 deletions

@ -102,8 +102,8 @@ DFHACK_EXPORT extern int (*alloc_creaturetype_callback)(c_creaturetype*, const c
DFHACK_EXPORT extern int (*alloc_creaturetype_buffer_callback)(c_creaturetype*, uint32_t);
DFHACK_EXPORT extern int (*alloc_vein_buffer_callback)(t_vein*, uint32_t);
DFHACK_EXPORT extern int (*alloc_frozenliquidvein_callback)(t_frozenliquidvein*, uint32_t);
DFHACK_EXPORT extern int (*alloc_spattervein_callback)(t_spattervein*, uint32_t);
DFHACK_EXPORT extern int (*alloc_frozenliquidvein_buffer_callback)(t_frozenliquidvein*, uint32_t);
DFHACK_EXPORT extern int (*alloc_spattervein_buffer_callback)(t_spattervein*, uint32_t);
#ifdef __cplusplus
}

@ -69,10 +69,9 @@ DFHACK_EXPORT int Maps_WriteBlockFlags(DFHackObject* maps, uint32_t x, uint32_t
DFHACK_EXPORT int Maps_ReadRegionOffsets(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z, biome_indices40d* buffer);
DFHACK_EXPORT int Maps_ReadAllVeins(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z, t_vein* vein_buffer, t_frozenliquidvein* frozenvein_buffer, t_spattervein* spattervein_buffer);
DFHACK_EXPORT int Maps_ReadStandardVeins(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z, t_vein* vein_buffer);
DFHACK_EXPORT int Maps_ReadFrozenVeins(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z, t_frozenliquidvein* frozenvein_buffer);
DFHACK_EXPORT int Maps_ReadSpatterVeins(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z, t_spattervein* spattervein_buffer);
DFHACK_EXPORT t_vein* Maps_ReadStandardVeins(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z);
DFHACK_EXPORT t_frozenliquidvein* Maps_ReadFrozenVeins(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z);
DFHACK_EXPORT t_spattervein* Maps_ReadSpatterVeins(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z);
#ifdef __cplusplus
}

@ -274,60 +274,12 @@ int Maps_ReadRegionOffsets(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t
return -1;
}
int Maps_ReadAllVeins(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z, t_vein* vein_buffer, t_frozenliquidvein* frozenvein_buffer, t_spattervein* spattervein_buffer)
{
if(maps != NULL)
{
if(alloc_vein_buffer_callback == NULL || alloc_frozenliquidvein_callback == NULL || alloc_spattervein_callback == NULL)
return 0;
vector<t_vein> veins;
vector<t_frozenliquidvein> frozen_veins;
vector<t_spattervein> spatter_veins;
bool result = ((DFHack::Maps*)maps)->ReadVeins(x, y, z, &veins, &frozen_veins, &spatter_veins);
if(result)
{
t_vein* v_buf = NULL;
t_frozenliquidvein* fv_buf = NULL;
t_spattervein* sv_buf = NULL;
if(veins.size() > 0)
{
((*alloc_vein_buffer_callback)(v_buf, veins.size()));
copy(veins.begin(), veins.end(), v_buf);
}
if(frozen_veins.size() > 0)
{
((*alloc_frozenliquidvein_callback)(fv_buf, frozen_veins.size()));
copy(frozen_veins.begin(), frozen_veins.end(), fv_buf);
}
if(spatter_veins.size() > 0)
{
((*alloc_spattervein_callback)(sv_buf, spatter_veins.size()));
copy(spatter_veins.begin(), spatter_veins.end(), sv_buf);
}
return 1;
}
else
return 0;
}
return -1;
}
int Maps_ReadStandardVeins(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z, t_vein* vein_buffer)
t_vein* Maps_ReadStandardVeins(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z)
{
if(maps != NULL)
{
if(alloc_vein_buffer_callback == NULL)
return 0;
return NULL;
vector<t_vein> veins;
bool result = ((DFHack::Maps*)maps)->ReadVeins(x, y, z, &veins);
@ -343,21 +295,21 @@ int Maps_ReadStandardVeins(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t
copy(veins.begin(), veins.end(), v_buf);
}
return 1;
return v_buf;
}
else
return 0;
return NULL;
}
return -1;
return NULL;
}
int Maps_ReadFrozenVeins(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z, t_frozenliquidvein* frozenvein_buffer)
t_frozenliquidvein* Maps_ReadFrozenVeins(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z)
{
if(maps != NULL)
{
if(alloc_vein_buffer_callback == NULL || alloc_frozenliquidvein_callback == NULL)
return 0;
if(alloc_frozenliquidvein_callback == NULL)
return NULL;
vector<t_vein> veins;
vector<t_frozenliquidvein> frozen_veins;
@ -365,38 +317,30 @@ int Maps_ReadFrozenVeins(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z,
if(result)
{
t_vein* v_buf = NULL;
t_frozenliquidvein* fv_buf = NULL;
if(veins.size() > 0)
{
((*alloc_vein_buffer_callback)(v_buf, veins.size()));
copy(veins.begin(), veins.end(), v_buf);
}
if(frozen_veins.size() > 0)
{
((*alloc_frozenliquidvein_callback)(fv_buf, frozen_veins.size()));
((*alloc_frozenliquidvein_buffer_callback)(fv_buf, frozen_veins.size()));
copy(frozen_veins.begin(), frozen_veins.end(), fv_buf);
}
return 1;
return fv_buf;
}
else
return 0;
return NULL;
}
return -1;
return NULL;
}
int Maps_ReadSpatterVeins(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z, t_spattervein* spattervein_buffer)
t_spattervein* Maps_ReadSpatterVeins(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z)
{
if(maps != NULL)
{
if(alloc_vein_buffer_callback == NULL || alloc_spattervein_callback == NULL)
return 0;
if(alloc_spattervein_callback == NULL)
return NULL;
vector<t_vein> veins;
vector<t_spattervein> spatter_veins;
@ -404,30 +348,22 @@ int Maps_ReadSpatterVeins(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z
if(result)
{
t_vein* v_buf = NULL;
t_spattervein* sv_buf = NULL;
if(veins.size() > 0)
{
((*alloc_vein_buffer_callback)(v_buf, veins.size()));
copy(veins.begin(), veins.end(), v_buf);
}
if(spatter_veins.size() > 0)
{
((*alloc_spattervein_callback)(sv_buf, spatter_veins.size()));
((*alloc_spattervein_buffer_callback)(sv_buf, spatter_veins.size()));
copy(spatter_veins.begin(), spatter_veins.end(), sv_buf);
}
return 1;
return sv_buf;
}
else
return 0;
return NULL;
}
return -1;
return NULL;
}
#ifdef __cplusplus