Buildings aren't a module anymore, fix probe segfaults.

develop
Petr Mrázek 2012-01-08 02:22:13 +01:00
parent 890824dd38
commit 72016d9188
7 changed files with 50 additions and 123 deletions

@ -1097,7 +1097,6 @@ MODULE_GETTER(Materials);
MODULE_GETTER(Items); MODULE_GETTER(Items);
MODULE_GETTER(Translation); MODULE_GETTER(Translation);
MODULE_GETTER(Vegetation); MODULE_GETTER(Vegetation);
MODULE_GETTER(Buildings);
MODULE_GETTER(Constructions); MODULE_GETTER(Constructions);
MODULE_GETTER(Vermin); MODULE_GETTER(Vermin);
MODULE_GETTER(Notes); MODULE_GETTER(Notes);

@ -61,7 +61,6 @@ namespace DFHack
class Items; class Items;
class Translation; class Translation;
class Vegetation; class Vegetation;
class Buildings;
class Constructions; class Constructions;
class Vermin; class Vermin;
class Notes; class Notes;
@ -119,8 +118,6 @@ namespace DFHack
Translation * getTranslation(); Translation * getTranslation();
/// get the vegetation module /// get the vegetation module
Vegetation * getVegetation(); Vegetation * getVegetation();
/// get the buildings module
Buildings * getBuildings();
/// get the constructions module /// get the constructions module
Constructions * getConstructions(); Constructions * getConstructions();
/// get the vermin module /// get the vermin module
@ -182,7 +179,6 @@ namespace DFHack
Items * pItems; Items * pItems;
Translation * pTranslation; Translation * pTranslation;
Vegetation * pVegetation; Vegetation * pVegetation;
Buildings * pBuildings;
Constructions * pConstructions; Constructions * pConstructions;
Vermin * pVermin; Vermin * pVermin;
Notes * pNotes; Notes * pNotes;

@ -23,25 +23,20 @@ distribution.
*/ */
#pragma once #pragma once
#ifndef CL_MOD_BUILDINGS
#define CL_MOD_BUILDINGS
/**
* \defgroup grp_buildings Building module parts - also includes zones and stockpiles
* @ingroup grp_modules
*/
#include "Export.h" #include "Export.h"
#include "Module.h"
#ifdef __cplusplus
namespace DFHack namespace DFHack
{ {
#endif namespace Simple
/** {
namespace Buildings
{
/**
* Structure for holding a read DF building object * Structure for holding a read DF building object
* \ingroup grp_buildings * \ingroup grp_buildings
*/ */
struct t_building struct t_building
{ {
uint32_t x1; uint32_t x1;
uint32_t y1; uint32_t y1;
uint32_t x2; uint32_t x2;
@ -51,33 +46,26 @@ namespace DFHack
uint32_t type; uint32_t type;
int32_t custom_type; int32_t custom_type;
void * origin; void * origin;
}; };
#ifdef __cplusplus /**
/**
* The Buildings module - allows reading DF buildings * The Buildings module - allows reading DF buildings
* \ingroup grp_modules * \ingroup grp_modules
* \ingroup grp_buildings * \ingroup grp_buildings
*/ */
class DFHACK_EXPORT Buildings : public Module DFHACK_EXPORT uint32_t getNumBuildings ();
{
public:
Buildings();
~Buildings();
bool Start(uint32_t & numBuildings);
// read one building at offset
bool Read (const uint32_t index, t_building & building);
bool Finish();
// read mapping from custom_type value to building RAW name /**
// custom_type of -1 implies ordinary building * read building by index
bool ReadCustomWorkshopTypes(std::map <uint32_t, std::string> & btypes); */
DFHACK_EXPORT bool Read (const uint32_t index, t_building & building);
private: /**
struct Private; * read mapping from custom_type value to building RAW name
Private *d; * custom_type of -1 implies ordinary building
}; */
} DFHACK_EXPORT bool ReadCustomWorkshopTypes(std::map <uint32_t, std::string> & btypes);
#endif // __cplusplus
#endif }
}
}

