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 "dfhack/VersionInfo.h"
#include "dfhack/DFProcess.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"
#include "dfhack/DFModule.h"
using namespace DFHack;

@ -28,25 +28,14 @@ distribution.
#include "dfhack/DFProcessEnumerator.h"
#include "dfhack/DFContext.h"
#include "dfhack/DFError.h"
#include "dfhack/DFModule.h"
#include <shms.h>
#include <mod-core.h>
#include <mod-maps.h>
#include <mod-creature40d.h>
#include "private/ContextShared.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"
#include "private/ModuleFactory.h"
using namespace DFHack;
@ -162,8 +151,9 @@ TYPE * Context::get##TYPE() \
{ \
if(!d->s_mods.p##TYPE)\
{\
d->s_mods.p##TYPE = new TYPE(d);\
d->allModules.push_back(d->s_mods.p##TYPE);\
Module * mod = create##TYPE(d);\
d->s_mods.p##TYPE = (TYPE *) mod;\
d->allModules.push_back(mod);\
}\
return d->s_mods.p##TYPE;\
}

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

@ -1,6 +1,12 @@
#ifndef 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
#ifdef __GNUC__
#define DEPRECATED(func) func __attribute__ ((deprecated))

@ -1,4 +1,3 @@
/*
www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
@ -44,17 +43,23 @@ namespace DFHack
class DFContextShared;
class WindowIO;
class Process;
/**
* This class wraps all the different related objects for a particular Process
* \ingroup grp_context
*/
class DFHACK_EXPORT Context
{
public:
Context(Process * p);
~Context();
/// @return true if there's version information for the associated Process
bool isValid();
/// attach to the related process. Claims OS debugging resources
bool Attach();
/// detach from the related process. Releases OS debugging resources
bool Detach();
/// @return true if the process is attached.
bool isAttached();
/// stop the tracked process
@ -77,8 +82,6 @@ namespace DFHack
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);
// FIXME: this is crap.
/// get the creatures module
Creatures * getCreatures();
@ -125,15 +128,6 @@ namespace DFHack
bool WriteEffect(const uint32_t index, const t_effect_df40d & effect);
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
*/
@ -168,12 +162,6 @@ namespace DFHack
/*
* 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:
DFContextShared * d;
};

@ -40,6 +40,7 @@ namespace DFHack
/**
* Used to enumerate, create and destroy Contexts. The very base of DFHack.
* @see DFHack::Context
* \ingroup grp_context
*/
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.
* @see DFHack::Context
* @see DFHack::Process
* \ingroup grp_context
*/
class DFHACK_EXPORT BadContexts
{

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

@ -35,6 +35,10 @@ namespace DFHack
class Process;
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
{
ProcessID(const uint64_t _time, const uint64_t _pid): time(_time), pid(_pid){};
@ -54,7 +58,10 @@ namespace DFHack
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
{
uint64_t start;
@ -75,7 +82,10 @@ namespace DFHack
bool valid;
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
{
public:

@ -37,6 +37,7 @@ namespace DFHack
* Process enumerator
* Used to enumerate, create and destroy Processes.
* @see DFHack::Process
* \ingroup grp_context
*/
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.
* @see DFHack::Process
* \ingroup grp_context
*/
class DFHACK_EXPORT BadProcesses
{

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

@ -5,17 +5,29 @@
*/
#include "dfhack/DFExport.h"
#include "dfhack/DFModule.h"
/**
* \defgroup grp_constructions Construction module parts
* @ingroup grp_modules
*/
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
{
constr_bar = 0,
constr_block = 2,
constr_boulder = 4,
constr_logs = 5
constr_bar = 0, /*!< Bars */
constr_block = 2, /*!< Blocks */
constr_boulder = 4, /*!< Rough stones or boulders */
constr_logs = 5 /*!< Wooden logs */
};
#pragma pack(push, 1)
/**
* structure for holding a DF construction
* \ingroup grp_constructions
*/
struct t_construction
{
//0
@ -23,7 +35,7 @@ namespace DFHack
uint16_t y;
// 4
uint16_t z;
uint16_t form; // e_construction_base
e_construction_base form : 16;
// 8
uint16_t unk_8; // = -1 in many cases
uint16_t mat_type;
@ -35,12 +47,17 @@ namespace DFHack
uint16_t unk5;
// 14
uint32_t unk6;
// added later by dfhack
/// Address of the read object in DF memory. Added by DFHack.
uint32_t origin;
};
#pragma pack (pop)
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
{
public:
@ -49,7 +66,7 @@ namespace DFHack
bool Start(uint32_t & numConstructions);
bool Read (const uint32_t index, t_construction & constr);
bool Finish();
private:
struct Private;
Private *d;

@ -375,8 +375,8 @@ namespace DFHack
const uint16_t x2, const uint16_t y2,const uint16_t z2);
bool ReadCreature(const int32_t index, t_creature & furball);
bool ReadJob(const t_creature * furball, std::vector<t_material> & mat);
bool ReadInventoryIdx(const uint32_t index, std::vector<uint32_t> & item);
bool ReadInventoryPtr(const uint32_t index, std::vector<uint32_t> & item);
bool ReadInventoryIdx(const uint32_t index, std::vector<uint32_t> & item);
bool ReadInventoryPtr(const uint32_t index, std::vector<uint32_t> & item);
/* Getters */
uint32_t GetDwarfRaceIndex ( void );
@ -392,7 +392,7 @@ namespace DFHack
bool WriteTraits(const uint32_t index, const t_soul &soul);
bool WriteMood(const uint32_t index, const uint16_t mood);
bool WriteMoodSkill(const uint32_t index, const uint16_t moodSkill);
bool WriteJob(const t_creature * furball, std::vector<t_material> const& mat);
bool WriteJob(const t_creature * furball, std::vector<t_material> const& mat);
bool WritePos(const uint32_t index, const t_creature &creature);
bool WriteCiv(const uint32_t index, const int32_t civ);

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

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

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

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

@ -30,9 +30,15 @@ distribution.
#include "dfhack/DFVector.h"
#include "dfhack/modules/Materials.h"
#include "dfhack/modules/Items.h"
#include "ModuleFactory.h"
using namespace DFHack;
Module* DFHack::createItems(DFContextShared * d)
{
return new Items(d);
}
enum accessor_type {ACCESSOR_CONSTANT, ACCESSOR_INDIRECT, ACCESSOR_DOUBLE_INDIRECT};
/* 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 SHMDATA(type) ((type *)(d->d->shm_start + SHM_HEADER))
#define MAPS_GUARD if(!d->Started) throw DFHack::Error::ModuleNotInitialized();
#include "ModuleFactory.h"
using namespace DFHack;
Module* DFHack::createMaps(DFContextShared * d)
{
return new Maps(d);
}
const char * DFHack::sa_feature(int index)
{
switch(index)

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

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

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

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

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

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

@ -28,7 +28,6 @@ distribution.
using namespace std;
#include "dfhack/DFIntegers.h"
#include "DFHack.h"
#include "DFHack_C.h"
#include "dfhack/modules/WindowIO.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/DFTypes.h"
#include "dfhack/DFError.h"
#include "ModuleFactory.h"
using namespace DFHack;
Module* DFHack::createWorld(DFContextShared * d)
{
return new World(d);
}
struct World::Private
{
bool Inited;