Merge branch 'master' of git://github.com/peterix/dfhack into errorhandling

develop
mizipzor 2010-02-28 05:52:48 +01:00
commit c13e37adf6
7 changed files with 108 additions and 53 deletions

@ -23,6 +23,7 @@ SET(SO_VERSION "${SO_MAJOR_VERSION}.${SO_MINOR_VERSION}.${SO_BUILD_VERSION}")
SET( LIBRARY_OUTPUT_PATH ${dfhack_SOURCE_DIR}/output CACHE PATH "Output directory for the dfhack library" )
SET( EXECUTABLE_OUTPUT_PATH ${dfhack_SOURCE_DIR}/output CACHE PATH "Output directory for the dfhack tools" )
SET( CMAKE_SWIG_OUTDIR ${dfhack_SOURCE_DIR}/output CACHE PATH "Global output directory for swig generated language wrappers" )
include_directories (${CMAKE_SOURCE_DIR}/library/)
include_directories (${CMAKE_SOURCE_DIR}/shmserver/)

@ -30,6 +30,7 @@ DFMemInfo.cpp
DFMemInfoManager.cpp
DFHackAPI.cpp
DFTileTypes.cpp
DFVector.cpp
md5/md5.cpp
md5/md5wrapper.cpp
tinyxml/tinystr.cpp
@ -105,4 +106,19 @@ IF(UNIX)
install(FILES ${CMAKE_SOURCE_DIR}/output/Memory.xml DESTINATION share/dfhack)
ENDIF(UNIX)
#install(TARGETS mySharedLib DESTINATION /some/full/path)
# SWIG stuff
FIND_PACKAGE(SWIG)
IF(SWIG_FOUND)
INCLUDE(${SWIG_USE_FILE})
FIND_PACKAGE(PythonLibs)
IF(PYTHONLIBS_FOUND)
INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH})
SET(CMAKE_SWIG_FLAGS "-c++")
SET_SOURCE_FILES_PROPERTIES(pydfhack.i PROPERTIES CPLUSPLUS ON)
# SET(CMAKE_DFHACK_SWIG_OUTDIR ${dfhack_SOURCE_DIR}/output CACHE PATH "Directory where Java wrapped libraries will be saved.")
# SET_SOURCE_FILES_PROPERTIES(pydfhack.i PROPERTIES SWIG_FLAGS "-includeall")
SWIG_ADD_MODULE(pydfhack python pydfhack.i)
SWIG_LINK_LIBRARIES(pydfhack ${PYTHON_LIBRARIES} dfhack)
ENDIF(PYTHONLIBS_FOUND)
ENDIF(SWIG_FOUND)

@ -25,6 +25,7 @@ distribution.
#ifndef ERROR_H_INCLUDED
#define ERROR_H_INCLUDED
#include "Export.h"
#include <string>
#include <sstream>
#include <exception>
@ -33,7 +34,7 @@ namespace DFHack
{
namespace Error
{
class NoProcess : public exception
class DFHACK_EXPORT NoProcess : public std::exception
{
public:
virtual const char* what() const throw()
@ -42,7 +43,7 @@ namespace DFHack
}
};
class CantAttach : public exception
class DFHACK_EXPORT CantAttach : public std::exception
{
public:
virtual const char* what() const throw()
@ -51,7 +52,7 @@ namespace DFHack
}
};
class NoMapLoaded : public exception
class DFHACK_EXPORT NoMapLoaded : public std::exception
{
public:
virtual const char* what() const throw()
@ -60,7 +61,7 @@ namespace DFHack
}
};
class BadMapDimensions : public exception
class DFHACK_EXPORT BadMapDimensions : public std::exception
{
public:
BadMapDimensions(uint32_t& _x, uint32_t& _y) : x(_x), y(_y) {}
@ -74,7 +75,7 @@ namespace DFHack
};
// a call to DFHack::mem_info::get* failed
class MissingMemoryDefinition : public exception
class DFHACK_EXPORT MissingMemoryDefinition : public std::exception
{
public:
MissingMemoryDefinition(const char* _type, const char* _key) : type(_type), key(_key) {}
@ -86,6 +87,8 @@ namespace DFHack
s << _key;
key = s.str();
}
virtual ~MissingMemoryDefinition() throw()
{};
// (perhaps it should be an enum, but this is intended for easy printing/logging)
// type can be any of the following:

