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(Translation);
MODULE_GETTER(Vegetation);
MODULE_GETTER(Buildings);
MODULE_GETTER(Constructions);
MODULE_GETTER(Vermin);
MODULE_GETTER(Notes);

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

@ -23,19 +23,14 @@ distribution.
*/
#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 "Module.h"
#ifdef __cplusplus
namespace DFHack
{
#endif
namespace Simple
{
namespace Buildings
{
/**
* Structure for holding a read DF building object
* \ingroup grp_buildings
@ -53,31 +48,24 @@ namespace DFHack
void * origin;
};
#ifdef __cplusplus
/**
* The Buildings module - allows reading DF buildings
* \ingroup grp_modules
* \ingroup grp_buildings
*/
class DFHACK_EXPORT Buildings : public Module
{
public:
Buildings();
~Buildings();
bool Start(uint32_t & numBuildings);
// read one building at offset
bool Read (const uint32_t index, t_building & building);
bool Finish();
DFHACK_EXPORT uint32_t getNumBuildings ();
/**
* read building by index
*/
DFHACK_EXPORT bool Read (const uint32_t index, t_building & building);
// read mapping from custom_type value to building RAW name
// custom_type of -1 implies ordinary building
bool ReadCustomWorkshopTypes(std::map <uint32_t, std::string> & btypes);
/**
* read mapping from custom_type value to building RAW name
* custom_type of -1 implies ordinary building
*/
DFHACK_EXPORT bool ReadCustomWorkshopTypes(std::map <uint32_t, std::string> & btypes);
private:
struct Private;
Private *d;
};
}
#endif // __cplusplus
#endif
}
}

@ -38,10 +38,10 @@ using namespace std;
#include "ModuleFactory.h"
#include "Core.h"
using namespace DFHack;
using namespace DFHack::Simple;
#include "DataDefs.h"
#include "df/world.h"
#include "df/world_raws.h"
#include "df/building_def.h"
#include "df/building.h"
#include "df/building_workshopst.h"
@ -50,70 +50,19 @@ using namespace df::enums;
using df::global::world;
using df::building_def;
//raw
struct t_building_df40d
uint32_t Buildings::getNumBuildings()
{
uint32_t vtable;
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;
return world->buildings.all.size();
}
bool Buildings::Read (const uint32_t index, t_building & building)
{
if(!d->Started)
return false;
Core & c = Core::getInstance();
df::building *bld_40d = world->buildings.all[index];
// transform
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.x2 = bld_40d->x2;
building.y1 = bld_40d->y1;
@ -127,19 +76,10 @@ bool Buildings::Read (const uint32_t index, t_building & building)
return true;
}
bool Buildings::Finish()
{
d->Started = false;
return true;
}
bool Buildings::ReadCustomWorkshopTypes(map <uint32_t, string> & btypes)
{
if(!d->Inited)
return false;
Core & c = Core::getInstance();
Process * p = d->owner;
vector <building_def *> & bld_def = world->raws.buildings.all;
uint32_t size = bld_def.size();
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);
mapblock40d & block = b->raw;
if(b)
if(b && b->valid)
{
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 << std::endl;
}
else
{
con.printerr("No data.\n");
}
}
}
c->Resume();

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