develop
Petr Mrázek 2010-09-24 19:07:07 +02:00
commit b95ec7a2b3
9 changed files with 342 additions and 9 deletions

@ -29,7 +29,7 @@ SET( DATA_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/output CACHE PATH "Output directory fo
OPTION(BUILD_DFHACK_DOCUMENTATION "Create doxygen documentation for developers" OFF)
OPTION(BUILD_DFHACK_EXAMPLES "Build example tools" OFF)
OPTION(BUILD_DFHACK_PLAYGROUND "Build tools from the playground folder" OFF)
OPTION(BUILD_DFHACK_C_BINDIGS "Build the C portion of the library" ON)
OPTION(BUILD_DFHACK_C_BINDINGS "Build the C portion of the library" ON)
OPTION(BUILD_OFFSET_EDITOR "Build the Offset GUI editor (not ready for use)." OFF)
OPTION(BUILD_DFHACK_SUPPORTED "Build the supported toold." ON)
OPTION(BUILD_DFHACK_SHM "Build the SHM." OFF)

@ -39,6 +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
@ -80,6 +105,114 @@ int (*alloc_vein_buffer_callback)(t_vein*, uint32_t) = NULL;
int (*alloc_frozenliquidvein_buffer_callback)(t_frozenliquidvein*, uint32_t) = NULL;
int (*alloc_spattervein_buffer_callback)(t_spattervein*, uint32_t) = NULL;
REG_MACRO(Byte, int8_t*, alloc_byte_buffer_callback)
REG_MACRO(Short, int16_t*, alloc_short_buffer_callback)
REG_MACRO(Int, int32_t*, alloc_int_buffer_callback)
REG_MACRO(UByte, uint8_t*, alloc_ubyte_buffer_callback)
REG_MACRO(UShort, uint16_t*, alloc_ushort_buffer_callback)
REG_MACRO(UInt, uint32_t*, alloc_uint_buffer_callback)
REG_MACRO(Char, char*, alloc_char_buffer_callback)
REG_MACRO(Matgloss, t_matgloss*, alloc_matgloss_buffer_callback)
REG_MACRO(DescriptorColor, t_descriptor_color*, alloc_descriptor_buffer_callback)
REG_MACRO(MatglossOther, t_matglossOther*, alloc_matgloss_other_buffer_callback)
REG_MACRO(Feature, t_feature*, alloc_t_feature_buffer_callback)
REG_MACRO(Hotkey, t_hotkey*, alloc_t_hotkey_buffer_callback)
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;
}
void RegisterNewColorModifierCallback(int (*funcptr)(c_colormodifier*, const char*, uint32_t))
{
alloc_colormodifier_callback = funcptr;
}
REG_MACRO(ColorModifier, c_colormodifier*, alloc_colormodifier_buffer_callback)
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*))
{
alloc_empty_creaturetype_callback = funcptr;
}
void RegisterNewCreatureTypeCallback(int (*funcptr)(c_creaturetype*, const char*, uint32_t, uint32_t, uint8_t, uint16_t, uint16_t, uint16_t))
{
alloc_creaturetype_callback = funcptr;
}
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
@ -54,6 +59,41 @@ DFHACK_EXPORT extern int (*alloc_t_feature_buffer_callback)(t_feature*, uint32_t
DFHACK_EXPORT extern int (*alloc_t_hotkey_buffer_callback)(t_hotkey*, uint32_t);
DFHACK_EXPORT extern int (*alloc_t_screen_buffer_callback)(t_screen*, uint32_t);
DFHACK_EXPORT void RegisterByteBufferCallback(int (*funcptr)(int8_t*, uint32_t));
DFHACK_EXPORT void RegisterShortBufferCallback(int (*funcptr)(int16_t*, uint32_t));
DFHACK_EXPORT void RegisterIntBufferCallback(int (*funcptr)(int32_t*, uint32_t));
DFHACK_EXPORT void RegisterUByteBufferCallback(int (*funcptr)(uint8_t*, uint32_t));
DFHACK_EXPORT void RegisterUShortBufferCallback(int (*funcptr)(uint16_t*, uint32_t));
DFHACK_EXPORT void RegisterUIntBufferCallback(int (*funcptr)(uint32_t*, uint32_t));
DFHACK_EXPORT void RegisterCharBufferCallback(int (*funcptr)(char*, uint32_t));
DFHACK_EXPORT void RegisterMatglossBufferCallback(int (*funcptr)(t_matgloss*, uint32_t));
DFHACK_EXPORT void RegisterDescriptorColorBufferCallback(int (*funcptr)(t_descriptor_color*, uint32_t));
DFHACK_EXPORT void RegisterMatglossOtherBufferCallback(int (*funcptr)(t_matglossOther*, uint32_t));
DFHACK_EXPORT void RegisterFeatureBufferCallback(int (*funcptr)(t_feature*, uint32_t));
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;
@ -61,9 +101,14 @@ struct t_customWorkshop
};
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);
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];
@ -75,6 +120,14 @@ DFHACK_EXPORT extern int (*alloc_empty_colormodifier_callback)(c_colormodifier*)
DFHACK_EXPORT extern int (*alloc_colormodifier_callback)(c_colormodifier*, const char*, uint32_t);
DFHACK_EXPORT extern int (*alloc_colormodifier_buffer_callback)(c_colormodifier*, uint32_t);
DFHACK_EXPORT void RegisterEmptyColorModifierCallback(int (*funcptr)(c_colormodifier*));
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];
@ -93,6 +146,14 @@ DFHACK_EXPORT extern int (*alloc_empty_creaturecaste_callback)(c_creaturecaste*)
DFHACK_EXPORT extern int (*alloc_creaturecaste_callback)(c_creaturecaste*, const char*, const char*, const char*, const char*, uint32_t, uint32_t);
DFHACK_EXPORT extern int (*alloc_creaturecaste_buffer_callback)(c_creaturecaste*, uint32_t);
DFHACK_EXPORT void RegisterEmptyCreatureCasteCallback(int (*funcptr)(c_creaturecaste*));
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];
@ -121,14 +182,30 @@ DFHACK_EXPORT extern int (*alloc_vein_buffer_callback)(t_vein*, 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);
DFHACK_EXPORT extern int DFHack_isWallTerrain(int in);
DFHACK_EXPORT extern int DFHack_isFloorTerrain(int in);
DFHACK_EXPORT extern int DFHack_isRampTerrain(int in);
DFHACK_EXPORT extern int DFHack_isStairTerrain(int in);
DFHACK_EXPORT extern int DFHack_isOpenTerrain(int in);
DFHACK_EXPORT extern int DFHack_getVegetationType(int in);
DFHACK_EXPORT void RegisterEmptyCreatureTypeCallback(int (*funcptr)(c_creaturetype*));
DFHACK_EXPORT void RegisterNewCreatureTypeCallback(int (*funcptr)(c_creaturetype*, const char*, uint32_t, uint32_t, uint8_t, uint16_t, uint16_t, uint16_t));
DFHACK_EXPORT void RegisterCreatureTypeBufferCallback(int (*funcptr)(c_creaturetype*, uint32_t));
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);
DFHACK_EXPORT int DFHack_isStairTerrain(int in);
DFHACK_EXPORT int DFHack_isOpenTerrain(int in);
DFHACK_EXPORT int DFHack_getVegetationType(int in);
DFHACK_EXPORT extern int DFHack_getTileType(int index, TileRow* tPtr);
DFHACK_EXPORT int DFHack_getTileType(int index, TileRow* tPtr);
#ifdef __cplusplus
}

