develop
Petr Mrázek 2010-08-28 06:36:40 +02:00
commit 4d55e37e20
11 changed files with 136 additions and 4 deletions

@ -57,6 +57,10 @@ int (*alloc_matgloss_buffer_callback)(t_matgloss*, uint32_t) = NULL;
int (*alloc_descriptor_buffer_callback)(t_descriptor_color*, 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_matgloss_other_buffer_callback)(t_matglossOther*, uint32_t) = NULL;
int (*alloc_t_feature_buffer_callback)(t_feature*, uint32_t) = NULL;
int (*alloc_t_hotkey_buffer_callback)(t_hotkey*, uint32_t) = NULL;
int (*alloc_t_screen_buffer_callback)(t_screen*, uint32_t) = NULL;
int (*alloc_t_customWorkshop_buffer_callback)(t_customWorkshop*, 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_t_material_buffer_callback)(t_material*, uint32_t) = NULL;

@ -29,6 +29,7 @@ distribution.
#include "dfhack/DFTypes.h" #include "dfhack/DFTypes.h"
#include "dfhack/modules/Maps.h" #include "dfhack/modules/Maps.h"
#include "dfhack/modules/Materials.h" #include "dfhack/modules/Materials.h"
#include "dfhack/modules/Position.h"
#include "dfhack/DFTileTypes.h" #include "dfhack/DFTileTypes.h"
#ifdef __cplusplus #ifdef __cplusplus
@ -49,6 +50,10 @@ 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_descriptor_buffer_callback)(t_descriptor_color*, uint32_t);
DFHACK_EXPORT extern int (*alloc_matgloss_other_buffer_callback)(t_matglossOther*, uint32_t); DFHACK_EXPORT extern int (*alloc_matgloss_other_buffer_callback)(t_matglossOther*, uint32_t);
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);
struct t_customWorkshop struct t_customWorkshop
{ {
uint32_t index; uint32_t index;

@ -54,17 +54,36 @@ Buffer Callback List
- alloc_ubyte_buffer_callback(uint8_t*, uint32_t) - alloc_ubyte_buffer_callback(uint8_t*, uint32_t)
- alloc_ushort_buffer_callback(uint16_t*, uint32_t) - alloc_ushort_buffer_callback(uint16_t*, uint32_t)
- alloc_uint_buffer_callback(uint32_t*, uint32_t) - alloc_uint_buffer_callback(uint32_t*, uint32_t)
- alloc_char_buffer_callback(char* uint32_t)
- alloc_matgloss_buffer_callback(t_matgloss*, uint32_t) - alloc_matgloss_buffer_callback(t_matgloss*, uint32_t)
- alloc_descriptor_buffer_callback(t_descriptor_color*, uint32_t) - alloc_descriptor_buffer_callback(t_descriptor_color*, uint32_t)
- alloc_matgloss_other_buffer_callback(t_matglossOther*, uint32_t) - alloc_matgloss_other_buffer_callback(t_matglossOther*, uint32_t)
- alloc_vein_buffer_callback(t_vein*, uint32_t) - alloc_vein_buffer_callback(t_vein*, uint32_t)
- alloc_t_feature_buffer_callback(t_feature*, uint32_t)
- alloc_t_hotkey_buffer_callback(t_hotkey*, uint32_t)
- alloc_t_screen_buffer_callback(t_screen*, uint32_t)
- alloc_frozenliquidvein_buffer_callback(t_frozenliquidvein*, uint32_t) - alloc_frozenliquidvein_buffer_callback(t_frozenliquidvein*, uint32_t)
- alloc_spattervein_buffer_callback(t_spattervein*, uint32_t) - alloc_spattervein_buffer_callback(t_spattervein*, uint32_t)
Templates Make My Life Harder Templates Make My Life Harder
------------------------------- -------------------------------
Three dfhack structures (t_colormodifier, t_creaturecaste, and t_creaturetype) contain vectors, which (obviously) don't work in C. Therefore, these structures have C versions that replace the vector with a buffer and length, but are otherwise identical to their C++ counterparts. For each structure, there are three associated callbacks. One initializes an empty instance of the structure, one initializes an instance with values passed in, and one allocates a buffer in the same manner as the other allocators. Several dfhack structures contain vectors, which (obviously) don't work in C. Therefore, these structures have C versions that replace the vector with a buffer and length, but are otherwise identical to their C++ counterparts. For each structure, there are three associated callbacks. One initializes an empty instance of the structure (*alloc_empty_colormodifier_callback*, for instance), one initializes an instance with values passed in (*alloc_colormodifier_callback*), and one allocates a buffer in the same manner as the other allocators (*alloc_colormodifier_buffer_callback*).
The replaced structures and their callbacks are as follows.
- c_colormodifier
* alloc_empty_colormodifier_callback(c_colormodifier*)
* alloc_colormodifier_callback(c_colormodifier*, const char*, uint32_t)
* alloc_colormodifier_buffer_callback(c_colormodifier*, uint32_t)
- c_creaturecaste
* alloc_empty_creaturecaste_callback(c_creaturecaste*)
* alloc_creaturecaste_callback(c_creaturecaste*, const char*, const char*, const char*, const char*, uint32_t, uint32_t)
* alloc_creaturecaste_buffer_callback(c_creaturecaste*, uint32_t)
- c_creaturetype
* alloc_empty_creaturetype_callback(c_creaturetype*)
* alloc_creaturetype_callback(c_creaturetype*, const char*, uint32_t, uint32_t, uint8_t, uint16_t, uint16_t, uint16_t)
* alloc_creaturetype_buffer_callback(c_creaturetype*, uint32_t)
A Small Callback Example In Python A Small Callback Example In Python
------------------------------------- -------------------------------------
The Python bindings for dfhack implement the unsigned integer allocator callback like this: The Python bindings for dfhack implement the unsigned integer allocator callback like this:

@ -38,6 +38,7 @@ DFHACK_EXPORT int Gui_Finish(DFHackObject* gui);
DFHACK_EXPORT int Gui_ReadPauseState(DFHackObject* gui); DFHACK_EXPORT int Gui_ReadPauseState(DFHackObject* gui);
DFHACK_EXPORT int Gui_ReadViewScreen(DFHackObject* gui, t_viewscreen* viewscreen); DFHACK_EXPORT int Gui_ReadViewScreen(DFHackObject* gui, t_viewscreen* viewscreen);
DFHACK_EXPORT int Gui_ReadMenuState(DFHackObject* gui, uint32_t* menuState);
#ifdef __cplusplus #ifdef __cplusplus
} }

