Eliminated silly dependency cascade within the library. Some documentation tweaks.

develop
Petr Mrázek 2011-03-18 08:53:59 +01:00
parent 737643a33f
commit b94ddf50d0
26 changed files with 165 additions and 71 deletions

@ -6,18 +6,7 @@
#include "private/ContextShared.h" #include "private/ContextShared.h"
#include "dfhack/VersionInfo.h" #include "dfhack/VersionInfo.h"
#include "dfhack/DFProcess.h" #include "dfhack/DFProcess.h"
#include "dfhack/DFModule.h"
#include "dfhack/modules/Materials.h"
#include "dfhack/modules/Creatures.h"
#include "dfhack/modules/Maps.h"
#include "dfhack/modules/Position.h"
#include "dfhack/modules/Translation.h"
#include "dfhack/modules/Vegetation.h"
#include "dfhack/modules/Gui.h"
#include "dfhack/modules/World.h"
#include "dfhack/modules/Buildings.h"
#include "dfhack/modules/Constructions.h"
#include "dfhack/modules/WindowIO.h"
using namespace DFHack; using namespace DFHack;

@ -28,25 +28,14 @@ distribution.
#include "dfhack/DFProcessEnumerator.h" #include "dfhack/DFProcessEnumerator.h"
#include "dfhack/DFContext.h" #include "dfhack/DFContext.h"
#include "dfhack/DFError.h" #include "dfhack/DFError.h"
#include "dfhack/DFModule.h"
#include <shms.h> #include <shms.h>
#include <mod-core.h> #include <mod-core.h>
#include <mod-maps.h> #include <mod-maps.h>
#include <mod-creature40d.h> #include <mod-creature40d.h>
#include "private/ContextShared.h" #include "private/ContextShared.h"
#include "private/ModuleFactory.h"
#include "dfhack/modules/Maps.h"
#include "dfhack/modules/Materials.h"
#include "dfhack/modules/Items.h"
#include "dfhack/modules/Position.h"
#include "dfhack/modules/Gui.h"
#include "dfhack/modules/World.h"
#include "dfhack/modules/Creatures.h"
#include "dfhack/modules/Translation.h"
#include "dfhack/modules/Vegetation.h"
#include "dfhack/modules/Buildings.h"
#include "dfhack/modules/Constructions.h"
#include "dfhack/modules/WindowIO.h"
using namespace DFHack; using namespace DFHack;
@ -162,8 +151,9 @@ TYPE * Context::get##TYPE() \
{ \ { \
if(!d->s_mods.p##TYPE)\ if(!d->s_mods.p##TYPE)\
{\ {\
d->s_mods.p##TYPE = new TYPE(d);\ Module * mod = create##TYPE(d);\
d->allModules.push_back(d->s_mods.p##TYPE);\ d->s_mods.p##TYPE = (TYPE *) mod;\
d->allModules.push_back(mod);\
}\ }\
return d->s_mods.p##TYPE;\ return d->s_mods.p##TYPE;\
} }

@ -31,11 +31,6 @@ distribution.
#include "dfhack/DFContext.h" #include "dfhack/DFContext.h"
#include "dfhack/DFContextManager.h" #include "dfhack/DFContextManager.h"
#include <shms.h>
#include <mod-core.h>
#include <mod-maps.h>
#include <mod-creature40d.h>
#include "private/ContextShared.h" #include "private/ContextShared.h"
using namespace DFHack; using namespace DFHack;

@ -1,6 +1,12 @@
#ifndef DFHACK_API_H #ifndef DFHACK_API_H
#define DFHACK_API_H #define DFHACK_API_H
/**
* \defgroup grp_context Context and Process management
* \defgroup grp_modules DFHack Module classes
* \defgroup grp_cwrap C Wrapper
*/
// Defines // Defines
#ifdef __GNUC__ #ifdef __GNUC__
#define DEPRECATED(func) func __attribute__ ((deprecated)) #define DEPRECATED(func) func __attribute__ ((deprecated))

@ -1,4 +1,3 @@
/* /*
www.sourceforge.net/projects/dfhack www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
@ -44,17 +43,23 @@ namespace DFHack
class DFContextShared; class DFContextShared;
class WindowIO; class WindowIO;
class Process; class Process;
/**
* This class wraps all the different related objects for a particular Process
* \ingroup grp_context
*/
class DFHACK_EXPORT Context class DFHACK_EXPORT Context
{ {
public: public:
Context(Process * p); Context(Process * p);
~Context(); ~Context();
/// @return true if there's version information for the associated Process
bool isValid(); bool isValid();
/// attach to the related process. Claims OS debugging resources
bool Attach(); bool Attach();
/// detach from the related process. Releases OS debugging resources
bool Detach(); bool Detach();
/// @return true if the process is attached.
bool isAttached(); bool isAttached();
/// stop the tracked process /// stop the tracked process
@ -77,8 +82,6 @@ namespace DFHack
void ReadRaw (const uint32_t offset, const uint32_t size, uint8_t *target); void ReadRaw (const uint32_t offset, const uint32_t size, uint8_t *target);
void WriteRaw (const uint32_t offset, const uint32_t size, uint8_t *source); void WriteRaw (const uint32_t offset, const uint32_t size, uint8_t *source);
// FIXME: this is crap.
/// get the creatures module /// get the creatures module
Creatures * getCreatures(); Creatures * getCreatures();
@ -125,15 +128,6 @@ namespace DFHack
bool WriteEffect(const uint32_t index, const t_effect_df40d & effect); bool WriteEffect(const uint32_t index, const t_effect_df40d & effect);
void FinishReadEffects(); void FinishReadEffects();
*/ */
/*
* Trees and shrubs
*/
/*
bool InitReadVegetation( uint32_t & numplants );
bool ReadVegetation(const int32_t index, t_tree_desc & shrubbery);
void FinishReadVegetation();
*/
/* /*
* Notes placed by the player * Notes placed by the player
*/ */
@ -168,12 +162,6 @@ namespace DFHack
/* /*
* Get the other API parts for raw access * Get the other API parts for raw access
*/ */
/*
// FIXME: BAD!
bool ReadAllMatgloss(vector< vector< string > > & all);
*/
//bool ReadItemTypes(std::vector< std::vector< t_itemType > > & itemTypes);
private: private:
DFContextShared * d; DFContextShared * d;
}; };

@ -40,6 +40,7 @@ namespace DFHack
/** /**
* Used to enumerate, create and destroy Contexts. The very base of DFHack. * Used to enumerate, create and destroy Contexts. The very base of DFHack.
* @see DFHack::Context * @see DFHack::Context
* \ingroup grp_context
*/ */
class DFHACK_EXPORT ContextManager class DFHACK_EXPORT ContextManager
{ {
@ -95,6 +96,7 @@ namespace DFHack
* Class used for holding a set of invalidated Context AND Process objects temporarily and destroy them safely. * Class used for holding a set of invalidated Context AND Process objects temporarily and destroy them safely.
* @see DFHack::Context * @see DFHack::Context
* @see DFHack::Process * @see DFHack::Process
* \ingroup grp_context
*/ */
class DFHACK_EXPORT BadContexts class DFHACK_EXPORT BadContexts
{ {

@ -30,6 +30,10 @@ distribution.
namespace DFHack namespace DFHack
{ {
class Context; class Context;
/**
* The parent class for all DFHack modules
* \ingroup grp_modules
*/
class DFHACK_EXPORT Module class DFHACK_EXPORT Module
{ {
public: public:

@ -35,6 +35,10 @@ namespace DFHack
class Process; class Process;
class Window; class Window;
/**
* A type for storing an extended OS Process ID (combines PID and the time the process was started for unique identification)
* \ingroup grp_context
*/
struct ProcessID struct ProcessID
{ {
ProcessID(const uint64_t _time, const uint64_t _pid): time(_time), pid(_pid){}; ProcessID(const uint64_t _time, const uint64_t _pid): time(_time), pid(_pid){};
@ -54,7 +58,10 @@ namespace DFHack
uint64_t pid; uint64_t pid;
}; };
// structure describing a memory range /**
* Structure describing a section of virtual memory inside a process
* \ingroup grp_context
*/
struct DFHACK_EXPORT t_memrange struct DFHACK_EXPORT t_memrange
{ {
uint64_t start; uint64_t start;
@ -75,7 +82,10 @@ namespace DFHack
bool valid; bool valid;
uint8_t * buffer; uint8_t * buffer;
}; };
/**
* Allows low-level access to the memory of an OS process. OS processes can be enumerated by \ref ProcessEnumerator
* \ingroup grp_context
*/
class DFHACK_EXPORT Process class DFHACK_EXPORT Process
{ {
public: public:

@ -37,6 +37,7 @@ namespace DFHack
* Process enumerator * Process enumerator
* Used to enumerate, create and destroy Processes. * Used to enumerate, create and destroy Processes.
* @see DFHack::Process * @see DFHack::Process
* \ingroup grp_context
*/ */
class DFHACK_EXPORT ProcessEnumerator class DFHACK_EXPORT ProcessEnumerator
{ {
@ -84,6 +85,7 @@ namespace DFHack
/** /**
* Class used for holding a set of invalidated Process objects temporarily and destroy them safely. * Class used for holding a set of invalidated Process objects temporarily and destroy them safely.
* @see DFHack::Process * @see DFHack::Process
* \ingroup grp_context
*/ */
class DFHACK_EXPORT BadProcesses class DFHACK_EXPORT BadProcesses
{ {

@ -5,8 +5,17 @@
*/ */
#include "dfhack/DFExport.h" #include "dfhack/DFExport.h"
#include "dfhack/DFModule.h" #include "dfhack/DFModule.h"
/**
* \defgroup grp_buildings Building module parts
* @ingroup grp_modules
*/
namespace DFHack namespace DFHack
{ {
/**
* Structure for holding a read DF building object
* \ingroup grp_buildings
*/
struct t_building struct t_building
{ {
uint32_t origin; uint32_t origin;
@ -27,6 +36,11 @@ namespace DFHack
}; };
class DFContextShared; class DFContextShared;
/**
* The Buildings module - allows reading DF buildings
* \ingroup grp_modules
* \ingroup grp_buildings
*/
class DFHACK_EXPORT Buildings : public Module class DFHACK_EXPORT Buildings : public Module
{ {
public: public:

@ -5,17 +5,29 @@
*/ */
#include "dfhack/DFExport.h" #include "dfhack/DFExport.h"
#include "dfhack/DFModule.h" #include "dfhack/DFModule.h"
/**
* \defgroup grp_constructions Construction module parts
* @ingroup grp_modules
*/
namespace DFHack namespace DFHack
{ {
// type of item the construction is made of /**
* type of item the construction is made of
* \ingroup grp_constructions
*/
enum e_construction_base enum e_construction_base
{ {
constr_bar = 0, constr_bar = 0, /*!< Bars */
constr_block = 2, constr_block = 2, /*!< Blocks */
constr_boulder = 4, constr_boulder = 4, /*!< Rough stones or boulders */
constr_logs = 5 constr_logs = 5 /*!< Wooden logs */
}; };
#pragma pack(push, 1) #pragma pack(push, 1)
/**
* structure for holding a DF construction
* \ingroup grp_constructions
*/
struct t_construction struct t_construction
{ {
//0 //0
@ -23,7 +35,7 @@ namespace DFHack
uint16_t y; uint16_t y;
// 4 // 4
uint16_t z; uint16_t z;
uint16_t form; // e_construction_base e_construction_base form : 16;
// 8 // 8
uint16_t unk_8; // = -1 in many cases uint16_t unk_8; // = -1 in many cases
uint16_t mat_type; uint16_t mat_type;
@ -36,11 +48,16 @@ namespace DFHack
// 14 // 14
uint32_t unk6; uint32_t unk6;
// added later by dfhack /// Address of the read object in DF memory. Added by DFHack.
uint32_t origin; uint32_t origin;
}; };
#pragma pack (pop) #pragma pack (pop)
class DFContextShared; class DFContextShared;
/**
* The Constructions module - allows reading constructed tiles (walls, floors, stairs, etc.)
* \ingroup grp_modules
* \ingroup grp_constructions
*/
class DFHACK_EXPORT Constructions : public Module class DFHACK_EXPORT Constructions : public Module
{ {
public: public:

@ -30,9 +30,8 @@ distribution.
#include "dfhack/DFVector.h" #include "dfhack/DFVector.h"
#include "dfhack/DFTypes.h" #include "dfhack/DFTypes.h"
#include "dfhack/DFError.h" #include "dfhack/DFError.h"
//#include "dfhack/modules/Translation.h"
#include "dfhack/modules/Buildings.h" #include "dfhack/modules/Buildings.h"
#include "ModuleFactory.h"
using namespace DFHack; using namespace DFHack;
//raw //raw
@ -67,6 +66,11 @@ struct Buildings::Private
bool Started; bool Started;
}; };
Module* DFHack::createBuildings(DFContextShared * d)
{
return new Buildings(d);
}
Buildings::Buildings(DFContextShared * d_) Buildings::Buildings(DFContextShared * d_)
{ {
d = new Private; d = new Private;

@ -30,6 +30,7 @@ distribution.
#include "dfhack/DFVector.h" #include "dfhack/DFVector.h"
#include "dfhack/DFTypes.h" #include "dfhack/DFTypes.h"
#include "dfhack/modules/Constructions.h" #include "dfhack/modules/Constructions.h"
#include "ModuleFactory.h"
using namespace DFHack; using namespace DFHack;
@ -45,6 +46,11 @@ struct Constructions::Private
bool Started; bool Started;
}; };
Module* DFHack::createConstructions(DFContextShared * d)
{
return new Constructions(d);
}
Constructions::Constructions(DFContextShared * d_) Constructions::Constructions(DFContextShared * d_)
{ {
d = new Private; d = new Private;

@ -37,7 +37,7 @@ distribution.
#include <mod-creature2010.h> #include <mod-creature2010.h>
#include "dfhack/modules/Materials.h" #include "dfhack/modules/Materials.h"
#include "dfhack/modules/Creatures.h" #include "dfhack/modules/Creatures.h"
#include "ModuleFactory.h"
#define SHMCREATURESHDR ((Creatures2010::shm_creature_hdr *)d->d->shm_start) #define SHMCREATURESHDR ((Creatures2010::shm_creature_hdr *)d->d->shm_start)
#define SHMCMD(num) ((shm_cmd *)d->d->shm_start)[num]->pingpong #define SHMCMD(num) ((shm_cmd *)d->d->shm_start)[num]->pingpong
@ -65,6 +65,11 @@ struct Creatures::Private
Process *owner; Process *owner;
}; };
Module* DFHack::createCreatures(DFContextShared * d)
{
return new Creatures(d);
}
Creatures::Creatures(DFContextShared* _d) Creatures::Creatures(DFContextShared* _d)
{ {
d = new Private; d = new Private;

@ -28,9 +28,15 @@ distribution.
#include "dfhack/DFProcess.h" #include "dfhack/DFProcess.h"
#include "dfhack/VersionInfo.h" #include "dfhack/VersionInfo.h"
#include "dfhack/DFTypes.h" #include "dfhack/DFTypes.h"
#include "ModuleFactory.h"
using namespace DFHack; using namespace DFHack;
Module* DFHack::createGui(DFContextShared * d)
{
return new Gui(d);
}
struct Gui::Private struct Gui::Private
{ {
Private() Private()

@ -30,9 +30,15 @@ distribution.
#include "dfhack/DFVector.h" #include "dfhack/DFVector.h"
#include "dfhack/modules/Materials.h" #include "dfhack/modules/Materials.h"
#include "dfhack/modules/Items.h" #include "dfhack/modules/Items.h"
#include "ModuleFactory.h"
using namespace DFHack; using namespace DFHack;
Module* DFHack::createItems(DFContextShared * d)
{
return new Items(d);
}
enum accessor_type {ACCESSOR_CONSTANT, ACCESSOR_INDIRECT, ACCESSOR_DOUBLE_INDIRECT}; enum accessor_type {ACCESSOR_CONSTANT, ACCESSOR_INDIRECT, ACCESSOR_DOUBLE_INDIRECT};
/* this is used to store data about the way accessors work */ /* this is used to store data about the way accessors work */

@ -39,8 +39,15 @@ distribution.
#define SHMHDR ((shm_core_hdr *)d->d->shm_start) #define SHMHDR ((shm_core_hdr *)d->d->shm_start)
#define SHMDATA(type) ((type *)(d->d->shm_start + SHM_HEADER)) #define SHMDATA(type) ((type *)(d->d->shm_start + SHM_HEADER))
#define MAPS_GUARD if(!d->Started) throw DFHack::Error::ModuleNotInitialized(); #define MAPS_GUARD if(!d->Started) throw DFHack::Error::ModuleNotInitialized();
#include "ModuleFactory.h"
using namespace DFHack; using namespace DFHack;
Module* DFHack::createMaps(DFContextShared * d)
{
return new Maps(d);
}
const char * DFHack::sa_feature(int index) const char * DFHack::sa_feature(int index)
{ {
switch(index) switch(index)

@ -30,9 +30,15 @@ distribution.
#include "dfhack/DFProcess.h" #include "dfhack/DFProcess.h"
#include "dfhack/DFVector.h" #include "dfhack/DFVector.h"
#include <dfhack/DFError.h> #include <dfhack/DFError.h>
#include "ModuleFactory.h"
using namespace DFHack; using namespace DFHack;
Module* DFHack::createMaterials(DFContextShared * d)
{
return new Materials(d);
}
class Materials::Private class Materials::Private
{ {
public: public:

@ -28,8 +28,15 @@ distribution.
#include "dfhack/VersionInfo.h" #include "dfhack/VersionInfo.h"
#include "dfhack/DFProcess.h" #include "dfhack/DFProcess.h"
#include "dfhack/DFError.h" #include "dfhack/DFError.h"
#include "ModuleFactory.h"
using namespace DFHack; using namespace DFHack;
Module* DFHack::createPosition(DFContextShared * d)
{
return new Position(d);
}
struct Position::Private struct Position::Private
{ {
uint32_t window_x_offset; uint32_t window_x_offset;

@ -29,9 +29,15 @@ distribution.
#include "dfhack/DFProcess.h" #include "dfhack/DFProcess.h"
#include "dfhack/DFVector.h" #include "dfhack/DFVector.h"
#include "dfhack/DFTypes.h" #include "dfhack/DFTypes.h"
#include "ModuleFactory.h"
using namespace DFHack; using namespace DFHack;
Module* DFHack::createTranslation(DFContextShared * d)
{
return new Translation(d);
}
struct Translation::Private struct Translation::Private
{ {
uint32_t genericAddress; uint32_t genericAddress;

@ -31,9 +31,15 @@ distribution.
#include "dfhack/DFTypes.h" #include "dfhack/DFTypes.h"
#include "dfhack/modules/Vegetation.h" #include "dfhack/modules/Vegetation.h"
#include "dfhack/modules/Translation.h" #include "dfhack/modules/Translation.h"
#include "ModuleFactory.h"
using namespace DFHack; using namespace DFHack;
Module* DFHack::createVegetation(DFContextShared * d)
{
return new Vegetation(d);
}
struct Vegetation::Private struct Vegetation::Private
{ {
uint32_t vegetation_vector; uint32_t vegetation_vector;

@ -26,10 +26,16 @@ distribution.
#include <X11/Xlib.h> //need for X11 functions #include <X11/Xlib.h> //need for X11 functions
#include <X11/keysym.h> #include <X11/keysym.h>
#include <ContextShared.h> #include "ContextShared.h"
#include "ModuleFactory.h"
using namespace DFHack; using namespace DFHack;
Module* DFHack::createWindowIO(DFContextShared * d)
{
return new WindowIO(d);
}
// should always reflect the enum in DFkeys.h // should always reflect the enum in DFkeys.h
const static KeySym ksTable[NUM_SPECIALS]= const static KeySym ksTable[NUM_SPECIALS]=
{ {

@ -26,8 +26,15 @@ distribution.
#include "ContextShared.h" #include "ContextShared.h"
#include "dfhack/modules/WindowIO.h" #include "dfhack/modules/WindowIO.h"
#include "dfhack/DFProcess.h" #include "dfhack/DFProcess.h"
#include "ModuleFactory.h"
using namespace DFHack; using namespace DFHack;
Module* DFHack::createWindowIO(DFContextShared * d)
{
return new WindowIO(d);
}
// should always reflect the enum in DFkeys.h // should always reflect the enum in DFkeys.h
const static int ksTable[NUM_SPECIALS]= const static int ksTable[NUM_SPECIALS]=
{ {

@ -28,7 +28,6 @@ distribution.
using namespace std; using namespace std;
#include "dfhack/DFIntegers.h" #include "dfhack/DFIntegers.h"
#include "DFHack.h"
#include "DFHack_C.h" #include "DFHack_C.h"
#include "dfhack/modules/WindowIO.h" #include "dfhack/modules/WindowIO.h"
#include "dfhack-c/modules/WindowIO_C.h" #include "dfhack-c/modules/WindowIO_C.h"

@ -41,9 +41,15 @@ FIXME: Japa said that he had to do this with the time stuff he got from here
#include "dfhack/VersionInfo.h" #include "dfhack/VersionInfo.h"
#include "dfhack/DFTypes.h" #include "dfhack/DFTypes.h"
#include "dfhack/DFError.h" #include "dfhack/DFError.h"
#include "ModuleFactory.h"
using namespace DFHack; using namespace DFHack;
Module* DFHack::createWorld(DFContextShared * d)
{
return new World(d);
}
struct World::Private struct World::Private
{ {
bool Inited; bool Inited;