updated to use the allocator callbacks correctly

develop
doomchild 2011-03-09 12:23:48 -06:00
parent 44cbc3fd5c
commit 5bd51c2e08
6 changed files with 55 additions and 86 deletions

@ -81,7 +81,7 @@ t_customWorkshop* Buildings_ReadCustomWorkshopTypes(DFHackObject* b_Ptr)
if(!((DFHack::Buildings*)b_Ptr)->ReadCustomWorkshopTypes(bTypes)) if(!((DFHack::Buildings*)b_Ptr)->ReadCustomWorkshopTypes(bTypes))
return NULL; return NULL;
(*alloc_t_customWorkshop_buffer_callback)(cw_Ptr, bTypes.size()); (*alloc_t_customWorkshop_buffer_callback)(&cw_Ptr, bTypes.size());
if(cw_Ptr == NULL) if(cw_Ptr == NULL)
return NULL; return NULL;

@ -86,7 +86,7 @@ t_material* Creatures_ReadJob(DFHackObject* cPtr, const t_creature* furball)
t_material* buf = NULL; t_material* buf = NULL;
(*alloc_t_material_buffer_callback)(buf, mat.size()); (*alloc_t_material_buffer_callback)(&buf, mat.size());
if(buf != NULL) if(buf != NULL)
{ {
@ -117,7 +117,7 @@ uint32_t* Creatures_ReadInventoryIdx(DFHackObject* cPtr, const uint32_t index)
uint32_t* buf = NULL; uint32_t* buf = NULL;
(*alloc_uint_buffer_callback)(buf, item.size()); (*alloc_uint_buffer_callback)(&buf, item.size());
if(buf != NULL) if(buf != NULL)
{ {
@ -146,7 +146,7 @@ uint32_t* Creatures_ReadInventoryPtr(DFHackObject* cPtr, const uint32_t index)
uint32_t* buf = NULL; uint32_t* buf = NULL;
(*alloc_uint_buffer_callback)(buf, item.size()); (*alloc_uint_buffer_callback)(&buf, item.size());
if(buf != NULL) if(buf != NULL)
{ {

@ -59,7 +59,8 @@ char* Items_getItemDescription(DFHackObject* items, uint32_t itemptr, DFHackObje
if(desc.size() > 0) if(desc.size() > 0)
{ {
char* buf = NULL; char* buf = NULL;
(*alloc_char_buffer_callback)(buf,desc.size());
(*alloc_char_buffer_callback)(&buf, desc.size());
if(buf != NULL) if(buf != NULL)
{ {
@ -87,7 +88,9 @@ char* Items_getItemClass(DFHackObject* items, int32_t index)
if(iclass.size() > 0) if(iclass.size() > 0)
{ {
char* buf = NULL; char* buf = NULL;
(*alloc_char_buffer_callback)(buf, iclass.size());
(*alloc_char_buffer_callback)(&buf, iclass.size());
if(buf != NULL) if(buf != NULL)
{ {
size_t len = iclass.copy(buf, iclass.size()); size_t len = iclass.copy(buf, iclass.size());

@ -32,7 +32,10 @@ int Materials_ReadInorganicMaterials(DFHackObject* mat)
{ {
if(mat != NULL) if(mat != NULL)
{ {
return ((DFHack::Materials*)mat)->ReadInorganicMaterials(); if(((DFHack::Materials*)mat)->ReadInorganicMaterials() == true)
return 1;
else
return 0;
} }
return -1; return -1;
@ -42,7 +45,10 @@ int Materials_ReadOrganicMaterials(DFHackObject* mat)
{ {
if(mat != NULL) if(mat != NULL)
{ {
return ((DFHack::Materials*)mat)->ReadOrganicMaterials(); if(((DFHack::Materials*)mat)->ReadOrganicMaterials() == true)
return 1;
else
return 0;
} }
return -1; return -1;
@ -52,7 +58,10 @@ int Materials_ReadWoodMaterials(DFHackObject* mat)
{ {
if(mat != NULL) if(mat != NULL)
{ {
return ((DFHack::Materials*)mat)->ReadWoodMaterials(); if(((DFHack::Materials*)mat)->ReadWoodMaterials() == true)
return 1;
else
return 0;
} }
return -1; return -1;
@ -62,7 +71,10 @@ int Materials_ReadPlantMaterials(DFHackObject* mat)
{ {
if(mat != NULL) if(mat != NULL)
{ {
return ((DFHack::Materials*)mat)->ReadPlantMaterials(); if(((DFHack::Materials*)mat)->ReadPlantMaterials() == true)
return 1;
else
return 0;
} }
return -1; return -1;
@ -72,7 +84,10 @@ int Materials_ReadCreatureTypes(DFHackObject* mat)
{ {
if(mat != NULL) if(mat != NULL)
{ {
return ((DFHack::Materials*)mat)->ReadCreatureTypes(); if(((DFHack::Materials*)mat)->ReadCreatureTypes() == true)
return 1;
else
return 0;
} }
return -1; return -1;
@ -82,7 +97,10 @@ int Materials_ReadCreatureTypesEx(DFHackObject* mat)
{ {
if(mat != NULL) if(mat != NULL)
{ {
return ((DFHack::Materials*)mat)->ReadCreatureTypesEx(); if(((DFHack::Materials*)mat)->ReadCreatureTypesEx() == true)
return 1;
else
return 0;
} }
return -1; return -1;
@ -92,7 +110,10 @@ int Materials_ReadDescriptorColors(DFHackObject* mat)
{ {
if(mat != NULL) if(mat != NULL)
{ {
return ((DFHack::Materials*)mat)->ReadDescriptorColors(); if(((DFHack::Materials*)mat)->ReadDescriptorColors() == true)
return 1;
else
return 0;
} }
return -1; return -1;
@ -102,7 +123,10 @@ int Materials_ReadOthers(DFHackObject* mat)
{ {
if(mat != NULL) if(mat != NULL)
{ {
return ((DFHack::Materials*)mat)->ReadOthers(); if(((DFHack::Materials*)mat)->ReadOthers() == true)
return 1;
else
return 0;
} }
return -1; return -1;
@ -237,7 +261,7 @@ t_matgloss* Materials_getInorganic(DFHackObject* mat)
if(alloc_matgloss_buffer_callback == NULL) if(alloc_matgloss_buffer_callback == NULL)
return NULL; return NULL;
((*alloc_matgloss_buffer_callback)(buf, materials->inorganic.size())); ((*alloc_matgloss_buffer_callback)(&buf, materials->inorganic.size()));
if(buf != NULL) if(buf != NULL)
{ {
@ -264,7 +288,7 @@ t_matgloss* Materials_getOrganic(DFHackObject* mat)
if(alloc_matgloss_buffer_callback == NULL) if(alloc_matgloss_buffer_callback == NULL)
return NULL; return NULL;
((*alloc_matgloss_buffer_callback)(buf, materials->organic.size())); ((*alloc_matgloss_buffer_callback)(&buf, materials->organic.size()));
if(buf != NULL) if(buf != NULL)
{ {
@ -291,7 +315,7 @@ t_matgloss* Materials_getTree(DFHackObject* mat)
if(alloc_matgloss_buffer_callback == NULL) if(alloc_matgloss_buffer_callback == NULL)
return NULL; return NULL;
((*alloc_matgloss_buffer_callback)(buf, materials->tree.size())); ((*alloc_matgloss_buffer_callback)(&buf, materials->tree.size()));
if(buf != NULL) if(buf != NULL)
{ {
@ -318,7 +342,7 @@ t_matgloss* Materials_getPlant(DFHackObject* mat)
if(alloc_matgloss_buffer_callback == NULL) if(alloc_matgloss_buffer_callback == NULL)
return NULL; return NULL;
((*alloc_matgloss_buffer_callback)(buf, materials->plant.size())); ((*alloc_matgloss_buffer_callback)(&buf, materials->plant.size()));
if(buf != NULL) if(buf != NULL)
{ {
@ -345,7 +369,7 @@ t_matgloss* Materials_getRace(DFHackObject* mat)
if(alloc_matgloss_buffer_callback == NULL) if(alloc_matgloss_buffer_callback == NULL)
return NULL; return NULL;
((*alloc_matgloss_buffer_callback)(buf, materials->race.size())); ((*alloc_matgloss_buffer_callback)(&buf, materials->race.size()));
if(buf != NULL) if(buf != NULL)
{ {
@ -374,12 +398,12 @@ c_creaturetype* Materials_getRaceEx(DFHackObject* mat)
if(alloc_creaturetype_buffer_callback == NULL) if(alloc_creaturetype_buffer_callback == NULL)
return NULL; return NULL;
((*alloc_creaturetype_buffer_callback)(buf, matSize)); ((*alloc_creaturetype_buffer_callback)(&buf, matSize));
if(buf != NULL) if(buf != NULL)
{ {
for(int i = 0; i < matSize; i++) for(int i = 0; i < matSize; i++)
CreatureTypeConvert(&materials->raceEx[i], &buf[i]); CreatureTypeConvert(&materials->raceEx[i], &(buf[i]));
return buf; return buf;
} }
@ -399,7 +423,7 @@ t_descriptor_color* Materials_getColor(DFHackObject* mat)
{ {
t_descriptor_color* buf = NULL; t_descriptor_color* buf = NULL;
((*alloc_descriptor_buffer_callback)(buf, materials->color.size())); ((*alloc_descriptor_buffer_callback)(&buf, materials->color.size()));
if(buf != NULL) if(buf != NULL)
{ {
@ -423,7 +447,7 @@ t_matglossOther* Materials_getOther(DFHackObject* mat)
{ {
t_matglossOther* buf = NULL; t_matglossOther* buf = NULL;
((*alloc_matgloss_other_buffer_callback)(buf, materials->other.size())); ((*alloc_matgloss_other_buffer_callback)(&buf, materials->other.size()));
if(buf != NULL) if(buf != NULL)
{ {
@ -447,7 +471,7 @@ t_matgloss* Materials_getAllDesc(DFHackObject* mat)
{ {
t_matgloss* buf = NULL; t_matgloss* buf = NULL;
((*alloc_matgloss_buffer_callback)(buf, materials->alldesc.size())); ((*alloc_matgloss_buffer_callback)(&buf, materials->alldesc.size()));
if(buf != NULL) if(buf != NULL)
{ {

@ -104,7 +104,7 @@ t_hotkey* Position_ReadHotkeys(DFHackObject* pos)
{ {
t_hotkey* buf = NULL; t_hotkey* buf = NULL;
(*alloc_t_hotkey_buffer_callback)(buf, NUM_HOTKEYS); (*alloc_t_hotkey_buffer_callback)(&buf, NUM_HOTKEYS);
if(buf != NULL) if(buf != NULL)
{ {
@ -146,7 +146,7 @@ t_screen* Position_getScreenTiles(DFHackObject* pos, int32_t width, int32_t heig
{ {
t_screen* buf = NULL; t_screen* buf = NULL;
(*alloc_t_screen_buffer_callback)(buf, width * height); (*alloc_t_screen_buffer_callback)(&buf, width * height);
if(buf == NULL) if(buf == NULL)
return NULL; return NULL;

@ -58,64 +58,6 @@ int Translation_Finish(DFHackObject* trans)
return -1; return -1;
} }
// char* Translation_TranslateNameEnglish(DFHackObject* trans, const DFHack::t_name* name, char* (*char_buffer_create)(int))
// {
// if(trans != NULL)
// {
// std::string nameTrans = ((DFHack::Translation*)trans)->TranslateName(*name, true);
// if(nameTrans.size() > 0)
// {
// char* buf = (*char_buffer_create)(nameTrans.size());
// if(buf != NULL)
// {
// size_t len = nameTrans.copy(buf, nameTrans.size());
// if(len > 0)
// buf[len] = '\0';
// else
// buf[0] = '\0';
// }
// return buf;
// }
// else
// return NULL;
// }
// return NULL;
// }
// char* Translation_TranslateNameNonEnglish(DFHackObject* trans, const DFHack::t_name* name, char* (*char_buffer_create)(int))
// {
// if(trans != NULL)
// {
// std::string nameTrans = ((DFHack::Translation*)trans)->TranslateName(*name, false);
// if(nameTrans.size() > 0)
// {
// char* buf = (*char_buffer_create)(nameTrans.size());
// if(buf != NULL)
// {
// size_t len = nameTrans.copy(buf, nameTrans.size());
// if(len > 0)
// buf[len] = '\0';
// else
// buf[0] = '\0';
// }
// return buf;
// }
// else
// return NULL;
// }
// return NULL;
// }
char* Translation_TranslateNameEnglish(DFHackObject* trans, const DFHack::t_name* name) char* Translation_TranslateNameEnglish(DFHackObject* trans, const DFHack::t_name* name)
{ {
if(trans != NULL) if(trans != NULL)
@ -126,7 +68,7 @@ char* Translation_TranslateNameEnglish(DFHackObject* trans, const DFHack::t_name
{ {
char* buf = NULL; char* buf = NULL;
(*alloc_char_buffer_callback)(buf, nameTrans.size()); (*alloc_char_buffer_callback)(&buf, nameTrans.size());
if(buf != NULL) if(buf != NULL)
{ {
@ -157,7 +99,7 @@ char* Translation_TranslateNameNonEnglish(DFHackObject* trans, const DFHack::t_n
{ {
char* buf = NULL; char* buf = NULL;
(*alloc_char_buffer_callback)(buf, nameTrans.size()); (*alloc_char_buffer_callback)(&buf, nameTrans.size());
if(buf != NULL) if(buf != NULL)
{ {