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

Main program now stores ESM data in memory

This commit is contained in:
Nicolay Korslund 2010-05-17 17:35:42 +02:00
parent ccfc63ab9f
commit e534431022
6 changed files with 207 additions and 6 deletions

View file

@ -11,7 +11,7 @@ set(BSA bsa/bsa_archive.cpp bsa/bsa_file.cpp)
set(NIF nif/nif_file.cpp nifogre/ogre_nif_loader.cpp) set(NIF nif/nif_file.cpp nifogre/ogre_nif_loader.cpp)
set(TOOLS tools/stringops.cpp) set(TOOLS tools/stringops.cpp)
set(MANGLE_VFS mangle/vfs/servers/ogre_vfs.cpp) set(MANGLE_VFS mangle/vfs/servers/ogre_vfs.cpp)
set(GAME game/main.cpp) set(GAME game/main.cpp game/esm_store.cpp)
# Platform specific # Platform specific
if (WIN32) if (WIN32)

View file

@ -222,8 +222,8 @@ public:
else spf = SF_Other; else spf = SF_Other;
} }
/// Load ES file from a new stream, parses the header. Calls close() /// Load ES file from a new stream, parses the header. Closes the
/// automatically. /// currently open file first, if any.
void open(Mangle::Stream::StreamPtr _esm, const std::string &name) void open(Mangle::Stream::StreamPtr _esm, const std::string &name)
{ {
openRaw(_esm, name); openRaw(_esm, name);

184
game/esm_store.cpp Normal file
View file

@ -0,0 +1,184 @@
#include <map>
#include <iostream>
#include "esm_store.hpp"
using namespace ESM;
using namespace std;
struct RecList
{
virtual void load(ESMReader &esm) = 0;
virtual int getSize() = 0;
virtual const string& getName() = 0;
};
/* Lists all the list types. Mostly used for quick lookup on
loading. The index is the record name (4 chars) parsed as a 32 bit
int. Eg. REC_ACTI, REC_BOOK etc. See esm/records.hpp for the
complete list.
*/
typedef map<int,RecList*> RecListList;
RecListList recLists;
template <int RecID>
struct RecListIDT : RecList
{
// Store ourselves in the list of all lists
RecListIDT() { recLists[RecID] = this; }
};
template <int RecID, typename X>
struct RecListT : RecListIDT<RecID>
{
typedef map<string,X> MapType;
MapType list;
string listName;
RecListT(const string &name) : listName(name) {}
void load(ESMReader &esm)
{
string id = esm.getHNString("NAME");
X &ref = list[id];
ref.load(esm);
}
int getSize() { return list.size(); }
const string& getName() { return listName; }
};
// The only difference to the above is a slight change to the load()
// function. We might merge these together later, and store the id in
// all the structs.
template <int RecID, typename X>
struct RecIDListT : RecListIDT<RecID>
{
typedef map<string,X> MapType;
MapType list;
string listName;
RecIDListT(const string &name) : listName(name) {}
void load(ESMReader &esm)
{
string id = esm.getHNString("NAME");
X &ref = list[id];
ref.id = id;
ref.load(esm);
}
int getSize() { return list.size(); }
const string& getName() { return listName; }
};
// Cells aren't simply indexed by name. Exterior cells are treated
// separately.
struct CellList : RecListIDT<REC_CELL>
{
// Just count them for now
int count;
string listName;
CellList() { listName = "Cells"; }
void load(ESMReader &esm)
{
count++;
esm.skipRecord();
}
int getSize() { return count; }
const string& getName() { return listName; }
};
/* We need special lists for:
Cells (partially done)
Magic effects
Skills
Dialog / Info combo
Scripts
Land
Path grids
Land textures
*/
RecListT<REC_ACTI, Activator> activators ("Activators");
RecListT<REC_ALCH, Potion> potions ("Potions");
RecListT<REC_APPA, Apparatus> appas ("Apparatuses");
RecListT<REC_ARMO, Armor> armors ("Armors");
RecListT<REC_BODY, BodyPart> bodyParts ("Body parts");
RecListT<REC_BOOK, Book> books ("Books");
RecListT<REC_BSGN, BirthSign> birthSigns ("Birth signs");
CellList cells;
RecListT<REC_CLAS, Class> classes ("Classes");
RecListT<REC_CLOT, Clothing> clothes ("Clothes");
RecListT<REC_CNTC, LoadCNTC> contChange ("Container changes");
RecListT<REC_CONT, Container> containers ("Containers");
RecListT<REC_CREA, Creature> creatures ("Creatures");
RecListT<REC_CREC, LoadCREC> creaChange ("Creature changes");
RecListT<REC_DIAL, Dialogue> dialogs ("Dialogues");
RecListT<REC_DOOR, Door> doors ("Doors");
RecListT<REC_ENCH, Enchantment> enchants ("Enchantments");
RecListT<REC_FACT, Faction> factions ("Factions");
RecListT<REC_GLOB, Global> globals ("Globals");
RecIDListT<REC_GMST,GameSetting>gameSettings ("Game settings");
//RecListT<REC_INFO, DialInfo> dialInfos ("Dialog entries");
RecListT<REC_INGR, Ingredient> ingreds ("Ingredients");
//RecListT<REC_LAND, Land> lands ("Land data");
RecListT<REC_LEVC, CreatureLevList> creatureLists("Creature leveled lists");
RecListT<REC_LEVI, ItemLevList> itemLists ("Item leveled lists");
RecListT<REC_LIGH, Light> lights ("Lights");
RecListT<REC_LOCK, Tool> lockpicks ("Lockpicks");
//RecListT<REC_LTEX, LandTexture> landTexts ("Land textures");
//RecListT<REC_MGEF, MagicEffect> magicEffects ("Magic effects");
RecListT<REC_MISC, Misc> miscItems ("Misc items");
RecListT<REC_NPC_, NPC> npcs ("NPCs");
RecListT<REC_NPCC, LoadNPCC> npcChange ("NPC changes");
//RecListT<REC_PGRD, PathGrid> pathgrids ("Path grids");
RecListT<REC_PROB, Tool> probes ("Probes");
RecListT<REC_RACE, Race> races ("Races");
RecListT<REC_REGN, Region> regions ("Regions");
RecListT<REC_REPA, Tool> repairs ("Repair items");
//RecListT<REC_SCPT, Script> scripts ("Scripts");
//RecListT<REC_SKIL, Skill> skills ("Skills");
RecListT<REC_SNDG, SoundGenerator> soundGens ("Sound generators");
RecListT<REC_SOUN, Sound> sounds ("Sounds");
RecListT<REC_SPEL, Spell> spells ("Spells");
RecListT<REC_SSCR, StartScript> startScripts ("Start scripts");
RecListT<REC_STAT, Static> statics ("Statics");
RecListT<REC_WEAP, Weapon> weapons ("Weapons");
void storeESM(ESMReader &esm)
{
// Loop through all records
while(esm.hasMoreRecs())
{
NAME n = esm.getRecName();
esm.getRecHeader();
// Look up the record type.
RecListList::iterator it = recLists.find(n.val);
if(it == recLists.end())
{
// Not found (this would be an error later)
esm.skipRecord();
continue;
}
// Load it
it->second->load(esm);
}
cout << "\n" << recLists.size() << " record types:\n";
for(RecListList::iterator it = recLists.begin(); it != recLists.end(); it++)
cout << " " << it->second->getName() << ": " << it->second->getSize() << endl;
}

8
game/esm_store.hpp Normal file
View file

@ -0,0 +1,8 @@
#ifndef _GAME_ESM_STORE_H
#define _GAME_ESM_STORE_H
#include "esm/records.hpp"
void storeESM(ESM::ESMReader &esm);
#endif

View file

@ -1,7 +1,7 @@
#include <iostream> #include <iostream>
#include "bsa/bsa_archive.h" #include "bsa/bsa_archive.h"
#include "esm/records.hpp" #include "esm_store.hpp"
#include "Ogre.h" #include "Ogre.h"
@ -34,9 +34,11 @@ void maintest()
cout << "Adding " << bsaFile << endl; cout << "Adding " << bsaFile << endl;
addBSA(bsaFile); addBSA(bsaFile);
cout << "Loading ESM " << esmFile << " (header only)\n"; cout << "Loading ESM " << esmFile << "\n";
ESM::ESMReader esm; ESM::ESMReader esm;
esm.open(esmFile); esm.open(esmFile);
storeESM(esm);
esm.close();
cout << "\nThat's all for now!\n"; cout << "\nThat's all for now!\n";
} }

View file

@ -1,7 +1,13 @@
#include "ogre_mesh_common.cpp" #include "ogre_common.cpp"
void C::doTest() void C::doTest()
{ {
SkeletonManager &skm = SkeletonManager::getSingleton();
SkeletonPtr skp = skm.create("MySkel", "General");
cout << "hello\n";
/*
MeshPtr msh = makeMesh("mesh1"); MeshPtr msh = makeMesh("mesh1");
// Display the mesh // Display the mesh
@ -11,4 +17,5 @@ void C::doTest()
node->attachObject(ent); node->attachObject(ent);
node->setPosition(0,0,4); node->setPosition(0,0,4);
} }
*/
} }