added unregistration functions for callbacks

develop
doomchild 2010-09-16 13:04:52 -05:00
parent 78a12876d5
commit 70b1a48cea
2 changed files with 115 additions and 0 deletions

@ -39,9 +39,31 @@ using namespace std;
using namespace DFHack;
/*
I believe this is what they call "the bad kind of clever", but writing out registration functions for each callback just feels *so* wrong...
The output of this macro is something like this...
void RegisterByteBufferCallback(int(*fptr)(int8_t*, uint32_t))
{
alloc_byte_buffer_callback = fptr;
}
*/
#define BUILD(a) a ## BufferCallback
#define REG_MACRO(type_name, type, callback) void BUILD(Register ## type_name) (int (*fptr)(type, uint32_t)) { callback = fptr; }
/*
The output of this macro is something like this...
void UnregisterByteBufferCallback()
{
alloc_byte_buffer_callback = NULL;
}
*/
#define UNREG_MACRO(type_name, callback) void BUILD(Unregister ## type_name) () { callback = NULL; }
#ifdef __cplusplus
extern "C" {
#endif
@ -99,6 +121,22 @@ REG_MACRO(Screen, t_screen*, alloc_t_screen_buffer_callback)
REG_MACRO(CustomWorkshop, t_customWorkshop*, alloc_t_customWorkshop_buffer_callback)
REG_MACRO(Material, t_material*, alloc_t_material_buffer_callback)
UNREG_MACRO(Byte, alloc_byte_buffer_callback)
UNREG_MACRO(Short, alloc_short_buffer_callback)
UNREG_MACRO(Int, alloc_int_buffer_callback)
UNREG_MACRO(UByte, alloc_ubyte_buffer_callback)
UNREG_MACRO(UShort, alloc_ushort_buffer_callback)
UNREG_MACRO(UInt, alloc_uint_buffer_callback)
UNREG_MACRO(Char, alloc_char_buffer_callback)
UNREG_MACRO(Matgloss, alloc_matgloss_buffer_callback)
UNREG_MACRO(DescriptorColor, alloc_descriptor_buffer_callback)
UNREG_MACRO(MatglossOther, alloc_matgloss_other_buffer_callback)
UNREG_MACRO(Feature, alloc_t_feature_buffer_callback)
UNREG_MACRO(Hotkey, alloc_t_hotkey_buffer_callback)
UNREG_MACRO(Screen, alloc_t_screen_buffer_callback)
UNREG_MACRO(CustomWorkshop, alloc_t_customWorkshop_buffer_callback)
UNREG_MACRO(Material, alloc_t_material_buffer_callback)
void RegisterEmptyColorModifierCallback(int (*funcptr)(c_colormodifier*))
{
alloc_empty_colormodifier_callback = funcptr;
@ -116,12 +154,33 @@ void RegisterEmptyCreatureCasteCallback(int (*funcptr)(c_creaturecaste*))
alloc_empty_creaturecaste_callback = funcptr;
}
void UnregisterEmptyColorModifierCallback()
{
alloc_empty_colormodifier_callback = NULL;
}
void UnregisterNewColorModifierCallback()
{
alloc_colormodifier_callback = NULL;
}
void RegisterNewCreatureCasteCallback(int (*funcptr)(c_creaturecaste*, const char*, const char*, const char*, const char*, uint32_t, uint32_t))
{
alloc_creaturecaste_callback = funcptr;
}
REG_MACRO(CreatureCaste, c_creaturecaste*, alloc_creaturecaste_buffer_callback)
UNREG_MACRO(CreatureCaste, alloc_creaturecaste_buffer_callback)
void UnregisterEmptyCreatureCasteCallback()
{
alloc_empty_creaturecaste_callback = NULL;
}
void UnregisterNewCreatureCasteCallback()
{
alloc_creaturecaste_callback = NULL;
}
void RegisterEmptyCreatureTypeCallback(int (*funcptr)(c_creaturetype*))
{
@ -134,11 +193,26 @@ void RegisterNewCreatureTypeCallback(int (*funcptr)(c_creaturetype*, const char*
}
REG_MACRO(CreatureType, c_creaturetype*, alloc_creaturetype_buffer_callback)
UNREG_MACRO(CreatureType, alloc_creaturetype_buffer_callback)
void UnregisterEmptyCreatureTypeCallback()
{
alloc_empty_creaturetype_callback = NULL;
}
void UnregisterNewCreatureTypeCallback()
{
alloc_creaturetype_callback = NULL;
}
REG_MACRO(Vein, t_vein*, alloc_vein_buffer_callback)
REG_MACRO(FrozenLiquidVein, t_frozenliquidvein*, alloc_frozenliquidvein_buffer_callback)
REG_MACRO(SpatterVein, t_spattervein*, alloc_spattervein_buffer_callback)
UNREG_MACRO(Vein, alloc_vein_buffer_callback)
UNREG_MACRO(FrozenLiquidVein, alloc_frozenliquidvein_buffer_callback)
UNREG_MACRO(SpatterVein, alloc_spattervein_buffer_callback)
int DFHack_isWallTerrain(int in)
{
return DFHack::isWallTerrain(in);

@ -32,6 +32,11 @@ distribution.
#include "dfhack/modules/Position.h"
#include "dfhack/DFTileTypes.h"
#define HBUILD(a) a ## BufferCallback
#define HREG_MACRO(type_name, type) DFHACK_EXPORT void HBUILD(Register ## type_name) (int (*funcptr)(type, uint32_t));
#define HUNREG_MACRO(type_name) DFHACK_EXPORT void HBUILD(Unregister ## type_name) ();
#ifdef __cplusplus
extern "C" {
#endif
@ -72,6 +77,23 @@ DFHACK_EXPORT void RegisterFeatureBufferCallback(int (*funcptr)(t_feature*, uint
DFHACK_EXPORT void RegisterHotkeyBufferCallback(int (*funcptr)(t_hotkey*, uint32_t));
DFHACK_EXPORT void RegisterScreenBufferCallback(int (*funcptr)(t_screen*, uint32_t));
HUNREG_MACRO(Byte)
HUNREG_MACRO(Short)
HUNREG_MACRO(Int)
HUNREG_MACRO(UByte)
HUNREG_MACRO(UShort)
HUNREG_MACRO(UInt)
HUNREG_MACRO(Char)
HUNREG_MACRO(Matgloss)
HUNREG_MACRO(DescriptorColor)
HUNREG_MACRO(MatglossOther)
HUNREG_MACRO(Feature)
HUNREG_MACRO(Hotkey)
HUNREG_MACRO(Screen)
struct t_customWorkshop
{
uint32_t index;
@ -84,6 +106,9 @@ DFHACK_EXPORT extern int (*alloc_t_material_buffer_callback)(t_material*, uint32
DFHACK_EXPORT void RegisterCustomWorkshopBufferCallback(int (*funcptr)(t_customWorkshop*, uint32_t));
DFHACK_EXPORT void RegisterMaterialBufferCallback(int (*funcptr)(t_material*, uint32_t));
HUNREG_MACRO(CustomWorkshop)
HUNREG_MACRO(Material)
struct c_colormodifier
{
char part[128];
@ -99,6 +124,10 @@ DFHACK_EXPORT void RegisterEmptyColorModifierCallback(int (*funcptr)(c_colormodi
DFHACK_EXPORT void RegisterNewColorModifierCallback(int (*funcptr)(c_colormodifier*, const char*, uint32_t));
DFHACK_EXPORT void RegisterColorModifierBufferCallback(int (*funcptr)(c_colormodifier*, uint32_t));
DFHACK_EXPORT void UnregisterEmptyColorModifierCallback();
DFHACK_EXPORT void UnregisterNewColorModifierCallback();
HUNREG_MACRO(ColorModifier)
struct c_creaturecaste
{
char rawname[128];
@ -121,6 +150,10 @@ DFHACK_EXPORT void RegisterEmptyCreatureCasteCallback(int (*funcptr)(c_creaturec
DFHACK_EXPORT void RegisterNewCreatureCasteCallback(int (*funcptr)(c_creaturecaste*, const char*, const char*, const char*, const char*, uint32_t, uint32_t));
DFHACK_EXPORT void RegisterCreatureCasteBufferCallback(int (*funcptr)(c_creaturecaste*, uint32_t));
DFHACK_EXPORT void UnregisterEmptyCreatureCasteCallback();
DFHACK_EXPORT void UnregisterNewCreatureCasteCallback();
HUNREG_MACRO(CreatureCaste)
struct c_creaturetype
{
char rawname[128];
@ -157,6 +190,14 @@ DFHACK_EXPORT void RegisterVeinBufferCallback(int (*funcptr)(t_vein*, uint32_t))
DFHACK_EXPORT void RegisterFrozenLiquidVeinBufferCallback(int (*funcptr)(t_frozenliquidvein*, uint32_t));
DFHACK_EXPORT void RegisterSpatterVeinBufferCallback(int (*funcptr)(t_spattervein*, uint32_t));
DFHACK_EXPORT void UnregisterEmptyCreatureTypeCallback();
DFHACK_EXPORT void UnregisterNewCreatureTypeCallback();
HUNREG_MACRO(CreatureType)
HUNREG_MACRO(Vein)
HUNREG_MACRO(FrozenLiquidVein)
HUNREG_MACRO(SpatterVein)
DFHACK_EXPORT int DFHack_isWallTerrain(int in);
DFHACK_EXPORT int DFHack_isFloorTerrain(int in);
DFHACK_EXPORT int DFHack_isRampTerrain(int in);