From 8c21616ce5013ebe704b69c0212543106a2ad0b2 Mon Sep 17 00:00:00 2001 From: Nicolay Korslund Date: Mon, 17 May 2010 20:59:15 +0200 Subject: [PATCH] ESM storage, take two --- game/esm_reclists.hpp | 88 ++++++++++++++++++++++ game/esm_store.cpp | 170 +++++------------------------------------- game/esm_store.hpp | 116 +++++++++++++++++++++++++++- game/main.cpp | 3 +- 4 files changed, 223 insertions(+), 154 deletions(-) create mode 100644 game/esm_reclists.hpp diff --git a/game/esm_reclists.hpp b/game/esm_reclists.hpp new file mode 100644 index 000000000..6fa236a36 --- /dev/null +++ b/game/esm_reclists.hpp @@ -0,0 +1,88 @@ +#ifndef _GAME_ESM_RECLISTS_H +#define _GAME_ESM_RECLISTS_H + +#include "esm/records.hpp" +#include +#include + +namespace ESMS +{ + using namespace ESM; + + struct RecList + { + virtual void load(ESMReader &esm) = 0; + virtual int getSize() = 0; + }; + + typedef std::map RecListList; + + template + struct RecListT : RecList + { + typedef std::map MapType; + + MapType list; + + void load(ESMReader &esm) + { + std::string id = esm.getHNString("NAME"); + + X &ref = list[id]; + ref.load(esm); + } + + int getSize() { return list.size(); } + }; + + // 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 + struct RecIDListT : RecList + { + typedef std::map MapType; + + MapType list; + + void load(ESMReader &esm) + { + std::string id = esm.getHNString("NAME"); + + X &ref = list[id]; + ref.id = id; + ref.load(esm); + } + + int getSize() { return list.size(); } + }; + + // Cells aren't simply indexed by name. Exterior cells are treated + // separately. + struct CellList : RecList + { + // Just count them for now + int count; + + void load(ESMReader &esm) + { + count++; + esm.skipRecord(); + } + + int getSize() { return count; } + }; + + /* We need special lists for: + + Cells (in progress) + Magic effects + Skills + Dialog / Info combo + Scripts + Land + Path grids + Land textures + */ +} +#endif diff --git a/game/esm_store.cpp b/game/esm_store.cpp index 1544719de..a532fa542 100644 --- a/game/esm_store.cpp +++ b/game/esm_store.cpp @@ -1,163 +1,23 @@ -#include +#include #include #include "esm_store.hpp" -using namespace ESM; using namespace std; +using namespace ESM; +using namespace ESMS; -struct RecList +static string toStr(int i) { - virtual void load(ESMReader &esm) = 0; - virtual int getSize() = 0; - virtual const string& getName() = 0; -}; + char name[5]; + *((int*)name) = i; + name[4] = 0; + return std::string(name); +} -/* 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 RecListList; -RecListList recLists; - -template -struct RecListIDT : RecList +void ESMStore::load(ESMReader &esm) { - // Store ourselves in the list of all lists - RecListIDT() { recLists[RecID] = this; } -}; + set missing; -template -struct RecListT : RecListIDT -{ - typedef map 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 -struct RecIDListT : RecListIDT -{ - typedef map 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 -{ - // 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 activators ("Activators"); -RecListT potions ("Potions"); -RecListT appas ("Apparatuses"); -RecListT armors ("Armors"); -RecListT bodyParts ("Body parts"); -RecListT books ("Books"); -RecListT birthSigns ("Birth signs"); -CellList cells; -RecListT classes ("Classes"); -RecListT clothes ("Clothes"); -RecListT contChange ("Container changes"); -RecListT containers ("Containers"); -RecListT creatures ("Creatures"); -RecListT creaChange ("Creature changes"); -RecListT dialogs ("Dialogues"); -RecListT doors ("Doors"); -RecListT enchants ("Enchantments"); -RecListT factions ("Factions"); -RecListT globals ("Globals"); -RecIDListTgameSettings ("Game settings"); -//RecListT dialInfos ("Dialog entries"); -RecListT ingreds ("Ingredients"); -//RecListT lands ("Land data"); -RecListT creatureLists("Creature leveled lists"); -RecListT itemLists ("Item leveled lists"); -RecListT lights ("Lights"); -RecListT lockpicks ("Lockpicks"); -//RecListT landTexts ("Land textures"); -//RecListT magicEffects ("Magic effects"); -RecListT miscItems ("Misc items"); -RecListT npcs ("NPCs"); -RecListT npcChange ("NPC changes"); -//RecListT pathgrids ("Path grids"); -RecListT probes ("Probes"); -RecListT races ("Races"); -RecListT regions ("Regions"); -RecListT repairs ("Repair items"); -//RecListT scripts ("Scripts"); -//RecListT skills ("Skills"); -RecListT soundGens ("Sound generators"); -RecListT sounds ("Sounds"); -RecListT spells ("Spells"); -RecListT startScripts ("Start scripts"); -RecListT statics ("Statics"); -RecListT weapons ("Weapons"); - -void storeESM(ESMReader &esm) -{ // Loop through all records while(esm.hasMoreRecs()) { @@ -171,6 +31,7 @@ void storeESM(ESMReader &esm) { // Not found (this would be an error later) esm.skipRecord(); + missing.insert(n.toString()); continue; } @@ -180,5 +41,10 @@ void storeESM(ESMReader &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; + cout << " " << toStr(it->first) << ": " << it->second->getSize() << endl; + cout << "\nNot implemented yet: "; + for(set::iterator it = missing.begin(); + it != missing.end(); it++ ) + cout << *it << " "; + cout << endl; } diff --git a/game/esm_store.hpp b/game/esm_store.hpp index a074c90b7..57c902d0a 100644 --- a/game/esm_store.hpp +++ b/game/esm_store.hpp @@ -2,7 +2,121 @@ #define _GAME_ESM_STORE_H #include "esm/records.hpp" +#include "esm_reclists.hpp" -void storeESM(ESM::ESMReader &esm); +namespace ESMS +{ + using namespace ESM; + + struct ESMStore + { + /* Lists all the list types. Mostly used for quick lookup on + loading. The key is the record name (4 chars) parsed as a 32 + bit int. See esm/records.hpp for the complete list. + */ + RecListList recLists; + + // Each individual list + RecListT activators; + RecListT potions; + RecListT appas; + RecListT armors; + RecListT bodyParts; + RecListT books; + RecListT birthSigns; + RecListT classes; + RecListT clothes; + RecListT contChange; + RecListT containers; + RecListT creatures; + RecListT creaChange; + RecListT dialogs; + RecListT doors; + RecListT enchants; + RecListT factions; + RecListT globals; + RecListT ingreds; + RecListT creatureLists; + RecListT itemLists; + RecListT lights; + RecListT lockpicks; + RecListT miscItems; + RecListT npcs; + RecListT npcChange; + RecListT probes; + RecListT races; + RecListT regions; + RecListT repairs; + RecListT soundGens; + RecListT sounds; + RecListT spells; + RecListT startScripts; + RecListT statics; + RecListT weapons; + + // Lists that need special rules + CellList cells; + RecIDListT gameSettings; + //RecListT dialInfos; + //RecListT lands; + //RecListT landTexts; + //RecListT magicEffects; + //RecListT