@ -38,10 +38,10 @@ using namespace std;
#include "ModuleFactory.h" #include "ModuleFactory.h"
#include "Core.h" #include "Core.h"
using namespace DFHack; using namespace DFHack;
using namespace DFHack::Simple;
#include "DataDefs.h" #include "DataDefs.h"
#include "df/world.h" #include "df/world.h"
#include "df/world_raws.h"
#include "df/building_def.h" #include "df/building_def.h"
#include "df/building.h" #include "df/building.h"
#include "df/building_workshopst.h" #include "df/building_workshopst.h"
@ -50,70 +50,19 @@ using namespace df::enums;
using df::global::world; using df::global::world;
using df::building_def; using df::building_def;
//raw uint32_t Buildings::getNumBuildings()
struct t_building_df40d
{ {
uint32_t vtable; return world->buildings.all.size();
uint32_t x1;
uint32_t y1;
uint32_t centerx;
uint32_t x2;
uint32_t y2;
uint32_t centery;
uint32_t z;
uint32_t height;
t_matglossPair material;
// not complete
};
struct Buildings::Private
{
Process * owner;
bool Inited;
bool Started;
int32_t custom_workshop_id;
};
Module* DFHack::createBuildings()
{
return new Buildings();
}
Buildings::Buildings()
{
Core & c = Core::getInstance();
d = new Private;
d->Started = false;
d->owner = c.p;
d->Inited = true;
c.vinfo->resolveClassnameToClassID("building_custom_workshop", d->custom_workshop_id);
}
Buildings::~Buildings()
{
if(d->Started)
Finish();
delete d;
}
bool Buildings::Start(uint32_t & numbuildings)
{
if(!d->Inited)
return false;
numbuildings = world->buildings.all.size();
d->Started = true;
return true;
} }
bool Buildings::Read (const uint32_t index, t_building & building) bool Buildings::Read (const uint32_t index, t_building & building)
{ {
if(!d->Started) Core & c = Core::getInstance();
return false;
df::building *bld_40d = world->buildings.all[index]; df::building *bld_40d = world->buildings.all[index];
// transform // transform
int32_t type = -1; int32_t type = -1;
d->owner->getDescriptor()->resolveObjectToClassID ( (char *)bld_40d, type); c.vinfo->resolveObjectToClassID ( (char *)bld_40d, type);
building.x1 = bld_40d->x1; building.x1 = bld_40d->x1;
building.x2 = bld_40d->x2; building.x2 = bld_40d->x2;
building.y1 = bld_40d->y1; building.y1 = bld_40d->y1;
@ -127,19 +76,10 @@ bool Buildings::Read (const uint32_t index, t_building & building)
return true; return true;
} }
bool Buildings::Finish()
{
d->Started = false;
return true;
}
bool Buildings::ReadCustomWorkshopTypes(map <uint32_t, string> & btypes) bool Buildings::ReadCustomWorkshopTypes(map <uint32_t, string> & btypes)
{ {
if(!d->Inited)
return false;
Core & c = Core::getInstance(); Core & c = Core::getInstance();
Process * p = d->owner;
vector <building_def *> & bld_def = world->raws.buildings.all; vector <building_def *> & bld_def = world->raws.buildings.all;
uint32_t size = bld_def.size(); uint32_t size = bld_def.size();
btypes.clear(); btypes.clear();

@ -1 +1 @@
Subproject commit 3277c6b29ddbb5d800ccb65eba27fed200236f3d Subproject commit c114ec5f995aec69631187212254309464f82775

@ -135,7 +135,7 @@ DFhackCExport command_result df_probe (Core * c, vector <string> & parameters)
MapExtras::Block * b = mc.BlockAt(cursor/16); MapExtras::Block * b = mc.BlockAt(cursor/16);
mapblock40d & block = b->raw; mapblock40d & block = b->raw;
if(b) if(b && b->valid)
{ {
con.print("block addr: 0x%x\n\n", block.origin); con.print("block addr: 0x%x\n\n", block.origin);
/* /*
@ -285,6 +285,10 @@ DFhackCExport command_result df_probe (Core * c, vector <string> & parameters)
con << "mystery: " << block.mystery << endl; con << "mystery: " << block.mystery << endl;
con << std::endl; con << std::endl;
} }
else
{
con.printerr("No data.\n");
}
} }
} }
c->Resume(); c->Resume();

@ -1 +1 @@
Subproject commit 545b2730ed137935643778f1b8ba115ae11c50a2 Subproject commit 92627e39cb3502812cd5a131716d3d1da8ef625a