From d95ea2c006224202fafafcd04051f4eb3fb16068 Mon Sep 17 00:00:00 2001 From: doomchild Date: Fri, 30 Apr 2010 15:24:49 -0500 Subject: [PATCH 1/7] first commit --- dfhack/DFHackAPI_C.cpp | 83 ++++++++++++++++++++++++++++++++++++ dfhack/include/DFHackAPI_C.h | 52 ++++++++++++++++++++++ 2 files changed, 135 insertions(+) create mode 100644 dfhack/DFHackAPI_C.cpp create mode 100644 dfhack/include/DFHackAPI_C.h diff --git a/dfhack/DFHackAPI_C.cpp b/dfhack/DFHackAPI_C.cpp new file mode 100644 index 000000000..2c07e4d2e --- /dev/null +++ b/dfhack/DFHackAPI_C.cpp @@ -0,0 +1,83 @@ +/* +www.sourceforge.net/projects/dfhack +Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any +damages arising from the use of this software. + +Permission is granted to anyone to use this software for any +purpose, including commercial applications, and to alter it and +redistribute it freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must +not claim that you wrote the original software. If you use this +software in a product, an acknowledgment in the product documentation +would be appreciated but is not required. + +2. Altered source versions must be plainly marked as such, and +must not be misrepresented as being the original software. + +3. This notice may not be removed or altered from any source +distribution. +*/ + +#include "Tranquility.h" +#include "Export.h" +#include +#include +#include +#include "integers.h" +#include "DFTileTypes.h" +#include "DFTypes.h" +#include "DFWindow.h" +#include "DFHackAPI.h" + +using namespace std; +using namespace DFHack; + +#include "DFHackAPI_C.h" + +#ifdef __cplusplus +extern "C" { +#endif + +DFHackObject* API_Alloc(const char* path_to_xml) +{ + DFHack::API* api = new DFHack::API(std::string(path_to_xml)); + return (DFHackObject*)api; +} + +/* + +void API_Free(DFHackObject* api) +{ + if(api != NULL) + { + delete api; + api = NULL; + } +} + +bool API_Attach(DFHackObject* api) +{ + if(api != NULL) + return ((DFHack::API*)api)->Attach(); +} + +bool API_Detach(DFHackObject* api) +{ + if(api != NULL) + return ((DFHack::API*)api)->Detach(); +} + +bool API_isAttached(DFHackObject* api) +{ + if(api != NULL) + return ((DFHack::API*)api)->isAttached(); +} +*/ + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/dfhack/include/DFHackAPI_C.h b/dfhack/include/DFHackAPI_C.h new file mode 100644 index 000000000..f02d91d28 --- /dev/null +++ b/dfhack/include/DFHackAPI_C.h @@ -0,0 +1,52 @@ +/* +www.sourceforge.net/projects/dfhack +Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any +damages arising from the use of this software. + +Permission is granted to anyone to use this software for any +purpose, including commercial applications, and to alter it and +redistribute it freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must +not claim that you wrote the original software. If you use this +software in a product, an acknowledgment in the product documentation +would be appreciated but is not required. + +2. Altered source versions must be plainly marked as such, and +must not be misrepresented as being the original software. + +3. This notice may not be removed or altered from any source +distribution. +*/ + +#ifndef DFHACK_C_API +#define DFHACK_C_API + +typedef void DFHackObject; + +#ifdef __cplusplus +extern "C" { +#endif + +__declspec(dllexport) DFHackObject* API_Alloc(const char* path_to_xml); +/* +static void API_Free(DFHackObject* api); + +static bool API_Attach(DFHackObject* api); +static bool API_Detach(DFHackObject* api); +static bool API_isAttached(DFHackObject* api); + +static bool API_Suspend(DFHackObject* api); +static bool API_Resume(DFHackObject* api); +static bool API_isSuspended(DFHackObject* api); +static bool API_ForceResume(DFHackObject* api); +*/ + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file From 39ab2cd8ec00f7a5186b156dfbcad7d9bb5ac7dd Mon Sep 17 00:00:00 2001 From: doomchild Date: Fri, 30 Apr 2010 15:25:12 -0500 Subject: [PATCH 2/7] added C api to make lists --- dfhack/CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dfhack/CMakeLists.txt b/dfhack/CMakeLists.txt index 8bb09e992..a1a56a5ea 100644 --- a/dfhack/CMakeLists.txt +++ b/dfhack/CMakeLists.txt @@ -12,6 +12,7 @@ include/DFTileTypes.h include/DFTypes.h include/DFVector.h include/DFWindow.h +include/DFHackAPI_C.h include/integers.h shm/shms.h ) @@ -23,6 +24,7 @@ DFHackAPI.cpp APIPrivate.cpp DFTileTypes.cpp DFVector.cpp +DFHackAPI_C.cpp depends/md5/md5.cpp depends/md5/md5wrapper.cpp @@ -91,7 +93,7 @@ ENDIF( CMAKE_SIZEOF_VOID_P MATCHES 4 ) CONFIGURE_FILE( ${CMAKE_SOURCE_DIR}/dfhack/config.h.cmake ${CMAKE_SOURCE_DIR}/dfhack/include/config.h ) - +ADD_DEFINITIONS(-DBUILD_DFHACK_LIB) IF(UNIX) add_definitions(-DLINUX_BUILD) From 4166f1e1946edcb409caf283f9ff8625b5aea5ad Mon Sep 17 00:00:00 2001 From: doomchild Date: Fri, 30 Apr 2010 16:01:29 -0500 Subject: [PATCH 3/7] added EXPORT definition, because I'm lazy and don't like typing __declspec(dllexport) everywhere --- dfhack/include/Export.h | 2 + dfhack/include/modules/Position_C.h | 48 +++++++++++ dfhack/modules/Position_C.cpp | 127 ++++++++++++++++++++++++++++ 3 files changed, 177 insertions(+) create mode 100644 dfhack/include/modules/Position_C.h create mode 100644 dfhack/modules/Position_C.cpp diff --git a/dfhack/include/Export.h b/dfhack/include/Export.h index 820c046ab..a3984c372 100644 --- a/dfhack/include/Export.h +++ b/dfhack/include/Export.h @@ -41,3 +41,5 @@ distribution. #endif #endif #endif + +#define EXPORT __declspec(dllexport) diff --git a/dfhack/include/modules/Position_C.h b/dfhack/include/modules/Position_C.h new file mode 100644 index 000000000..4879116c8 --- /dev/null +++ b/dfhack/include/modules/Position_C.h @@ -0,0 +1,48 @@ +/* +www.sourceforge.net/projects/dfhack +Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any +damages arising from the use of this software. + +Permission is granted to anyone to use this software for any +purpose, including commercial applications, and to alter it and +redistribute it freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must +not claim that you wrote the original software. If you use this +software in a product, an acknowledgment in the product documentation +would be appreciated but is not required. + +2. Altered source versions must be plainly marked as such, and +must not be misrepresented as being the original software. + +3. This notice may not be removed or altered from any source +distribution. +*/ + +#ifndef POSITION_C_API +#define POSITION_C_API + +#include "Export.h" + +#include "DFHackAPI_C.h" + +#ifdef __cplusplus +extern "C" { +#endif + +EXPORT int Position_getViewCoords(DFHackObject* pos, int32_t* x, int32_t* y, int32_t* z); +EXPORT int Position_setViewCoords(DFHackObject* pos, const int32_t x, const int32_t y, const int32_t z); + +EXPORT int Position_getCursorCoords(DFHackObject* pos, int32_t* x, int32_t* y, int32_t* z); +EXPORT int Position_setCursorCoords(DFHackObject* pos, const int32_t x, const int32_t y, const int32_t z); + +EXPORT int Position_getWindowSize(DFHackObject* pos, int32_t* width, int32_t* height); + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/dfhack/modules/Position_C.cpp b/dfhack/modules/Position_C.cpp new file mode 100644 index 000000000..2c38e8be5 --- /dev/null +++ b/dfhack/modules/Position_C.cpp @@ -0,0 +1,127 @@ +/* +www.sourceforge.net/projects/dfhack +Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any +damages arising from the use of this software. + +Permission is granted to anyone to use this software for any +purpose, including commercial applications, and to alter it and +redistribute it freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must +not claim that you wrote the original software. If you use this +software in a product, an acknowledgment in the product documentation +would be appreciated but is not required. + +2. Altered source versions must be plainly marked as such, and +must not be misrepresented as being the original software. + +3. This notice may not be removed or altered from any source +distribution. +*/ + +#include "modules/Position_C.h" +#include "integers.h" + +#include "modules/Position.h" + +using namespace DFHack; + +#ifdef __cplusplus +extern "C" { +#endif + +int Position_getViewCoords(DFHackObject* pos, int32_t* x, int32_t* y, int32_t* z) +{ + if(pos != 0) + { + int32_t tx, ty, tz; + + if(((DFHack::Position*)pos)->getViewCoords(tx, ty, tz)) + { + *x = tx; + *y = ty; + *z = tz; + + return 1; + } + else + return 0; + } + + return -1; +} + +int Position_setViewCoords(DFHackObject* pos, int32_t x, int32_t y, int32_t z) +{ + if(pos != 0) + { + if(((DFHack::Position*)pos)->setViewCoords(x, y, z)) + return 1; + else + return 0; + } + + return -1; +} + + +int Position_getCursorCoords(DFHackObject* pos, int32_t* x, int32_t* y, int32_t* z) +{ + if(pos != 0) + { + int32_t tx, ty, tz; + + if(((DFHack::Position*)pos)->getCursorCoords(tx, ty, tz)) + { + *x = tx; + *y = ty; + *z = tz; + + return 1; + } + else + return 0; + } + + return -1; +} + +int Position_setCursorCoords(DFHackObject* pos, int32_t x, int32_t y, int32_t z) +{ + if(pos != 0) + { + if(((DFHack::Position*)pos)->setCursorCoords(x, y, z)) + return 1; + else + return 0; + } + + return -1; +} + +int Position_getWindowSize(DFHackObject* pos, int32_t* width, int32_t* height) +{ + if(pos != 0) + { + int32_t tw, th; + + if(((DFHack::Position*)pos)->getWindowSize(tw, th)) + { + *width = tw; + *height = th; + + return 1; + } + else + return 0; + } + + return -1; +} + +#ifdef __cplusplus +} +#endif \ No newline at end of file From 08a897f0861cfa711e8fdec91243e4a07ec8c3b9 Mon Sep 17 00:00:00 2001 From: doomchild Date: Fri, 30 Apr 2010 16:01:40 -0500 Subject: [PATCH 4/7] using integers.h now --- dfhack/include/DFHackAPI_C.h | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/dfhack/include/DFHackAPI_C.h b/dfhack/include/DFHackAPI_C.h index f02d91d28..64408fa84 100644 --- a/dfhack/include/DFHackAPI_C.h +++ b/dfhack/include/DFHackAPI_C.h @@ -25,25 +25,30 @@ distribution. #ifndef DFHACK_C_API #define DFHACK_C_API +#include "Export.h" +#include "integers.h" + typedef void DFHackObject; #ifdef __cplusplus extern "C" { #endif -__declspec(dllexport) DFHackObject* API_Alloc(const char* path_to_xml); -/* -static void API_Free(DFHackObject* api); +EXPORT DFHackObject* API_Alloc(const char* path_to_xml); +EXPORT void API_Free(DFHackObject* api); -static bool API_Attach(DFHackObject* api); -static bool API_Detach(DFHackObject* api); -static bool API_isAttached(DFHackObject* api); +EXPORT int API_Attach(DFHackObject* api); +EXPORT int API_Detach(DFHackObject* api); +EXPORT int API_isAttached(DFHackObject* api); -static bool API_Suspend(DFHackObject* api); -static bool API_Resume(DFHackObject* api); -static bool API_isSuspended(DFHackObject* api); -static bool API_ForceResume(DFHackObject* api); -*/ +EXPORT int API_Suspend(DFHackObject* api); +EXPORT int API_Resume(DFHackObject* api); +EXPORT int API_isSuspended(DFHackObject* api); +EXPORT int API_ForceResume(DFHackObject* api); +EXPORT int API_AsyncSuspend(DFHackObject* api); + +EXPORT void API_ReadRaw(DFHackObject* api, const uint32_t offset, const uint32_t size, uint8_t* target); +EXPORT void API_WriteRaw(DFHackObject* api, const uint32_t offset, const uint32_t size, uint8_t* source); #ifdef __cplusplus } From d750e30612390cd85cb8877397591d933b644c2b Mon Sep 17 00:00:00 2001 From: doomchild Date: Fri, 30 Apr 2010 16:03:37 -0500 Subject: [PATCH 5/7] now using DFCommonInternal.h --- dfhack/modules/Position_C.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/dfhack/modules/Position_C.cpp b/dfhack/modules/Position_C.cpp index 2c38e8be5..ef274c930 100644 --- a/dfhack/modules/Position_C.cpp +++ b/dfhack/modules/Position_C.cpp @@ -25,6 +25,7 @@ distribution. #include "modules/Position_C.h" #include "integers.h" +#include "DFCommonInternal.h" #include "modules/Position.h" using namespace DFHack; @@ -35,7 +36,7 @@ extern "C" { int Position_getViewCoords(DFHackObject* pos, int32_t* x, int32_t* y, int32_t* z) { - if(pos != 0) + if(pos != NULL) { int32_t tx, ty, tz; @@ -56,7 +57,7 @@ int Position_getViewCoords(DFHackObject* pos, int32_t* x, int32_t* y, int32_t* z int Position_setViewCoords(DFHackObject* pos, int32_t x, int32_t y, int32_t z) { - if(pos != 0) + if(pos != NULL) { if(((DFHack::Position*)pos)->setViewCoords(x, y, z)) return 1; @@ -70,7 +71,7 @@ int Position_setViewCoords(DFHackObject* pos, int32_t x, int32_t y, int32_t z) int Position_getCursorCoords(DFHackObject* pos, int32_t* x, int32_t* y, int32_t* z) { - if(pos != 0) + if(pos != NULL) { int32_t tx, ty, tz; @@ -91,7 +92,7 @@ int Position_getCursorCoords(DFHackObject* pos, int32_t* x, int32_t* y, int32_t* int Position_setCursorCoords(DFHackObject* pos, int32_t x, int32_t y, int32_t z) { - if(pos != 0) + if(pos != NULL) { if(((DFHack::Position*)pos)->setCursorCoords(x, y, z)) return 1; @@ -104,7 +105,7 @@ int Position_setCursorCoords(DFHackObject* pos, int32_t x, int32_t y, int32_t z) int Position_getWindowSize(DFHackObject* pos, int32_t* width, int32_t* height) { - if(pos != 0) + if(pos != NULL) { int32_t tw, th; From 177bbf30c0a579f753b2e5f375b3e890b8581f4b Mon Sep 17 00:00:00 2001 From: doomchild Date: Fri, 30 Apr 2010 16:04:05 -0500 Subject: [PATCH 6/7] added ReadRaw/WriteRaw --- dfhack/DFHackAPI_C.cpp | 117 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 108 insertions(+), 9 deletions(-) diff --git a/dfhack/DFHackAPI_C.cpp b/dfhack/DFHackAPI_C.cpp index 2c07e4d2e..81847c419 100644 --- a/dfhack/DFHackAPI_C.cpp +++ b/dfhack/DFHackAPI_C.cpp @@ -48,8 +48,6 @@ DFHackObject* API_Alloc(const char* path_to_xml) return (DFHackObject*)api; } -/* - void API_Free(DFHackObject* api) { if(api != NULL) @@ -59,24 +57,125 @@ void API_Free(DFHackObject* api) } } -bool API_Attach(DFHackObject* api) +int API_Attach(DFHackObject* api) { if(api != NULL) - return ((DFHack::API*)api)->Attach(); + { + if(((DFHack::API*)api)->Attach()) + return 1; + else + return 0; + } + + return -1; } -bool API_Detach(DFHackObject* api) +int API_Detach(DFHackObject* api) { if(api != NULL) - return ((DFHack::API*)api)->Detach(); + { + if(((DFHack::API*)api)->Detach()) + return 1; + else + return 0; + } + + return -1; } -bool API_isAttached(DFHackObject* api) +int API_isAttached(DFHackObject* api) { if(api != NULL) - return ((DFHack::API*)api)->isAttached(); + { + if(((DFHack::API*)api)->isAttached()) + return 1; + else + return 0; + } + + return -1; +} + +int API_Suspend(DFHackObject* api) +{ + if(api != NULL) + { + if(((DFHack::API*)api)->Suspend()) + return 1; + else + return 0; + } + + return -1; +} + +int API_Resume(DFHackObject* api) +{ + if(api != NULL) + { + if(((DFHack::API*)api)->Resume()) + return 1; + else + return 0; + } + + return -1; +} + +int API_isSuspended(DFHackObject* api) +{ + if(api != NULL) + { + if(((DFHack::API*)api)->isSuspended()) + return 1; + else + return 0; + } + + return -1; +} + +int API_ForceResume(DFHackObject* api) +{ + if(api != NULL) + { + if(((DFHack::API*)api)->ForceResume()) + return 1; + else + return 0; + } + + return -1; +} + +int API_AsyncSuspend(DFHackObject* api) +{ + if(api != NULL) + { + if(((DFHack::API*)api)->AsyncSuspend()) + return 1; + else + return 0; + } + + return -1; +} + +void API_ReadRaw(DFHackObject* api, const uint32_t offset, const uint32_t size, uint8_t* target) +{ + if(api != NULL) + { + ((DFHack::API*)api)->ReadRaw(offset, size, target); + } +} + +void API_WriteRaw(DFHackObject* api, const uint32_t offset, const uint32_t size, uint8_t* source) +{ + if(api != NULL) + { + ((DFHack::API*)api)->WriteRaw(offset, size, source); + } } -*/ #ifdef __cplusplus } From ed6596107108dd10b478bac7032412b80dae622e Mon Sep 17 00:00:00 2001 From: doomchild Date: Fri, 30 Apr 2010 16:04:17 -0500 Subject: [PATCH 7/7] added Position_C.cpp to build list --- dfhack/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dfhack/CMakeLists.txt b/dfhack/CMakeLists.txt index a1a56a5ea..a652e6554 100644 --- a/dfhack/CMakeLists.txt +++ b/dfhack/CMakeLists.txt @@ -43,6 +43,8 @@ modules/Translation.cpp modules/Vegetation.cpp modules/Buildings.cpp modules/Constructions.cpp + +modules/Position_C.cpp ) SET(PROJECT_HDRS_LINUX