@ -36,6 +36,8 @@ extern "C" {
DFHACK_EXPORT int Maps_Start(DFHackObject* maps); DFHACK_EXPORT int Maps_Start(DFHackObject* maps);
DFHACK_EXPORT int Maps_Finish(DFHackObject* maps); DFHACK_EXPORT int Maps_Finish(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); DFHACK_EXPORT void Maps_getSize(DFHackObject* maps, uint32_t* x, uint32_t* y, uint32_t* z);
DFHACK_EXPORT int Maps_isValidBlock(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z); DFHACK_EXPORT int Maps_isValidBlock(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z);

@ -44,6 +44,7 @@ DFHACK_EXPORT int Materials_ReadOthers(DFHackObject* mat);
DFHACK_EXPORT void Materials_ReadAllMaterials(DFHackObject* mat); DFHACK_EXPORT void Materials_ReadAllMaterials(DFHackObject* mat);
DFHACK_EXPORT const char* Materials_getType(DFHackObject* mat, t_material* material);
DFHACK_EXPORT const char* Materials_getDescription(DFHackObject* mat, t_material* material); DFHACK_EXPORT const char* Materials_getDescription(DFHackObject* mat, t_material* material);
DFHACK_EXPORT int Materials_getInorganicSize(DFHackObject* mat); DFHACK_EXPORT int Materials_getInorganicSize(DFHackObject* mat);

@ -38,8 +38,12 @@ DFHACK_EXPORT int Position_setViewCoords(DFHackObject* pos, const int32_t x, con
DFHACK_EXPORT int Position_getCursorCoords(DFHackObject* pos, int32_t* x, int32_t* y, int32_t* z); DFHACK_EXPORT int Position_getCursorCoords(DFHackObject* pos, int32_t* x, int32_t* y, int32_t* z);
DFHACK_EXPORT int Position_setCursorCoords(DFHackObject* pos, const int32_t x, const int32_t y, const int32_t z); DFHACK_EXPORT int Position_setCursorCoords(DFHackObject* pos, const int32_t x, const int32_t y, const int32_t z);
DFHACK_EXPORT t_hotkey* Position_ReadHotkeys(DFHackObject* pos);
DFHACK_EXPORT int Position_getWindowSize(DFHackObject* pos, int32_t* width, int32_t* height); DFHACK_EXPORT int Position_getWindowSize(DFHackObject* pos, int32_t* width, int32_t* height);
DFHACK_EXPORT t_screen* Position_getScreenTiles(DFHackObject* pos, int32_t width, int32_t height);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

@ -60,8 +60,6 @@ int Gui_ReadPauseState(DFHackObject* gui)
int Gui_ReadViewScreen(DFHackObject* gui, t_viewscreen* viewscreen) int Gui_ReadViewScreen(DFHackObject* gui, t_viewscreen* viewscreen)
{ {
//int result;
if(gui != NULL) if(gui != NULL)
{ {
return ((DFHack::Gui*)gui)->ReadViewScreen(*viewscreen); return ((DFHack::Gui*)gui)->ReadViewScreen(*viewscreen);
@ -70,6 +68,18 @@ int Gui_ReadViewScreen(DFHackObject* gui, t_viewscreen* viewscreen)
return -1; return -1;
} }
int Gui_ReadMenuState(DFHackObject* gui, uint32_t* menuState)
{
if(gui != NULL)
{
*menuState = ((DFHack::Gui*)gui)->ReadMenuState();
return 1;
}
return -1;
}
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

@ -54,6 +54,37 @@ int Maps_Finish(DFHackObject* maps)
return -1; return -1;
} }
t_feature* Maps_ReadGlobalFeatures(DFHackObject* maps)
{
if(maps != NULL)
{
std::vector<t_feature> featureVec;
if(((DFHack::Maps*)maps)->ReadGlobalFeatures(featureVec))
{
if(featureVec.size() <= 0)
return NULL;
t_feature* buf;
(*alloc_t_feature_buffer_callback)(buf, featureVec.size());
if(buf != NULL)
{
copy(featureVec.begin(), featureVec.end(), buf);
return buf;
}
else
return NULL;
}
else
return NULL;
}
return NULL;
}
void Maps_getSize(DFHackObject* maps, uint32_t* x, uint32_t* y, uint32_t* z) void Maps_getSize(DFHackObject* maps, uint32_t* x, uint32_t* y, uint32_t* z)
{ {
if(maps != NULL) if(maps != NULL)

@ -116,6 +116,18 @@ void Materials_ReadAllMaterials(DFHackObject* mat)
} }
} }
const char* Materials_getType(DFHackObject* mat, t_material* material)
{
if(mat != NULL)
{
std::string type = ((DFHack::Materials*)mat)->getType(*material);
return type.c_str();
}
return "\0";
}
const char* Materials_getDescription(DFHackObject* mat, t_material* material) const char* Materials_getDescription(DFHackObject* mat, t_material* material)
{ {
if(mat != NULL) if(mat != NULL)

@ -22,6 +22,7 @@ must not be misrepresented as being the original software.
distribution. distribution.
*/ */
#include "dfhack-c/DFTypes_C.h"
#include "dfhack-c/modules/Position_C.h" #include "dfhack-c/modules/Position_C.h"
#ifdef __cplusplus #ifdef __cplusplus
@ -97,6 +98,28 @@ int Position_setCursorCoords(DFHackObject* pos, int32_t x, int32_t y, int32_t z)
return -1; return -1;
} }
t_hotkey* Position_ReadHotkeys(DFHackObject* pos)
{
if(pos != NULL)
{
t_hotkey* buf;
(*alloc_t_hotkey_buffer_callback)(buf, NUM_HOTKEYS);
if(buf != NULL)
{
if(((DFHack::Position*)pos)->ReadHotkeys(buf))
return buf;
else
return NULL;
}
else
return NULL;
}
return NULL;
}
int Position_getWindowSize(DFHackObject* pos, int32_t* width, int32_t* height) int Position_getWindowSize(DFHackObject* pos, int32_t* width, int32_t* height)
{ {
if(pos != NULL) if(pos != NULL)
@ -117,6 +140,26 @@ int Position_getWindowSize(DFHackObject* pos, int32_t* width, int32_t* height)
return -1; return -1;
} }
t_screen* Position_getScreenTiles(DFHackObject* pos, int32_t width, int32_t height)
{
if(pos != NULL)
{
t_screen* buf;
(*alloc_t_screen_buffer_callback)(buf, width * height);
if(buf == NULL)
return NULL;
if(((DFHack::Position*)pos)->getScreenTiles(width, height, buf))
return buf;
else
return NULL;
}
return NULL;
}
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif