using preregistered callbacks

develop
doomchild 2010-05-25 08:52:01 -05:00
parent 540b110d34
commit dd15ed8bff
2 changed files with 28 additions and 37 deletions

@ -37,6 +37,8 @@ using namespace std;
using namespace DFHack; using namespace DFHack;
/*
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@ -159,15 +161,14 @@ void CreatureType_Free(c_creaturetype* src)
} }
#endif #endif
*/
int ColorListConvert(t_colormodifier* src, c_colormodifier* dest) int ColorListConvert(t_colormodifier* src, c_colormodifier* dest)
{ {
if(src == NULL || dest == NULL) if(src == NULL)
return -1; return -1;
strcpy(dest->part, src->part); dest = ((*alloc_colormodifier_callback)(src->part, src->colorlist.size()));
dest->colorlistLength = src->colorlist.size();
dest->colorlist = (uint32_t*)malloc(sizeof(uint32_t) * dest->colorlistLength);
copy(src->colorlist.begin(), src->colorlist.end(), dest->colorlist); copy(src->colorlist.begin(), src->colorlist.end(), dest->colorlist);
@ -176,23 +177,14 @@ int ColorListConvert(t_colormodifier* src, c_colormodifier* dest)
int CreatureCasteConvert(t_creaturecaste* src, c_creaturecaste* dest) int CreatureCasteConvert(t_creaturecaste* src, c_creaturecaste* dest)
{ {
if(src == NULL || dest == NULL) if(src == NULL)
return -1; return -1;
strcpy(dest->rawname, src->rawname); dest = ((*alloc_creaturecaste_callback)(src->rawname, src->singular, src->plural, src->adjective, src->ColorModifier.size(), src->bodypart.size()));
strcpy(dest->singular, src->singular);
strcpy(dest->plural, src->plural);
strcpy(dest->adjective, src->adjective);
dest->colorModifierLength = src->ColorModifier.size();
dest->ColorModifier = (c_colormodifier*)malloc(sizeof(c_colormodifier) * dest->colorModifierLength);
for(int i = 0; i < dest->colorModifierLength; i++) for(int i = 0; i < dest->colorModifierLength; i++)
ColorListConvert(&src->ColorModifier[i], &dest->ColorModifier[i]); ColorListConvert(&src->ColorModifier[i], &dest->ColorModifier[i]);
dest->bodypartLength = src->bodypart.size();
dest->bodypart = (t_bodypart*)malloc(sizeof(t_bodypart) * dest->bodypartLength);
copy(src->bodypart.begin(), src->bodypart.end(), dest->bodypart); copy(src->bodypart.begin(), src->bodypart.end(), dest->bodypart);
return 1; return 1;
@ -200,27 +192,15 @@ int CreatureCasteConvert(t_creaturecaste* src, c_creaturecaste* dest)
int CreatureTypeConvert(t_creaturetype* src, c_creaturetype* dest) int CreatureTypeConvert(t_creaturetype* src, c_creaturetype* dest)
{ {
if(src == NULL || dest == NULL) if(src == NULL)
return -1; return -1;
strcpy(dest->rawname, src->rawname); dest = ((*alloc_creaturetype_callback)(src->rawname, src->castes.size(), src->extract.size(), src->tile_character, src->tilecolor.fore, src->tilecolor.back, src->tilecolor.bright));
dest->tilecolor.fore = src->tilecolor.fore;
dest->tilecolor.back = src->tilecolor.back;
dest->tilecolor.bright = src->tilecolor.bright;
dest->tile_character = src->tile_character;
dest->castesCount = src->castes.size();
dest->castes = (c_creaturecaste*)malloc(sizeof(c_creaturecaste) * dest->castesCount);
for(int i = 0; i < dest->castesCount; i++) for(int i = 0; i < dest->castesCount; i++)
CreatureCasteConvert(&src->castes[i], &dest->castes[i]); CreatureCasteConvert(&src->castes[i], &dest->castes[i]);
dest->extractCount = src->extract.size();
dest->extract = (t_creatureextract*)malloc(sizeof(t_creatureextract) * dest->extractCount);
copy(src->extract.begin(), src->extract.end(), dest->extract); copy(src->extract.begin(), src->extract.end(), dest->extract);
return 1; return 1;
} }

@ -37,6 +37,14 @@ using namespace DFHack;
extern "C" { extern "C" {
#endif #endif
int8_t* (*alloc_byte_buffer_callback)(uint32_t);
int16_t* (*alloc_short_buffer_callback)(uint32_t);
int32_t* (*alloc_int_buffer_callback)(uint32_t);
uint8_t* (*alloc_ubyte_buffer_callback)(uint32_t);
uint16_t* (*alloc_ushort_buffer_callback)(uint32_t);
uint32_t* (*alloc_uint_buffer_callback)(uint32_t);
struct c_colormodifier struct c_colormodifier
{ {
char part[128]; char part[128];
@ -44,8 +52,9 @@ struct c_colormodifier
uint32_t colorlistLength; uint32_t colorlistLength;
}; };
c_colormodifier* ColorModifier_New(); c_colormodifier* (*alloc_empty_colormodifier_callback)(void);
void ColorModifier_Free(c_colormodifier* src); c_colormodifier* (*alloc_colormodifier_callback)(const char*, uint32_t);
c_colormodifier* (*alloc_colormodifier_buffer_callback)(uint32_t);
struct c_creaturecaste struct c_creaturecaste
{ {
@ -61,8 +70,9 @@ struct c_creaturecaste
uint32_t bodypartLength; uint32_t bodypartLength;
}; };
c_creaturecaste* CreatureCaste_New(); c_creaturecaste* (*alloc_empty_creaturecaste_callback)(void);
void CreatureCaste_Free(c_creaturecaste* src); c_creaturecaste* (*alloc_creaturecaste_callback)(const char*, const char*, const char*, const char*, uint32_t, uint32_t);
c_creaturecaste* (*alloc_creaturecaste_buffer_callback)(uint32_t);
struct c_creaturetype struct c_creaturetype
{ {
@ -84,8 +94,9 @@ struct c_creaturetype
} tilecolor; } tilecolor;
}; };
c_creaturetype* CreatureType_New(); c_creaturetype* (*alloc_empty_creaturetype_callback)(void);
void CreatureType_Free(c_creaturetype* src); c_creaturetype* (*alloc_creaturetype_callback)(const char*, uint32_t, uint32_t, uint8_t, uint16_t, uint16_t, uint16_t);
c_creaturetype* (*alloc_creaturetype_buffer_callback)(uint32_t);
#ifdef __cplusplus #ifdef __cplusplus
} }