@ -0,0 +1,44 @@
/*
www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
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 "DFCommonInternal.h"
using namespace DFHack;
DfVector::DfVector(uint32_t _start, uint32_t _size, uint32_t _item_size): start(_start),size(_size),item_size(_item_size)
{
data = (uint8_t *) new char[size * item_size];
g_pProcess->read(start,size*item_size, (uint8_t *)data);
};
DfVector::DfVector()
{
data = 0;
};
DfVector::~DfVector()
{
if(data)
delete [] data;
};

@ -26,10 +26,11 @@ distribution.
#define DFVECTOR_H_INCLUDED
#include "Tranquility.h"
#include "Export.h"
namespace DFHack
{
class DfVector
class DFHACK_EXPORT DfVector
{
private:
// starting offset
@ -40,40 +41,20 @@ namespace DFHack
uint8_t* data;
public:
DfVector()
{
data = 0;
};
DfVector(uint32_t _start, uint32_t _size, uint32_t _item_size):
start(_start),size(_size),item_size(_item_size)
{
data = (uint8_t *) new char[size * item_size];
g_pProcess->read(start,size*item_size, (uint8_t *)data);
};
/*
DfVector(const DfVector & vec)
{
start = vec.start;
size = vec.size;
item_size = vec.item_size;
data = (uint8_t *) new char[size * item_size];
memcpy(data,vec.data,item_size * size);
};*/
~DfVector()
{
if(data)
delete [] data;
}
DfVector();
DfVector(uint32_t _start, uint32_t _size, uint32_t _item_size);
~DfVector();
// get offset of the specified index
inline void* operator[] (uint32_t index)
{
assert(index < size);
// FIXME: vector out of bounds exception
//assert(index < size);
return data + index*item_size;
};
// get offset of the specified index
inline void* at (uint32_t index)
{
assert(index < size);
//assert(index < size);
return data + index*item_size;
};
// get vector size

@ -1,6 +1,7 @@
import dfhack
x = dfhack.API("Memory.xml")
y = dfhack.MatglossVector()
# -*- coding: utf-8 -*-
import pydfhack
x = pydfhack.API("Memory.xml")
y = pydfhack.MatglossVector()
if x.Attach():
success,stones = x.ReadStoneMatgloss()

@ -5,10 +5,28 @@ Author: Alex Legg
Based on code from and uses DFHack - www.sourceforge.net/projects/dfhack
*/
#include "DFCommonInternal.h"
//#include <DFCommonInternal.h>
#include <sstream>
#include <iostream>
#include <string.h>
#include <cstdlib>
#include <assert.h>
#include <string>
#include <vector>
using namespace std;
#include <integers.h>
#include <Export.h>
#include <DFError.h>
#include <DFVector.h>
#include <DFMemInfo.h>
#include <DFProcess.h>
#include <DFTypes.h>
#include <DFHackAPI.h>
using namespace DFHack;
int main ()
{
DFHack::Process *proc;
@ -32,9 +50,7 @@ int main ()
DF.Suspend();
/*
* Find out which material is bauxite
*/
// Find out which material is bauxite
if(!DF.ReadStoneMatgloss(stoneMat))
{
cout << "Materials not supported for this version of DF, exiting." << endl;
@ -63,23 +79,15 @@ int main ()
return EXIT_FAILURE;
}
/*
* Get some basics needed for full access
*/
// Get some basics needed for full access
proc = DF.getProcess();
meminfo = proc->getDescriptor();
/*
* Get the object name/ID mapping
*/
/*
vector <string> objecttypes;
DF.getClassIDMapping (objecttypes);
*/
// Get the object name/ID mapping
//FIXME: work on the 'supported features' system required
/*
* Check availability of required addresses and offsets (doing custom stuff here)
*/
// Check availability of required addresses and offsets (doing custom stuff here)
items = meminfo->getAddress("items");
item_material_offset = meminfo->getOffset("item_materials");
if( !items || ! item_material_offset)
@ -145,5 +153,6 @@ int main ()
cout << "Done. Press any key to continue" << endl;
cin.ignore();
#endif
return 0;
}