1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-20 23:39:43 +00:00

CellList is done, cells can be looked up

- finished CellList in game/esm_reclists.hpp
- esm_reader: get*String() now removes trailing zero terminators from result
This commit is contained in:
Nicolay Korslund 2010-05-20 12:04:34 +02:00
parent 35f8e79d07
commit 46e09c5c75
4 changed files with 33 additions and 22 deletions

View file

@ -591,9 +591,16 @@ public:
// Read the next size bytes and return them as a string
std::string getString(int size)
{
// Not very optimized, but we'll fix that later
// Not very optimized, but we can fix that later
char *ptr = new char[size];
esm->read(ptr,size);
// Remove any zero terminators
for(int i=0; i<size; i++)
if(ptr[i] == 0)
size = i;
// Convert to std::string and return
std::string res(ptr,size);
delete[] ptr;
return res;

View file

@ -118,6 +118,9 @@ struct Cell
void load(ESMReader &esm)
{
// All cells have a name record, even nameless exterior cells.
name = esm.getHNString("NAME");
// Ignore this for now, it might mean we should delete the entire
// cell?
if(esm.isNextSub("DELE")) esm.skipHSub();

View file

@ -61,42 +61,42 @@ namespace ESMS
// separately.
struct CellList : RecList
{
// Just count them for now
// Total cell count. Used for statistics.
int count;
CellList() : count(0) {}
int getSize() { return count; }
/*
What to do here:
// List of interior cells. Indexed by cell name.
std::map<std::string,Cell> intCells;
load() reads the appropriate records to determine if this is an
interior or exterior cell. The old D code should be straight
forward to port here. Unlike the lists above, this struct
contains two lists, one for each cell type. We will have to hack
around again to get good indexing of exterior cells, but I think
a hash thingie like we did in D will work. An alternative is
just a map<map<>>, so we can do ext_cells[X][Y].whatever. Hmm, I
think I like that better actually.
*/
// List of exterior cells. Indexed as extCells[gridX][gridY].
std::map<int, std::map<int, Cell> > extCells;
void load(ESMReader &esm)
{
// All cells have a name record, even nameless exterior cells.
std::string id = esm.getHNString("NAME");
using namespace std;
cout << id << endl;
count++;
esm.skipRecord();
}
int getSize() { return count; }
// The cell itself takes care of all the hairy details
Cell cell;
cell.load(esm);
if(cell.data.flags & Cell::Interior)
{
// Store interior cell by name
intCells[cell.name] = cell;
}
else
{
// Store exterior cells by grid position
extCells[cell.data.gridX][cell.data.gridY] = cell;
}
}
};
/* We need special lists for:
Cells (in progress)
Magic effects
Skills
Dialog / Info combo

View file

@ -2,3 +2,4 @@
meshlist.txt
ogre.cfg
*_test
chris*