Merged patches from Rainer Keller

develop
Petr Mrázek 2010-11-17 20:50:50 +01:00
parent 88e076c507
commit ac91f46b6c
17 changed files with 1049 additions and 1075 deletions

@ -86,6 +86,7 @@ VersionInfo.cpp
VersionInfoFactory.cpp VersionInfoFactory.cpp
DFContextManager.cpp DFContextManager.cpp
DFContext.cpp DFContext.cpp
DFTileTypes.cpp
DFProcessEnumerator.cpp DFProcessEnumerator.cpp
ContextShared.cpp ContextShared.cpp

@ -31,7 +31,7 @@ DFContextShared::DFContextShared()
DFContextShared::~DFContextShared() DFContextShared::~DFContextShared()
{ {
// invalidate all modules // invalidate all modules
for(int i = 0 ; i < allModules.size(); i++) for(unsigned int i = 0 ; i < allModules.size(); i++)
{ {
delete allModules[i]; delete allModules[i];
} }

@ -93,7 +93,7 @@ bool Context::Detach()
} }
d->shm_start = 0; d->shm_start = 0;
// invalidate all modules // invalidate all modules
for(int i = 0 ; i < d->allModules.size(); i++) for(unsigned int i = 0 ; i < d->allModules.size(); i++)
{ {
delete d->allModules[i]; delete d->allModules[i];
} }
@ -174,7 +174,7 @@ bool Context::AsyncSuspend()
bool Context::Resume() bool Context::Resume()
{ {
for(int i = 0 ; i < d->allModules.size(); i++) for(unsigned int i = 0 ; i < d->allModules.size(); i++)
{ {
d->allModules[i]->OnResume(); d->allModules[i]->OnResume();
} }

@ -69,7 +69,7 @@ BadContexts::~BadContexts()
bool BadContexts::Contains(Process* p) bool BadContexts::Contains(Process* p)
{ {
for(int i = 0; i < d->bad.size(); i++) for(unsigned int i = 0; i < d->bad.size(); i++)
{ {
if((d->bad[i])->getProcess() == p) if((d->bad[i])->getProcess() == p)
return true; return true;
@ -79,7 +79,7 @@ bool BadContexts::Contains(Process* p)
bool BadContexts::Contains(Context* c) bool BadContexts::Contains(Context* c)
{ {
for(int i = 0; i < d->bad.size(); i++) for(unsigned int i = 0; i < d->bad.size(); i++)
{ {
if(d->bad[i] == c) if(d->bad[i] == c)
return true; return true;
@ -94,7 +94,7 @@ uint32_t BadContexts::size()
void BadContexts::clear() void BadContexts::clear()
{ {
for(int i = 0; i < d->bad.size(); i++) for(unsigned int i = 0; i < d->bad.size(); i++)
{ {
// delete both Process and Context! // delete both Process and Context!
// process has to be deleted after context, because Context does some // process has to be deleted after context, because Context does some
@ -227,7 +227,7 @@ Context * ContextManager::getSingleContext()
{ {
Refresh(); Refresh();
} }
for(int i = 0; i < d->contexts.size();i++) for(unsigned int i = 0; i < d->contexts.size();i++)
{ {
if(d->contexts[i]->isValid()) if(d->contexts[i]->isValid())
{ {
@ -239,7 +239,7 @@ Context * ContextManager::getSingleContext()
void ContextManager::purge(void) void ContextManager::purge(void)
{ {
for(int i = 0; i < d->contexts.size();i++) for(unsigned int i = 0; i < d->contexts.size();i++)
delete d->contexts[i]; delete d->contexts[i];
d->contexts.clear(); d->contexts.clear();
d->pEnum->purge(); d->pEnum->purge();

@ -63,7 +63,7 @@ BadProcesses::~BadProcesses()
bool BadProcesses::Contains(Process* p) bool BadProcesses::Contains(Process* p)
{ {
for(int i = 0; i < d->bad.size(); i++) for(unsigned int i = 0; i < d->bad.size(); i++)
{ {
if(d->bad[i] == p) if(d->bad[i] == p)
return true; return true;
@ -96,7 +96,7 @@ uint32_t BadProcesses::size()
void BadProcesses::clear() void BadProcesses::clear()
{ {
for(int i = 0; i < d->bad.size(); i++) for(unsigned int i = 0; i < d->bad.size(); i++)
{ {
delete d->bad[i]; delete d->bad[i];
} }

@ -276,7 +276,7 @@ int CreatureCasteConvert(t_creaturecaste* src, c_creaturecaste* dest)
((*alloc_creaturecaste_callback)(dest, src->rawname, src->singular, src->plural, src->adjective, src->ColorModifier.size(), src->bodypart.size())); ((*alloc_creaturecaste_callback)(dest, src->rawname, src->singular, src->plural, src->adjective, src->ColorModifier.size(), src->bodypart.size()));
for(int i = 0; i < dest->colorModifierLength; i++) for(unsigned int i = 0; i < dest->colorModifierLength; i++)
ColorListConvert(&src->ColorModifier[i], &dest->ColorModifier[i]); ColorListConvert(&src->ColorModifier[i], &dest->ColorModifier[i]);
copy(src->bodypart.begin(), src->bodypart.end(), dest->bodypart); copy(src->bodypart.begin(), src->bodypart.end(), dest->bodypart);
@ -291,7 +291,7 @@ int CreatureTypeConvert(t_creaturetype* src, c_creaturetype* dest)
((*alloc_creaturetype_callback)(dest, src->rawname, src->castes.size(), src->extract.size(), src->tile_character, src->tilecolor.fore, src->tilecolor.back, src->tilecolor.bright)); ((*alloc_creaturetype_callback)(dest, src->rawname, src->castes.size(), src->extract.size(), src->tile_character, src->tilecolor.fore, src->tilecolor.back, src->tilecolor.bright));
for(int i = 0; i < dest->castesCount; i++) for(unsigned int i = 0; i < dest->castesCount; i++)
CreatureCasteConvert(&src->castes[i], &dest->castes[i]); CreatureCasteConvert(&src->castes[i], &dest->castes[i]);
copy(src->extract.begin(), src->extract.end(), dest->extract); copy(src->extract.begin(), src->extract.end(), dest->extract);

@ -683,7 +683,6 @@ bool VersionInfoFactory::loadFile(string path_to_xml)
if(name) if(name)
{ {
string str_name = name; string str_name = name;
VersionInfo *base = new VersionInfo();
mem = new VersionInfo(); mem = new VersionInfo();
ParseBase( pMemInfo , mem ); ParseBase( pMemInfo , mem );
knownVersions[str_name] = v_descr (pMemInfo, mem); knownVersions[str_name] = v_descr (pMemInfo, mem);

@ -62,19 +62,7 @@ namespace DFHack
}; };
#undef X #undef X
//Visual Studio screams if you don't do this for the const char* arrays extern const char *TileClassString[];
#ifndef char_p
typedef char * char_p;
#endif
//set tile class string lookup table (e.g. for printing to user)
#define X(name,comment) #name,
const char_p TileClassString[tileclass_count+1] = {
TILECLASS_MACRO
0
};
#undef X
#define TILEMATERIAL_MACRO \ #define TILEMATERIAL_MACRO \
X(AIR, "empty" ) \ X(AIR, "empty" ) \
@ -107,14 +95,8 @@ namespace DFHack
}; };
#undef X #undef X
//string lookup table (e.g. for printing to user)
#define X(name,comment) #name,
const char_p TileMaterialString[tilematerial_count+1] = {
TILEMATERIAL_MACRO
0
};
#undef X
extern const char *TileMaterialString[];
// Special specials of the tile. // Special specials of the tile.
// Not the best way to do this, but compatible with existing code. // Not the best way to do this, but compatible with existing code.
@ -144,14 +126,7 @@ namespace DFHack
}; };
#undef X #undef X
//string lookup table (e.g. for printing to user) extern const char *TileSpecialString[];
#define X(name,comment) #name,
const char_p TileSpecialString[tilespecial_count+1] = {
TILESPECIAL_MACRO
0
};
#undef X
// variants are used for tiles, where there are multiple variants of the same - like grass floors // variants are used for tiles, where there are multiple variants of the same - like grass floors
enum TileVariant enum TileVariant
@ -991,8 +966,6 @@ namespace DFHack
int32_t tt, maybe=0, match=0; int32_t tt, maybe=0, match=0;
int value=0, matchv=0; int value=0, matchv=0;
const TileRow *source = &tileTypeTable[sourceTileType]; const TileRow *source = &tileTypeTable[sourceTileType];
const char * sourcename = source->name;
const uint32_t sourcenameint = *((const uint32_t *)sourcename);
#ifdef assert #ifdef assert
assert( sourceTileType >=0 && sourceTileType < TILE_TYPE_ARRAY_LENGTH ); assert( sourceTileType >=0 && sourceTileType < TILE_TYPE_ARRAY_LENGTH );

@ -74,7 +74,7 @@ t_customWorkshop* Buildings_ReadCustomWorkshopTypes(DFHackObject* b_Ptr)
if(b_Ptr != NULL) if(b_Ptr != NULL)
{ {
int i; int i;
t_customWorkshop* cw_Ptr; t_customWorkshop* cw_Ptr = NULL;
std::map<uint32_t, string> bTypes; std::map<uint32_t, string> bTypes;
map<uint32_t, string>::iterator bIter; map<uint32_t, string>::iterator bIter;

@ -69,7 +69,7 @@ Creatures::Creatures(DFContextShared* _d)
{ {
d = new Private; d = new Private;
d->d = _d; d->d = _d;
Process * p = d->owner = _d->p; d->owner = _d->p;
d->Inited = false; d->Inited = false;
d->Started = false; d->Started = false;
d->d->InitReadNames(); // throws on error d->d->InitReadNames(); // throws on error
@ -183,7 +183,6 @@ bool Creatures::ReadCreature (const int32_t index, t_creature & furball)
} }
*/ */
// non-SHM slow path // non-SHM slow path
VersionInfo * minfo = d->d->offset_descriptor;
// read pointer from vector at position // read pointer from vector at position
uint32_t temp = d->p_cre->at (index); uint32_t temp = d->p_cre->at (index);
@ -471,6 +470,8 @@ bool Creatures::WriteSex(const uint32_t index, const uint8_t sex)
uint32_t temp = d->p_cre->at (index); uint32_t temp = d->p_cre->at (index);
Process * p = d->owner; Process * p = d->owner;
p->writeByte (temp + d->creatures.sex_offset, sex); p->writeByte (temp + d->creatures.sex_offset, sex);
return true;
} }
bool Creatures::WriteTraits(const uint32_t index, const t_soul &soul) bool Creatures::WriteTraits(const uint32_t index, const t_soul &soul)
@ -596,7 +597,6 @@ bool Creatures::ReadJob(const t_creature * furball, vector<t_material> & mat)
if(!d->Inited) return false; if(!d->Inited) return false;
if(!furball->current_job.active) return false; if(!furball->current_job.active) return false;
Process * p = d->owner; Process * p = d->owner;
VersionInfo * minfo = d->d->offset_descriptor;
DfVector <uint32_t> cmats(p, furball->current_job.occupationPtr + d->OG_jobs->getOffset("materials_vector")); DfVector <uint32_t> cmats(p, furball->current_job.occupationPtr + d->OG_jobs->getOffset("materials_vector"));
mat.resize(cmats.size()); mat.resize(cmats.size());
@ -614,7 +614,6 @@ bool Creatures::ReadJob(const t_creature * furball, vector<t_material> & mat)
bool Creatures::ReadInventoryIdx(const uint32_t index, std::vector<uint32_t> & item) bool Creatures::ReadInventoryIdx(const uint32_t index, std::vector<uint32_t> & item)
{ {
if(!d->Started) return false; if(!d->Started) return false;
Process * p = d->owner;
uint32_t temp = d->p_cre->at (index); uint32_t temp = d->p_cre->at (index);
return this->ReadInventoryPtr(temp, item); return this->ReadInventoryPtr(temp, item);
} }

@ -84,7 +84,7 @@ t_material* Creatures_ReadJob(DFHackObject* cPtr, const t_creature* furball)
if(mat.size() <= 0) if(mat.size() <= 0)
return NULL; return NULL;
t_material* buf; t_material* buf = NULL;
(*alloc_t_material_buffer_callback)(buf, mat.size()); (*alloc_t_material_buffer_callback)(buf, mat.size());
@ -115,7 +115,7 @@ uint32_t* Creatures_ReadInventoryIdx(DFHackObject* cPtr, const uint32_t index)
if(item.size() <= 0) if(item.size() <= 0)
return NULL; return NULL;
uint32_t* buf; uint32_t* buf = NULL;
(*alloc_uint_buffer_callback)(buf, item.size()); (*alloc_uint_buffer_callback)(buf, item.size());
@ -144,7 +144,7 @@ uint32_t* Creatures_ReadInventoryPtr(DFHackObject* cPtr, const uint32_t index)
if(item.size() <= 0) if(item.size() <= 0)
return NULL; return NULL;
uint32_t* buf; uint32_t* buf = NULL;
(*alloc_uint_buffer_callback)(buf, item.size()); (*alloc_uint_buffer_callback)(buf, item.size());

@ -58,7 +58,7 @@ char* Items_getItemDescription(DFHackObject* items, uint32_t itemptr, DFHackObje
if(desc.size() > 0) if(desc.size() > 0)
{ {
char* buf; char* buf = NULL;
(*alloc_char_buffer_callback)(buf,desc.size()); (*alloc_char_buffer_callback)(buf,desc.size());
if(buf != NULL) if(buf != NULL)
@ -86,7 +86,7 @@ char* Items_getItemClass(DFHackObject* items, int32_t index)
if(iclass.size() > 0) if(iclass.size() > 0)
{ {
char* buf; char* buf = NULL;
(*alloc_char_buffer_callback)(buf, iclass.size()); (*alloc_char_buffer_callback)(buf, iclass.size());
if(buf != NULL) if(buf != NULL)
{ {

@ -661,7 +661,6 @@ __int16 __userpurge GetGeologicalRegion<ax>(__int16 block_X<cx>, int X<ebx>, __i
bool Maps::ReadGeology (vector < vector <uint16_t> >& assign) bool Maps::ReadGeology (vector < vector <uint16_t> >& assign)
{ {
MAPS_GUARD MAPS_GUARD
VersionInfo * minfo = d->d->offset_descriptor;
Process *p = d->owner; Process *p = d->owner;
// get needed addresses and offsets. Now this is what I call crazy. // get needed addresses and offsets. Now this is what I call crazy.
uint16_t worldSizeX, worldSizeY; uint16_t worldSizeX, worldSizeY;
@ -736,7 +735,6 @@ bool Maps::ReadLocalFeatures( std::map <planecoord, std::vector<t_feature *> > &
return false; return false;
Process * p = d->owner; Process * p = d->owner;
VersionInfo * mem = p->getDescriptor();
// deref pointer to the humongo-structure // deref pointer to the humongo-structure
uint32_t base = p->readDWord(d->OG_local_features->getAddress("start_ptr")); uint32_t base = p->readDWord(d->OG_local_features->getAddress("start_ptr"));
if(!base) if(!base)

@ -62,12 +62,12 @@ uint16_t* Maps_ReadGeology(DFHackObject* maps)
if(((DFHack::Maps*)maps)->ReadGeology(geology)) if(((DFHack::Maps*)maps)->ReadGeology(geology))
{ {
uint16_t* buf; uint16_t* buf = NULL;
uint32_t geoLength = 0; uint32_t geoLength = 0;
for(int i = 0; i < geology.size(); i++) for(unsigned int i = 0; i < geology.size(); i++)
{ {
for(int j = 0; j < geology[i].size(); j++) for(unsigned int j = 0; j < geology[i].size(); j++)
{ {
geoLength += geology[i].size(); geoLength += geology[i].size();
} }
@ -79,7 +79,7 @@ uint16_t* Maps_ReadGeology(DFHackObject* maps)
{ {
uint16_t* bufCopyPtr = buf; uint16_t* bufCopyPtr = buf;
for(int i = 0; i < geology.size(); i++) for(unsigned int i = 0; i < geology.size(); i++)
{ {
copy(geology[i].begin(), geology[i].end(), bufCopyPtr); copy(geology[i].begin(), geology[i].end(), bufCopyPtr);
@ -107,7 +107,7 @@ t_feature* Maps_ReadGlobalFeatures(DFHackObject* maps)
if(featureVec.size() <= 0) if(featureVec.size() <= 0)
return NULL; return NULL;
t_feature* buf; t_feature* buf = NULL;
(*alloc_t_feature_buffer_callback)(buf, featureVec.size()); (*alloc_t_feature_buffer_callback)(buf, featureVec.size());
@ -297,6 +297,8 @@ int Maps_WriteEmptyLocalFeature(DFHackObject* maps, uint32_t x, uint32_t y, uint
{ {
return ((DFHack::Maps*)maps)->WriteLocalFeature(x, y, z, -1); return ((DFHack::Maps*)maps)->WriteLocalFeature(x, y, z, -1);
} }
return -1;
} }
int Maps_WriteGlobalFeature(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z, int16_t local) int Maps_WriteGlobalFeature(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z, int16_t local)
@ -315,6 +317,8 @@ int Maps_WriteEmptyGlobalFeature(DFHackObject* maps, uint32_t x, uint32_t y, uin
{ {
return ((DFHack::Maps*)maps)->WriteGlobalFeature(x, y, z, -1); return ((DFHack::Maps*)maps)->WriteGlobalFeature(x, y, z, -1);
} }
return -1;
} }
int Maps_ReadBlockFlags(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z, t_blockflags* blockflags) int Maps_ReadBlockFlags(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z, t_blockflags* blockflags)

@ -232,7 +232,7 @@ t_matgloss* Materials_getInorganic(DFHackObject* mat)
if(materials->inorganic.size() > 0) if(materials->inorganic.size() > 0)
{ {
t_matgloss* buf; t_matgloss* buf = NULL;
((*alloc_matgloss_buffer_callback)(buf, materials->inorganic.size())); ((*alloc_matgloss_buffer_callback)(buf, materials->inorganic.size()));
@ -256,7 +256,7 @@ t_matgloss* Materials_getOrganic(DFHackObject* mat)
if(materials->organic.size() > 0) if(materials->organic.size() > 0)
{ {
t_matgloss* buf; t_matgloss* buf = NULL;
((*alloc_matgloss_buffer_callback)(buf, materials->organic.size())); ((*alloc_matgloss_buffer_callback)(buf, materials->organic.size()));
@ -280,7 +280,7 @@ t_matgloss* Materials_getTree(DFHackObject* mat)
if(materials->tree.size() > 0) if(materials->tree.size() > 0)
{ {
t_matgloss* buf; t_matgloss* buf = NULL;
((*alloc_matgloss_buffer_callback)(buf, materials->tree.size())); ((*alloc_matgloss_buffer_callback)(buf, materials->tree.size()));
@ -304,7 +304,7 @@ t_matgloss* Materials_getPlant(DFHackObject* mat)
if(materials->plant.size() > 0) if(materials->plant.size() > 0)
{ {
t_matgloss* buf; t_matgloss* buf = NULL;
((*alloc_matgloss_buffer_callback)(buf, materials->plant.size())); ((*alloc_matgloss_buffer_callback)(buf, materials->plant.size()));
@ -328,7 +328,7 @@ t_matgloss* Materials_getRace(DFHackObject* mat)
if(materials->race.size() > 0) if(materials->race.size() > 0)
{ {
t_matgloss* buf; t_matgloss* buf = NULL;
((*alloc_matgloss_buffer_callback)(buf, materials->race.size())); ((*alloc_matgloss_buffer_callback)(buf, materials->race.size()));
@ -354,7 +354,7 @@ c_creaturetype* Materials_getRaceEx(DFHackObject* mat)
if(matSize > 0) if(matSize > 0)
{ {
c_creaturetype* buf; c_creaturetype* buf = NULL;
((*alloc_creaturetype_buffer_callback)(buf, matSize)); ((*alloc_creaturetype_buffer_callback)(buf, matSize));
@ -379,7 +379,7 @@ t_descriptor_color* Materials_getColor(DFHackObject* mat)
if(materials->color.size() > 0) if(materials->color.size() > 0)
{ {
t_descriptor_color* buf; t_descriptor_color* buf = NULL;
((*alloc_descriptor_buffer_callback)(buf, materials->color.size())); ((*alloc_descriptor_buffer_callback)(buf, materials->color.size()));
@ -403,7 +403,7 @@ t_matglossOther* Materials_getOther(DFHackObject* mat)
if(materials->other.size() > 0) if(materials->other.size() > 0)
{ {
t_matglossOther* buf; t_matglossOther* buf = NULL;
((*alloc_matgloss_other_buffer_callback)(buf, materials->other.size())); ((*alloc_matgloss_other_buffer_callback)(buf, materials->other.size()));
@ -427,7 +427,7 @@ t_matgloss* Materials_getAllDesc(DFHackObject* mat)
if(materials->alldesc.size() > 0) if(materials->alldesc.size() > 0)
{ {
t_matgloss* buf; t_matgloss* buf = NULL;
((*alloc_matgloss_buffer_callback)(buf, materials->alldesc.size())); ((*alloc_matgloss_buffer_callback)(buf, materials->alldesc.size()));

@ -102,7 +102,7 @@ t_hotkey* Position_ReadHotkeys(DFHackObject* pos)
{ {
if(pos != NULL) if(pos != NULL)
{ {
t_hotkey* buf; t_hotkey* buf = NULL;
(*alloc_t_hotkey_buffer_callback)(buf, NUM_HOTKEYS); (*alloc_t_hotkey_buffer_callback)(buf, NUM_HOTKEYS);
@ -144,7 +144,7 @@ t_screen* Position_getScreenTiles(DFHackObject* pos, int32_t width, int32_t heig
{ {
if(pos != NULL) if(pos != NULL)
{ {
t_screen* buf; t_screen* buf = NULL;
(*alloc_t_screen_buffer_callback)(buf, width * height); (*alloc_t_screen_buffer_callback)(buf, width * height);

@ -124,7 +124,7 @@ char* Translation_TranslateNameEnglish(DFHackObject* trans, const DFHack::t_name
if(nameTrans.size() > 0) if(nameTrans.size() > 0)
{ {
char* buf; char* buf = NULL;
(*alloc_char_buffer_callback)(buf, nameTrans.size()); (*alloc_char_buffer_callback)(buf, nameTrans.size());
@ -155,7 +155,7 @@ char* Translation_TranslateNameNonEnglish(DFHackObject* trans, const DFHack::t_n
if(nameTrans.size() > 0) if(nameTrans.size() > 0)
{ {
char* buf; char* buf = NULL;
(*alloc_char_buffer_callback)(buf, nameTrans.size()); (*alloc_char_buffer_callback)(buf, nameTrans.size());