cursor and window coords reading and writing (only for 40d16 on windows right now)

develop
Petr Mrázek 2009-11-12 01:39:43 +00:00
parent e8e3f9e794
commit 30d8a015fd
4 changed files with 74 additions and 20 deletions

@ -1105,8 +1105,8 @@ bool API::InitViewAndCursor()
{ {
d->window_x_offset = d->offset_descriptor->getAddress("window_x"); d->window_x_offset = d->offset_descriptor->getAddress("window_x");
d->window_y_offset = d->offset_descriptor->getAddress("window_x"); d->window_y_offset = d->offset_descriptor->getAddress("window_y");
d->window_z_offset = d->offset_descriptor->getAddress("window_x"); d->window_z_offset = d->offset_descriptor->getAddress("window_z");
d->cursor_xyz_offset = d->offset_descriptor->getAddress("cursor_xyz"); d->cursor_xyz_offset = d->offset_descriptor->getAddress("cursor_xyz");
if(d->window_x_offset && d->window_y_offset && d->window_z_offset) if(d->window_x_offset && d->window_y_offset && d->window_z_offset)
{ {
@ -1119,35 +1119,40 @@ bool API::InitViewAndCursor()
} }
} }
void API::getViewCoords (uint32_t &x, uint32_t &y, uint32_t &z) bool API::getViewCoords (int32_t &x, int32_t &y, int32_t &z)
{ {
assert(d->cursorWindowInited); assert(d->cursorWindowInited);
MreadDWord(d->window_x_offset,x); MreadDWord(d->window_x_offset,(uint32_t &)x);
MreadDWord(d->window_y_offset,y); MreadDWord(d->window_y_offset,(uint32_t &)y);
MreadDWord(d->window_z_offset,z); MreadDWord(d->window_z_offset,(uint32_t &)z);
return true;
} }
//FIXME: confine writing of coords to map bounds? //FIXME: confine writing of coords to map bounds?
void API::setViewCoords (const uint32_t &x, const uint32_t &y, const uint32_t &z) bool API::setViewCoords (const int32_t &x, const int32_t &y, const int32_t &z)
{ {
assert(d->cursorWindowInited); assert(d->cursorWindowInited);
MwriteDWord(d->window_x_offset,x); MwriteDWord(d->window_x_offset,(uint32_t &)x);
MwriteDWord(d->window_y_offset,y); MwriteDWord(d->window_y_offset,(uint32_t &)y);
MwriteDWord(d->window_z_offset,z); MwriteDWord(d->window_z_offset,(uint32_t &)z);
return true;
} }
void API::getCursorCoords (uint32_t &x, uint32_t &y, uint32_t &z) bool API::getCursorCoords (int32_t &x, int32_t &y, int32_t &z)
{ {
assert(d->cursorWindowInited); assert(d->cursorWindowInited);
uint32_t coords[3]; int32_t coords[3];
Mread(d->cursor_xyz_offset,3*sizeof(uint32_t),(uint8_t *)coords); Mread(d->cursor_xyz_offset,3*sizeof(int32_t),(uint8_t *)coords);
x = coords[0]; x = coords[0];
y = coords[1]; y = coords[1];
z = coords[2]; z = coords[2];
if(x == -30000) return false;
return true;
} }
//FIXME: confine writing of coords to map bounds? //FIXME: confine writing of coords to map bounds?
void API::setCursorCoords (const uint32_t &x, const uint32_t &y, const uint32_t &z) bool API::setCursorCoords (const int32_t &x, const int32_t &y, const int32_t &z)
{ {
assert(d->cursorWindowInited); assert(d->cursorWindowInited);
uint32_t coords[3] = {x,y,z}; int32_t coords[3] = {x,y,z};
Mwrite(d->cursor_xyz_offset,3*sizeof(uint32_t),(uint8_t *)coords); Mwrite(d->cursor_xyz_offset,3*sizeof(int32_t),(uint8_t *)coords);
return true;
} }

@ -175,11 +175,11 @@ public:
bool InitViewAndCursor(); bool InitViewAndCursor();
void getViewCoords (uint32_t &x, uint32_t &y, uint32_t &z); bool getViewCoords (int32_t &x, int32_t &y, int32_t &z);
void setViewCoords (const uint32_t &x, const uint32_t &y, const uint32_t &z); bool setViewCoords (const int32_t &x, const int32_t &y, const int32_t &z);
void getCursorCoords (uint32_t &x, uint32_t &y, uint32_t &z); bool getCursorCoords (int32_t &x, int32_t &y, int32_t &z);
void setCursorCoords (const uint32_t &x, const uint32_t &y, const uint32_t &z); bool setCursorCoords (const int32_t &x, const int32_t &y, const int32_t &z);
}; };
} // namespace DFHack } // namespace DFHack

@ -38,6 +38,9 @@ TARGET_LINK_LIBRARIES(dfattachtest dfhack)
ADD_EXECUTABLE(dfmaterialtest materialtest.cpp) ADD_EXECUTABLE(dfmaterialtest materialtest.cpp)
TARGET_LINK_LIBRARIES(dfmaterialtest dfhack) TARGET_LINK_LIBRARIES(dfmaterialtest dfhack)
# materialtest - just list the first material of each type
ADD_EXECUTABLE(dfposition position.cpp)
TARGET_LINK_LIBRARIES(dfposition dfhack)
IF(UNIX) IF(UNIX)
install(TARGETS install(TARGETS
@ -50,6 +53,7 @@ dfcreaturedump
dfattachtest dfattachtest
dfmaterialtest dfmaterialtest
dfbuildingsdump dfbuildingsdump
dfposition
RUNTIME DESTINATION bin RUNTIME DESTINATION bin
) )

@ -0,0 +1,45 @@
// Just show some position data
#include <iostream>
#include <climits>
#include <integers.h>
#include <vector>
#include <ctime>
using namespace std;
#include <DFTypes.h>
#include <DFHackAPI.h>
int main (void)
{
DFHack::API DF("Memory.xml");
if(!DF.Attach())
{
cerr << "DF not found" << endl;
return 1;
}
if (DF.InitViewAndCursor())
{
int32_t x,y,z;
if(DF.getViewCoords(x,y,z))
cout << "view coords: " << x << "/" << y << "/" << z << endl;
if(DF.getCursorCoords(x,y,z))
cout << "cursor coords: " << x << "/" << y << "/" << z << endl;
}
else
{
cerr << "cursor and window parameters are unsupported on your version of DF" << endl;
}
if(!DF.Detach())
{
cerr << "Can't detach from DF" << endl;
return 1;
}
#ifndef LINUX_BUILD
cout << "Done. Press any key to continue" << endl;
cin.ignore();
#endif
return 0;
}