diff --git a/library/ContextShared.cpp b/library/ContextShared.cpp index 01842ee1f..b61784ea4 100644 --- a/library/ContextShared.cpp +++ b/library/ContextShared.cpp @@ -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; diff --git a/library/DFContext.cpp b/library/DFContext.cpp index fa4f85b59..3fee55d71 100644 --- a/library/DFContext.cpp +++ b/library/DFContext.cpp @@ -28,25 +28,14 @@ distribution. #include "dfhack/DFProcessEnumerator.h" #include "dfhack/DFContext.h" #include "dfhack/DFError.h" +#include "dfhack/DFModule.h" #include #include #include #include #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;\ } diff --git a/library/DFContextManager.cpp b/library/DFContextManager.cpp index 634794029..bfe5a3b98 100644 --- a/library/DFContextManager.cpp +++ b/library/DFContextManager.cpp @@ -31,11 +31,6 @@ distribution. #include "dfhack/DFContext.h" #include "dfhack/DFContextManager.h" - -#include -#include -#include -#include #include "private/ContextShared.h" using namespace DFHack; diff --git a/library/include/DFHack.h b/library/include/DFHack.h index 95f39729a..9580731f1 100644 --- a/library/include/DFHack.h +++ b/library/include/DFHack.h @@ -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)) diff --git a/library/include/dfhack/DFContext.h b/library/include/dfhack/DFContext.h index 3d8a0c150..14a53fb98 100644 --- a/library/include/dfhack/DFContext.h +++ b/library/include/dfhack/DFContext.h @@ -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; }; diff --git a/library/include/dfhack/DFContextManager.h b/library/include/dfhack/DFContextManager.h index 804b7c48a..5591fef03 100644 --- a/library/include/dfhack/DFContextManager.h +++ b/library/include/dfhack/DFContextManager.h @@ -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 { diff --git a/library/include/dfhack/DFModule.h b/library/include/dfhack/DFModule.h index 7ed3e6738..41f7dee6a 100644 --- a/library/include/dfhack/DFModule.h +++ b/library/include/dfhack/DFModule.h @@ -30,6 +30,10 @@ distribution. namespace DFHack { class Context; + /** + * The parent class for all DFHack modules + * \ingroup grp_modules + */ class DFHACK_EXPORT Module { public: diff --git a/library/include/dfhack/DFProcess.h b/library/include/dfhack/DFProcess.h index 140bdd505..6ff7f37ba 100644 --- a/library/include/dfhack/DFProcess.h +++ b/library/include/dfhack/DFProcess.h @@ -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: diff --git a/library/include/dfhack/DFProcessEnumerator.h b/library/include/dfhack/DFProcessEnumerator.h index 4b1eca7b0..16be66dca 100644 --- a/library/include/dfhack/DFProcessEnumerator.h +++ b/library/include/dfhack/DFProcessEnumerator.h @@ -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 { diff --git a/library/include/dfhack/modules/Buildings.h b/library/include/dfhack/modules/Buildings.h index f16f03953..a92cd02de 100644 --- a/library/include/dfhack/modules/Buildings.h +++ b/library/include/dfhack/modules/Buildings.h @@ -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: diff --git a/library/include/dfhack/modules/Constructions.h b/library/include/dfhack/modules/Constructions.h index 76384fc7b..e775df80a 100644 --- a/library/include/dfhack/modules/Constructions.h +++ b/library/include/dfhack/modules/Constructions.h @@ -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; diff --git a/library/include/dfhack/modules/Creatures.h b/library/include/dfhack/modules/Creatures.h index 613f462b6..a4d58d921 100644 --- a/library/include/dfhack/modules/Creatures.h +++ b/library/include/dfhack/modules/Creatures.h @@ -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 & mat); - bool ReadInventoryIdx(const uint32_t index, std::vector & item); - bool ReadInventoryPtr(const uint32_t index, std::vector & item); + bool ReadInventoryIdx(const uint32_t index, std::vector & item); + bool ReadInventoryPtr(const uint32_t index, std::vector & 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 const& mat); + bool WriteJob(const t_creature * furball, std::vector const& mat); bool WritePos(const uint32_t index, const t_creature &creature); bool WriteCiv(const uint32_t index, const int32_t civ); diff --git a/library/modules/Buildings.cpp b/library/modules/Buildings.cpp index 20b4cb88e..1d99fe09b 100644 --- a/library/modules/Buildings.cpp +++ b/library/modules/Buildings.cpp @@ -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; diff --git a/library/modules/Constructions.cpp b/library/modules/Constructions.cpp index ba6370ffd..eb079f5e9 100644 --- a/library/modules/Constructions.cpp +++ b/library/modules/Constructions.cpp @@ -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; diff --git a/library/modules/Creatures.cpp b/library/modules/Creatures.cpp index 27bc320db..9113723d2 100644 --- a/library/modules/Creatures.cpp +++ b/library/modules/Creatures.cpp @@ -37,7 +37,7 @@ distribution. #include #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; diff --git a/library/modules/Gui.cpp b/library/modules/Gui.cpp index 177a00467..14f308eab 100644 --- a/library/modules/Gui.cpp +++ b/library/modules/Gui.cpp @@ -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() diff --git a/library/modules/Items.cpp b/library/modules/Items.cpp index dcb137848..4b4d6bd65 100644 --- a/library/modules/Items.cpp +++ b/library/modules/Items.cpp @@ -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 */ diff --git a/library/modules/Maps.cpp b/library/modules/Maps.cpp index 03fdd0495..da443b97a 100644 --- a/library/modules/Maps.cpp +++ b/library/modules/Maps.cpp @@ -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) diff --git a/library/modules/Materials.cpp b/library/modules/Materials.cpp index 7ab9f8218..94f8e1e84 100644 --- a/library/modules/Materials.cpp +++ b/library/modules/Materials.cpp @@ -30,9 +30,15 @@ distribution. #include "dfhack/DFProcess.h" #include "dfhack/DFVector.h" #include +#include "ModuleFactory.h" using namespace DFHack; +Module* DFHack::createMaterials(DFContextShared * d) +{ + return new Materials(d); +} + class Materials::Private { public: diff --git a/library/modules/Position.cpp b/library/modules/Position.cpp index 7442d9ddb..ff0deb880 100644 --- a/library/modules/Position.cpp +++ b/library/modules/Position.cpp @@ -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; diff --git a/library/modules/Translation.cpp b/library/modules/Translation.cpp index ba6018d55..25f482a9d 100644 --- a/library/modules/Translation.cpp +++ b/library/modules/Translation.cpp @@ -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; diff --git a/library/modules/Vegetation.cpp b/library/modules/Vegetation.cpp index cceff66ef..c101e9da6 100644 --- a/library/modules/Vegetation.cpp +++ b/library/modules/Vegetation.cpp @@ -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; diff --git a/library/modules/WindowIO-linux.cpp b/library/modules/WindowIO-linux.cpp index b8ff0cd13..db27d0a44 100644 --- a/library/modules/WindowIO-linux.cpp +++ b/library/modules/WindowIO-linux.cpp @@ -26,10 +26,16 @@ distribution. #include //need for X11 functions #include -#include +#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]= { diff --git a/library/modules/WindowIO-windows.cpp b/library/modules/WindowIO-windows.cpp index 1a432ade4..249ebc6a6 100644 --- a/library/modules/WindowIO-windows.cpp +++ b/library/modules/WindowIO-windows.cpp @@ -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]= { diff --git a/library/modules/WindowIO_C.cpp b/library/modules/WindowIO_C.cpp index 73217a7d2..c265a4190 100644 --- a/library/modules/WindowIO_C.cpp +++ b/library/modules/WindowIO_C.cpp @@ -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" diff --git a/library/modules/World.cpp b/library/modules/World.cpp index 73b7a95cd..65ace2abf 100644 --- a/library/modules/World.cpp +++ b/library/modules/World.cpp @@ -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;