updated to use pre-registered callbacks like everything else

develop
doomchild 2010-08-18 12:59:11 -05:00
parent 34b6bc06b6
commit 2889b01357
8 changed files with 132 additions and 26 deletions

@ -57,6 +57,9 @@ int (*alloc_matgloss_buffer_callback)(t_matgloss*, uint32_t) = NULL;
int (*alloc_descriptor_buffer_callback)(t_descriptor_color*, uint32_t) = NULL;
int (*alloc_matgloss_other_buffer_callback)(t_matglossOther*, uint32_t) = NULL;
int (*alloc_t_customWorkshop_buffer_callback)(t_customWorkshop*, uint32_t) = NULL;
int (*alloc_t_material_buffer_callback)(t_material*, uint32_t) = NULL;
int (*alloc_empty_colormodifier_callback)(c_colormodifier*) = NULL;
int (*alloc_colormodifier_callback)(c_colormodifier*, const char*, uint32_t) = NULL;
int (*alloc_colormodifier_buffer_callback)(c_colormodifier*, uint32_t) = NULL;

@ -49,6 +49,16 @@ DFHACK_EXPORT extern int (*alloc_matgloss_buffer_callback)(t_matgloss*, uint32_t
DFHACK_EXPORT extern int (*alloc_descriptor_buffer_callback)(t_descriptor_color*, uint32_t);
DFHACK_EXPORT extern int (*alloc_matgloss_other_buffer_callback)(t_matglossOther*, uint32_t);
struct t_customWorkshop
{
uint32_t index;
char name[256];
};
DFHACK_EXPORT extern int (*alloc_t_customWorkshop_buffer_callback)(t_customWorkshop*, uint32_t);
DFHACK_EXPORT extern int (*alloc_t_material_buffer_callback)(t_material*, uint32_t);
struct c_colormodifier
{
char part[128];

@ -28,23 +28,18 @@ distribution.
#include "DFHack_C.h"
#include "dfhack/DFTypes.h"
#include "dfhack/modules/Buildings.h"
#include "dfhack-c/DFTypes_C.h"
#ifdef __cplusplus
extern "C" {
#endif
struct t_customWorkshop
{
uint32_t index;
char name[256];
};
DFHACK_EXPORT int Buildings_Start(DFHackObject* b_Ptr, uint32_t* numBuildings);
DFHACK_EXPORT int Buildings_Finish(DFHackObject* b_Ptr);
DFHACK_EXPORT int Buildings_Read(DFHackObject* b_Ptr, const uint32_t index, t_building* building);
DFHACK_EXPORT int Buildings_ReadCustomWorkshopTypes(DFHackObject* b_Ptr, void* (*t_customWorkshop_buffer_create)(uint32_t));
DFHACK_EXPORT t_customWorkshop* Buildings_ReadCustomWorkshopTypes(DFHackObject* b_Ptr);
DFHACK_EXPORT int Buildings_GetCustomWorkshopType(DFHackObject* b_Ptr, t_building* building);
#ifdef __cplusplus

@ -27,6 +27,7 @@ distribution.
#include "DFHack_C.h"
#include "dfhack/DFTypes.h"
#include "dfhack-c/DFTypes_C.h"
#include "dfhack/modules/Materials.h"
#include "dfhack/modules/Creatures.h"
@ -47,7 +48,7 @@ DFHACK_EXPORT int Creatures_WriteLabors(DFHackObject* cPtr, const uint32_t index
DFHACK_EXPORT uint32_t Creatures_GetDwarfRaceIndex(DFHackObject* cPtr);
DFHACK_EXPORT int32_t Creatures_GetDwarfCivId(DFHackObject* cPtr);
DFHACK_EXPORT int Creatures_ReadJob(DFHackObject* cPtr, const t_creature* furball, t_material* (*t_material_buffer_create)(int));
DFHACK_EXPORT t_material* Creatures_ReadJob(DFHackObject* cPtr, const t_creature* furball);
#ifdef __cplusplus
}

@ -27,6 +27,7 @@ distribution.
#include "DFHack_C.h"
#include "dfhack/DFTypes.h"
#include "dfhack-c/DFTypes_C.h"
#include "dfhack/modules/Translation.h"
#ifdef __cplusplus
@ -36,8 +37,8 @@ extern "C" {
DFHACK_EXPORT int Translation_Start(DFHackObject* trans);
DFHACK_EXPORT int Translation_Finish(DFHackObject* trans);
DFHACK_EXPORT char* Translation_TranslateNameEnglish(DFHackObject* trans, const DFHack::t_name* name, char* (*char_buffer_create)(int));
DFHACK_EXPORT char* Translation_TranslateNameNonEnglish(DFHackObject* trans, const DFHack::t_name* name, char* (*char_buffer_create)(int));
DFHACK_EXPORT char* Translation_TranslateNameEnglish(DFHackObject* trans, const DFHack::t_name* name);
DFHACK_EXPORT char* Translation_TranslateNameNonEnglish(DFHackObject* trans, const DFHack::t_name* name);
#ifdef __cplusplus
}

@ -24,6 +24,7 @@ distribution.
#include "dfhack-c/modules/Buildings_C.h"
using namespace std;
#ifdef __cplusplus
extern "C" {
#endif
@ -68,7 +69,7 @@ int Buildings_GetCustomWorkshopType(DFHackObject* b_Ptr, t_building* building)
return -1;
}
int Buildings_ReadCustomWorkshopTypes(DFHackObject* b_Ptr, void* (*t_customWorkshop_buffer_create)(uint32_t))
t_customWorkshop* Buildings_ReadCustomWorkshopTypes(DFHackObject* b_Ptr)
{
if(b_Ptr != NULL)
{
@ -78,19 +79,24 @@ int Buildings_ReadCustomWorkshopTypes(DFHackObject* b_Ptr, void* (*t_customWorks
map<uint32_t, string>::iterator bIter;
if(!((DFHack::Buildings*)b_Ptr)->ReadCustomWorkshopTypes(bTypes))
return 0;
cw_Ptr = (t_customWorkshop*)((*t_customWorkshop_buffer_create)(bTypes.size()));
return NULL;
(*alloc_t_customWorkshop_buffer_callback)(cw_Ptr, bTypes.size());
if(cw_Ptr == NULL)
return NULL;
for(i = 0, bIter = bTypes.begin(); bIter != bTypes.end(); bIter++, i++)
{
cw_Ptr[i].index = (*bIter).first;
size_t length = (*bIter).second.copy(cw_Ptr[i].name, 256);
cw_Ptr[i].name[length] = '\0';
}
return 1;
return cw_Ptr;
}
return -1;
return NULL;
}
#ifdef __cplusplus

@ -98,7 +98,33 @@ int32_t Creatures_GetDwarfCivId(DFHackObject* cPtr)
return -1;
}
int Creatures_ReadJob(DFHackObject* cPtr, const t_creature* furball, t_material* (*t_material_buffer_create)(int))
// int Creatures_ReadJob(DFHackObject* cPtr, const t_creature* furball, t_material* (*t_material_buffer_create)(int))
// {
// if(cPtr != NULL)
// {
// std::vector<t_material> mat;
// if(((DFHack::Creatures*)cPtr)->ReadJob(furball, mat))
// {
// t_material* buf = (*t_material_buffer_create)(mat.size());
// if(buf != NULL)
// {
// copy(mat.begin(), mat.end(), buf);
// return 1;
// }
// else
// return -1;
// }
// else
// return 0;
// }
// return -1;
// }
t_material* Creatures_ReadJob(DFHackObject* cPtr, const t_creature* furball)
{
if(cPtr != NULL)
{
@ -106,22 +132,24 @@ int Creatures_ReadJob(DFHackObject* cPtr, const t_creature* furball, t_material*
if(((DFHack::Creatures*)cPtr)->ReadJob(furball, mat))
{
t_material* buf = (*t_material_buffer_create)(mat.size());
t_material* buf;
(*alloc_t_material_buffer_callback)(buf, mat.size());
if(buf != NULL)
{
copy(mat.begin(), mat.end(), buf);
return 1;
return buf;
}
else
return -1;
return NULL;
}
else
return 0;
return NULL;
}
return -1;
return NULL;
}
#ifdef __cplusplus

@ -58,7 +58,65 @@ int Translation_Finish(DFHackObject* trans)
return -1;
}
char* Translation_TranslateNameEnglish(DFHackObject* trans, const DFHack::t_name* name, char* (*char_buffer_create)(int))
// 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)
{
if(trans != NULL)
{
@ -66,7 +124,9 @@ char* Translation_TranslateNameEnglish(DFHackObject* trans, const DFHack::t_name
if(nameTrans.size() > 0)
{
char* buf = (*char_buffer_create)(nameTrans.size());
char* buf;
(*alloc_char_buffer_callback)(buf, nameTrans.size());
if(buf != NULL)
{
@ -87,7 +147,7 @@ char* Translation_TranslateNameEnglish(DFHackObject* trans, const DFHack::t_name
return NULL;
}
char* Translation_TranslateNameNonEnglish(DFHackObject* trans, const DFHack::t_name* name, char* (*char_buffer_create)(int))
char* Translation_TranslateNameNonEnglish(DFHackObject* trans, const DFHack::t_name* name)
{
if(trans != NULL)
{
@ -95,7 +155,9 @@ char* Translation_TranslateNameNonEnglish(DFHackObject* trans, const DFHack::t_n
if(nameTrans.size() > 0)
{
char* buf = (*char_buffer_create)(nameTrans.size());
char* buf;
(*alloc_char_buffer_callback)(buf, nameTrans.size());
if(buf != NULL)
{