@ -45,6 +45,9 @@ DFHACK_EXPORT int32_t Creatures_ReadCreatureInBox(DFHackObject* cPtr, const int3
DFHACK_EXPORT int Creatures_ReadCreature(DFHackObject* cPtr, const int32_t index, t_creature* furball);
DFHACK_EXPORT t_material* Creatures_ReadJob(DFHackObject* cPtr, const t_creature* furball);
DFHACK_EXPORT uint32_t* Creatures_ReadInventoryIdx(DFHackObject* cPtr, const uint32_t index);
DFHACK_EXPORT uint32_t* Creatures_ReadInventoryPtr(DFHackObject* cPtr, const uint32_t index);
DFHACK_EXPORT uint32_t Creatures_GetDwarfRaceIndex(DFHackObject* cPtr);
DFHACK_EXPORT int32_t Creatures_GetDwarfCivId(DFHackObject* cPtr);

@ -37,6 +37,7 @@ DFHACK_EXPORT int Gui_Start(DFHackObject* gui);
DFHACK_EXPORT int Gui_Finish(DFHackObject* gui);
DFHACK_EXPORT int Gui_ReadPauseState(DFHackObject* gui);
DFHACK_EXPORT int Gui_SetPauseState(DFHackObject* gui, int8_t paused);
DFHACK_EXPORT int Gui_ReadViewScreen(DFHackObject* gui, t_viewscreen* viewscreen);
DFHACK_EXPORT int Gui_ReadMenuState(DFHackObject* gui, uint32_t* menuState);

@ -36,6 +36,8 @@ extern "C" {
DFHACK_EXPORT int Maps_Start(DFHackObject* maps);
DFHACK_EXPORT int Maps_Finish(DFHackObject* maps);
DFHACK_EXPORT uint16_t* Maps_ReadGeology(DFHackObject* maps);
DFHACK_EXPORT t_feature* Maps_ReadGlobalFeatures(DFHackObject* maps);
DFHACK_EXPORT void Maps_getSize(DFHackObject* maps, uint32_t* x, uint32_t* y, uint32_t* z);

@ -104,6 +104,64 @@ t_material* Creatures_ReadJob(DFHackObject* cPtr, const t_creature* furball)
return NULL;
}
uint32_t* Creatures_ReadInventoryIdx(DFHackObject* cPtr, const uint32_t index)
{
if(cPtr != NULL)
{
std::vector<uint32_t> item;
if(((DFHack::Creatures*)cPtr)->ReadInventoryIdx(index, item))
{
if(item.size() <= 0)
return NULL;
uint32_t* buf;
(*alloc_uint_buffer_callback)(buf, item.size());
if(buf != NULL)
{
copy(item.begin(), item.end(), buf);
return buf;
}
else
return NULL;
}
}
return NULL;
}
uint32_t* Creatures_ReadInventoryPtr(DFHackObject* cPtr, const uint32_t index)
{
if(cPtr != NULL)
{
std::vector<uint32_t> item;
if(((DFHack::Creatures*)cPtr)->ReadInventoryPtr(index, item))
{
if(item.size() <= 0)
return NULL;
uint32_t* buf;
(*alloc_uint_buffer_callback)(buf, item.size());
if(buf != NULL)
{
copy(item.begin(), item.end(), buf);
return buf;
}
else
return NULL;
}
}
return NULL;
}
uint32_t Creatures_GetDwarfRaceIndex(DFHackObject* cPtr)
{
if(cPtr != NULL)

@ -58,6 +58,23 @@ int Gui_ReadPauseState(DFHackObject* gui)
return -1;
}
int Gui_SetPauseState(DFHackObject* gui, int8_t paused)
{
if(gui != NULL)
{
bool pauseState = false;
if(paused > 0)
pauseState = true;
((DFHack::Gui*)gui)->SetPauseState(pauseState);
return 1;
}
return -1;
}
int Gui_ReadViewScreen(DFHackObject* gui, t_viewscreen* viewscreen)
{
if(gui != NULL)

@ -54,6 +54,48 @@ int Maps_Finish(DFHackObject* maps)
return -1;
}
uint16_t* Maps_ReadGeology(DFHackObject* maps)
{
if(maps != NULL)
{
std::vector < std::vector <uint16_t> > geology;
if(((DFHack::Maps*)maps)->ReadGeology(geology))
{
uint16_t* buf;
uint32_t geoLength = 0;
for(int i = 0; i < geology.size(); i++)
{
for(int j = 0; j < geology[i].size(); j++)
{
geoLength += geology[i].size();
}
}
(*alloc_ushort_buffer_callback)(buf, geoLength);
if(buf != NULL)
{
uint16_t* bufCopyPtr = buf;
for(int i = 0; i < geology.size(); i++)
{
copy(geology[i].begin(), geology[i].end(), bufCopyPtr);
bufCopyPtr += geology[i].size();
}
return buf;
}
else
return NULL;
}
}
return NULL;
}
t_feature* Maps_ReadGlobalFeatures(DFHackObject* maps)
{
if(maps != NULL)