From e5c0576f354d2b5ecddbc1a6b94ec1bcc91cecda Mon Sep 17 00:00:00 2001 From: megamage Date: Fri, 27 Mar 2009 10:00:42 -0600 Subject: [PATCH] *Add and remove files. --HG-- branch : trunk --- src/{shared/Database => game}/DBCEnums.h | 0 src/{shared/Database => game}/DBCStores.cpp | 5 +- src/{shared/Database => game}/DBCStores.h | 87 +----- src/{shared/Database => game}/DBCStructure.h | 4 +- .../Database/DBCfmt.cpp => game/DBCfmt.h} | 5 + .../Database/{dbcfile.h => DBCFileLoader.h} | 19 +- src/shared/Database/DBCStore.h | 94 +++++++ src/shared/Database/dbcfile.cpp | 261 ------------------ 8 files changed, 117 insertions(+), 358 deletions(-) rename src/{shared/Database => game}/DBCEnums.h (100%) rename src/{shared/Database => game}/DBCStores.cpp (99%) rename src/{shared/Database => game}/DBCStores.h (77%) rename src/{shared/Database => game}/DBCStructure.h (99%) rename src/{shared/Database/DBCfmt.cpp => game/DBCfmt.h} (99%) rename src/shared/Database/{dbcfile.h => DBCFileLoader.h} (92%) create mode 100644 src/shared/Database/DBCStore.h delete mode 100644 src/shared/Database/dbcfile.cpp diff --git a/src/shared/Database/DBCEnums.h b/src/game/DBCEnums.h similarity index 100% rename from src/shared/Database/DBCEnums.h rename to src/game/DBCEnums.h diff --git a/src/shared/Database/DBCStores.cpp b/src/game/DBCStores.cpp similarity index 99% rename from src/shared/Database/DBCStores.cpp rename to src/game/DBCStores.cpp index ba61b028203..018b361616f 100644 --- a/src/shared/Database/DBCStores.cpp +++ b/src/game/DBCStores.cpp @@ -19,12 +19,11 @@ */ #include "DBCStores.h" -//#include "DataStore.h" #include "Policies/SingletonImp.h" #include "Log.h" #include "ProgressBar.h" -#include "DBCfmt.cpp" +#include "DBCfmt.h" #include @@ -162,7 +161,7 @@ template inline void LoadDBC(uint32& availableDbcLocales,barGoLink& bar, StoreProblemList& errlist, DBCStorage& storage, const std::string& dbc_path, const std::string& filename) { // compatibility format and C++ structure sizes - assert(DBCFile::GetFormatRecordSize(storage.GetFormat()) == sizeof(T) || LoadDBC_assert_print(DBCFile::GetFormatRecordSize(storage.GetFormat()),sizeof(T),filename)); + assert(DBCFileLoader::GetFormatRecordSize(storage.GetFormat()) == sizeof(T) || LoadDBC_assert_print(DBCFileLoader::GetFormatRecordSize(storage.GetFormat()),sizeof(T),filename)); std::string dbc_filename = dbc_path + filename; if(storage.Load(dbc_filename.c_str())) diff --git a/src/shared/Database/DBCStores.h b/src/game/DBCStores.h similarity index 77% rename from src/shared/Database/DBCStores.h rename to src/game/DBCStores.h index 3e8d3280596..4cad2b106c5 100644 --- a/src/shared/Database/DBCStores.h +++ b/src/game/DBCStores.h @@ -1,8 +1,6 @@ /* * Copyright (C) 2005-2009 MaNGOS * - * Copyright (C) 2008-2009 Trinity - * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or @@ -18,12 +16,11 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef DBCSTORES_H -#define DBCSTORES_H +#ifndef MANGOS_DBCSTORES_H +#define MANGOS_DBCSTORES_H #include "Common.h" -//#include "DataStore.h" -#include "dbcfile.h" +#include "Database/DBCStore.h" #include "DBCStructure.h" #include @@ -61,77 +58,6 @@ uint32 GetTalentInspectBitPosInTab(uint32 talentId); uint32 GetTalentTabInspectBitSize(uint32 talentTabId); uint32 const* /*[3]*/ GetTalentTabPages(uint32 cls); -template -class DBCStorage -{ - typedef std::list StringPoolList; - public: - explicit DBCStorage(const char *f) : nCount(0), fieldCount(0), fmt(f), indexTable(NULL), m_dataTable(NULL) { } - ~DBCStorage() { Clear(); } - - T const* LookupEntry(uint32 id) const { return (id>=nCount)?NULL:indexTable[id]; } - uint32 GetNumRows() const { return nCount; } - char const* GetFormat() const { return fmt; } - uint32 GetFieldCount() const { return fieldCount; } - - bool Load(char const* fn) - { - DBCFile dbc; - // Check if load was sucessful, only then continue - if(!dbc.Load(fn, fmt)) - return false; - - fieldCount = dbc.GetCols(); - m_dataTable = (T*)dbc.AutoProduceData(fmt,nCount,(char**&)indexTable); - m_stringPoolList.push_back(dbc.AutoProduceStrings(fmt,(char*)m_dataTable)); - - // error in dbc file at loading if NULL - return indexTable!=NULL; - } - - bool LoadStringsFrom(char const* fn) - { - // DBC must be already loaded using Load - if(!indexTable) - return false; - - DBCFile dbc; - // Check if load was successful, only then continue - if(!dbc.Load(fn, fmt)) - return false; - - m_stringPoolList.push_back(dbc.AutoProduceStrings(fmt,(char*)m_dataTable)); - - return true; - } - - void Clear() - { - if (!indexTable) - return; - - delete[] ((char*)indexTable); - indexTable = NULL; - delete[] ((char*)m_dataTable); - m_dataTable = NULL; - - while(!m_stringPoolList.empty()) - { - delete[] m_stringPoolList.front(); - m_stringPoolList.pop_front(); - } - nCount = 0; - } - - private: - uint32 nCount; - uint32 fieldCount; - char const* fmt; - T** indexTable; - T* m_dataTable; - StringPoolList m_stringPoolList; -}; - extern DBCStorage sAchievementStore; extern DBCStorage sAchievementCriteriaStore; extern DBCStorage sAreaStore;// recommend access using functions @@ -220,11 +146,10 @@ extern DBCStorage sWorldMapOverlayStore; void LoadDBCStores(const std::string& dataPath); // script support functions -TRINITY_DLL_SPEC DBCStorage const* GetSoundEntriesStore(); -TRINITY_DLL_SPEC DBCStorage const* GetSpellStore(); -TRINITY_DLL_SPEC DBCStorage const* GetSpellRangeStore(); +TRINITY_DLL_SPEC DBCStorage const* GetSoundEntriesStore(); +TRINITY_DLL_SPEC DBCStorage const* GetSpellStore(); +TRINITY_DLL_SPEC DBCStorage const* GetSpellRangeStore(); TRINITY_DLL_SPEC DBCStorage const* GetFactionStore(); TRINITY_DLL_SPEC DBCStorage const* GetItemDisplayStore(); TRINITY_DLL_SPEC DBCStorage const* GetCreatureDisplayStore(); #endif - diff --git a/src/shared/Database/DBCStructure.h b/src/game/DBCStructure.h similarity index 99% rename from src/shared/Database/DBCStructure.h rename to src/game/DBCStructure.h index 32f78faa509..e9370c3e4ad 100644 --- a/src/shared/Database/DBCStructure.h +++ b/src/game/DBCStructure.h @@ -18,8 +18,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef DBCSTRUCTURE_H -#define DBCSTRUCTURE_H +#ifndef MANGOS_DBCSTRUCTURE_H +#define MANGOS_DBCSTRUCTURE_H #include "DBCEnums.h" #include "Platform/Define.h" diff --git a/src/shared/Database/DBCfmt.cpp b/src/game/DBCfmt.h similarity index 99% rename from src/shared/Database/DBCfmt.cpp rename to src/game/DBCfmt.h index fdaaac14f66..f7d8538bf3b 100644 --- a/src/shared/Database/DBCfmt.cpp +++ b/src/game/DBCfmt.h @@ -18,6 +18,9 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#ifndef MANGOS_DBCSFRM_H +#define MANGOS_DBCSFRM_H + const char Achievementfmt[]="niixxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxiixixxxxxxxxxxxxxxxxxxxi"; const char AchievementCriteriafmt[]="niiiiiiiixxxxxxxxxxxxxxxxxiixix"; const char AreaTableEntryfmt[]="iiinixxxxxissssssssssssssssxixxxxxxx"; @@ -99,3 +102,5 @@ const char VehicleSeatEntryfmt[]="niiffffffffffiiiiiifffffffiiifffiiiiiiiffiiiii const char WorldMapAreaEntryfmt[]="xinxffffix"; const char WorldSafeLocsEntryfmt[]="nifffxxxxxxxxxxxxxxxxx"; const char WorldMapOverlayEntryfmt[]="nxiiiixxxxxxxxxxx"; + +#endif \ No newline at end of file diff --git a/src/shared/Database/dbcfile.h b/src/shared/Database/DBCFileLoader.h similarity index 92% rename from src/shared/Database/dbcfile.h rename to src/shared/Database/DBCFileLoader.h index e94417b4371..13562148dfc 100644 --- a/src/shared/Database/dbcfile.h +++ b/src/shared/Database/DBCFileLoader.h @@ -1,8 +1,6 @@ /* * Copyright (C) 2005-2009 MaNGOS * - * Copyright (C) 2008-2009 Trinity - * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or @@ -18,8 +16,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef DBCFILE_H -#define DBCFILE_H +#ifndef DBC_FILE_LOADER_H +#define DBC_FILE_LOADER_H #include "Platform/Define.h" #include "Utilities/ByteConverter.h" #include @@ -37,11 +35,11 @@ enum FT_LOGIC='l' //Logical (boolean) }; -class DBCFile +class DBCFileLoader { public: - DBCFile(); - ~DBCFile(); + DBCFileLoader(); + ~DBCFileLoader(); bool Load(const char *filename, const char *fmt); @@ -77,11 +75,11 @@ class DBCFile } private: - Record(DBCFile &file_, unsigned char *offset_): offset(offset_), file(file_) {} + Record(DBCFileLoader &file_, unsigned char *offset_): offset(offset_), file(file_) {} unsigned char *offset; - DBCFile &file; + DBCFileLoader &file; - friend class DBCFile; + friend class DBCFileLoader; }; @@ -107,4 +105,3 @@ class DBCFile unsigned char *stringTable; }; #endif - diff --git a/src/shared/Database/DBCStore.h b/src/shared/Database/DBCStore.h new file mode 100644 index 00000000000..523d5c5a0b3 --- /dev/null +++ b/src/shared/Database/DBCStore.h @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2005-2009 MaNGOS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef DBCSTORE_H +#define DBCSTORE_H + +#include "DBCFileLoader.h" + +template +class DBCStorage +{ + typedef std::list StringPoolList; + public: + explicit DBCStorage(const char *f) : nCount(0), fieldCount(0), fmt(f), indexTable(NULL), m_dataTable(NULL) { } + ~DBCStorage() { Clear(); } + + T const* LookupEntry(uint32 id) const { return (id>=nCount)?NULL:indexTable[id]; } + uint32 GetNumRows() const { return nCount; } + char const* GetFormat() const { return fmt; } + uint32 GetFieldCount() const { return fieldCount; } + + bool Load(char const* fn) + { + DBCFileLoader dbc; + // Check if load was sucessful, only then continue + if(!dbc.Load(fn, fmt)) + return false; + + fieldCount = dbc.GetCols(); + m_dataTable = (T*)dbc.AutoProduceData(fmt,nCount,(char**&)indexTable); + m_stringPoolList.push_back(dbc.AutoProduceStrings(fmt,(char*)m_dataTable)); + + // error in dbc file at loading if NULL + return indexTable!=NULL; + } + + bool LoadStringsFrom(char const* fn) + { + // DBC must be already loaded using Load + if(!indexTable) + return false; + + DBCFileLoader dbc; + // Check if load was successful, only then continue + if(!dbc.Load(fn, fmt)) + return false; + + m_stringPoolList.push_back(dbc.AutoProduceStrings(fmt,(char*)m_dataTable)); + + return true; + } + + void Clear() + { + if (!indexTable) + return; + + delete[] ((char*)indexTable); + indexTable = NULL; + delete[] ((char*)m_dataTable); + m_dataTable = NULL; + + while(!m_stringPoolList.empty()) + { + delete[] m_stringPoolList.front(); + m_stringPoolList.pop_front(); + } + nCount = 0; + } + + private: + uint32 nCount; + uint32 fieldCount; + char const* fmt; + T** indexTable; + T* m_dataTable; + StringPoolList m_stringPoolList; +}; +#endif diff --git a/src/shared/Database/dbcfile.cpp b/src/shared/Database/dbcfile.cpp deleted file mode 100644 index 1de121bb17d..00000000000 --- a/src/shared/Database/dbcfile.cpp +++ /dev/null @@ -1,261 +0,0 @@ -/* - * Copyright (C) 2005-2009 MaNGOS - * - * Copyright (C) 2008-2009 Trinity - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include -#include -#include - -#include "dbcfile.h" - -DBCFile::DBCFile() -{ - data = NULL; - fieldsOffset = NULL; -} - -bool DBCFile::Load(const char *filename, const char *fmt) -{ - - uint32 header; - if(data) - { - delete [] data; - data=NULL; - } - - FILE * f=fopen(filename,"rb"); - if(!f)return false; - - if(fread(&header,4,1,f)!=1) // Number of records - return false; - - EndianConvert(header); - if(header!=0x43424457) - return false; //'WDBC' - - if(fread(&recordCount,4,1,f)!=1) // Number of records - return false; - - EndianConvert(recordCount); - - if(fread(&fieldCount,4,1,f)!=1) // Number of fields - return false; - - EndianConvert(fieldCount); - - if(fread(&recordSize,4,1,f)!=1) // Size of a record - return false; - - EndianConvert(recordSize); - - if(fread(&stringSize,4,1,f)!=1) // String size - return false; - - EndianConvert(stringSize); - - fieldsOffset = new uint32[fieldCount]; - fieldsOffset[0] = 0; - for(uint32 i = 1; i < fieldCount; i++) - { - fieldsOffset[i] = fieldsOffset[i - 1]; - if (fmt[i - 1] == 'b' || fmt[i - 1] == 'X') // byte fields - fieldsOffset[i] += 1; - else // 4 byte fields (int32/float/strings) - fieldsOffset[i] += 4; - } - - data = new unsigned char[recordSize*recordCount+stringSize]; - stringTable = data + recordSize*recordCount; - - if(fread(data,recordSize*recordCount+stringSize,1,f)!=1) - return false; - - fclose(f); - return true; -} - -DBCFile::~DBCFile() -{ - if(data) - delete [] data; - if(fieldsOffset) - delete [] fieldsOffset; -} - -DBCFile::Record DBCFile::getRecord(size_t id) -{ - assert(data); - return Record(*this, data + id*recordSize); -} - -uint32 DBCFile::GetFormatRecordSize(const char * format,int32* index_pos) -{ - uint32 recordsize = 0; - int32 i = -1; - for(uint32 x=0; format[x];++x) - switch(format[x]) - { - case FT_FLOAT: - case FT_INT: - recordsize+=4; - break; - case FT_STRING: - recordsize+=sizeof(char*); - break; - case FT_SORT: - i=x; - break; - case FT_IND: - i=x; - recordsize+=4; - break; - case FT_BYTE: - recordsize += 1; - break; - } - - if(index_pos) - *index_pos = i; - - return recordsize; -} - -char* DBCFile::AutoProduceData(const char* format, uint32& records, char**& indexTable) -{ - /* - format STRING, NA, FLOAT,NA,INT <=> - struct{ - char* field0, - float field1, - int field2 - }entry; - - this func will generate entry[rows] data; - */ - - typedef char * ptr; - if(strlen(format)!=fieldCount) - return NULL; - - //get struct size and index pos - int32 i; - uint32 recordsize=GetFormatRecordSize(format,&i); - - if(i>=0) - { - uint32 maxi=0; - //find max index - for(uint32 y=0;ymaxi)maxi=ind; - } - - ++maxi; - records=maxi; - indexTable=new ptr[maxi]; - memset(indexTable,0,maxi*sizeof(ptr)); - } - else - { - records = recordCount; - indexTable = new ptr[recordCount]; - } - - char* dataTable= new char[recordCount*recordsize]; - - uint32 offset=0; - - for(uint32 y =0;y=0) - { - indexTable[getRecord(y).getUInt(i)]=&dataTable[offset]; - } - else - indexTable[y]=&dataTable[offset]; - - for(uint32 x=0;x