From 6f908f8776531554f5269ee99c8acc486fa4491a Mon Sep 17 00:00:00 2001 From: leandor Date: Wed, 2 Nov 2016 03:54:02 -0300 Subject: [PATCH] (#6) Cleaned `TES4Record` of Skyrim dependencies Moved Skyrim's specific String functionality that was located in the generic master record (TES4Record) to the Skyrim ModFile implementation, as it's only used from records belonging to Skyrim's implementation. For that I had to break a cyclic dependence on TES5Record <-> TES5File by introducing a new zero sized abstract class TES5ModFile that only publishes the method required to access the StringsLookup implementation. As a result of this I can remove the inclusion of SkyrimCommon.h from `TES4Record.cpp` --- src/common/TES4Record.cpp | 27 ++---------------- src/common/TES4Record.h | 5 ---- src/game/Skyrim/TES5File.cpp | 13 +++++++-- src/game/Skyrim/TES5File.h | 17 +++++++++-- src/game/Skyrim/TES5ModFile.h | 54 +++++++++++++++++++++++++++++++++++ 5 files changed, 81 insertions(+), 35 deletions(-) create mode 100644 src/game/Skyrim/TES5ModFile.h diff --git a/src/common/TES4Record.cpp b/src/common/TES4Record.cpp index 4e21c1e..02faec2 100644 --- a/src/common/TES4Record.cpp +++ b/src/common/TES4Record.cpp @@ -35,7 +35,6 @@ * ***** END LICENSE BLOCK ***** */ #include "Common.h" #include "TES4Record.h" -#include "Skyrim\SkyrimCommon.h" // StringLookups #include "zlib.h" TES4Record::TES4HEDR::TES4HEDR(float _version, uint32_t _numRecords, uint32_t _nextObject): @@ -66,15 +65,13 @@ bool TES4Record::TES4HEDR::operator != (const TES4HEDR &other) const TES4Record::TES4Record(unsigned char *_recData): Record(_recData), - formVersion(0), - LookupStrings(NULL) + formVersion(0) { memset(&versionControl2[0], 0x00, 2); } TES4Record::TES4Record(TES4Record *srcRecord): - Record(), - LookupStrings(NULL) + Record() { if(srcRecord == NULL) return; @@ -110,7 +107,6 @@ TES4Record::TES4Record(TES4Record *srcRecord): TES4Record::~TES4Record() { - delete LookupStrings; } bool TES4Record::VisitFormIDs(FormIDOp &op) @@ -136,25 +132,6 @@ void TES4Record::IsESM(bool value) SETBIT(flags, fIsESM, value); } -bool TES4Record::IsLookupStrings() const -{ - // fIsTurnOffFire = LookupStrings - return IsLoaded() ? (flags & fIsTurnOffFire) != 0 : false; -} - -void TES4Record::IsLookupStrings(bool value) -{ - SETBIT(flags, fIsTurnOffFire, value); -} - -void TES4Record::LoadStringLookups(char * FileName) -{ - if (LookupStrings != NULL) - return; - - LookupStrings = new StringLookups; - LookupStrings->Open(FileName); -} uint32_t TES4Record::GetType() { diff --git a/src/common/TES4Record.h b/src/common/TES4Record.h index 00780f4..0955dd9 100644 --- a/src/common/TES4Record.h +++ b/src/common/TES4Record.h @@ -76,7 +76,6 @@ class TES4Record : public Record // Skyrim RawRecord INTV; //Unknown RawRecord INCC; //Unknown - StringLookups *LookupStrings; TES4Record(unsigned char *_recData=NULL); TES4Record(TES4Record *srcRecord); @@ -86,10 +85,6 @@ class TES4Record : public Record bool IsESM() const; void IsESM(bool value); - bool IsLookupStrings() const; - void IsLookupStrings(bool value); - - void LoadStringLookups(char * FileName); uint32_t GetFieldAttribute(DEFAULTED_FIELD_IDENTIFIERS, uint32_t WhichAttribute=0); void * GetField(DEFAULTED_FIELD_IDENTIFIERS, void **FieldValues=NULL); diff --git a/src/game/Skyrim/TES5File.cpp b/src/game/Skyrim/TES5File.cpp index e488c36..af9b8d6 100644 --- a/src/game/Skyrim/TES5File.cpp +++ b/src/game/Skyrim/TES5File.cpp @@ -37,17 +37,18 @@ #include "common/Common.h" #include "common/GenericRecord.h" #include "TES5File.h" +#include "TES5Record.h" #include "SkyrimCommon.h" TES5File::TES5File(Collection *_Parent, char * FileName, char * ModName, const uint32_t _flags): - ModFile(_Parent, FileName, ModName, _flags) + TES5ModFile(_Parent, FileName, ModName, _flags), _lookupStrings(NULL) { // } TES5File::~TES5File() { - // + delete _lookupStrings; } void TES5File::SetFilter(bool inclusive, boost::unordered_set &RecordTypes, boost::unordered_set &WorldSpaces) { @@ -56,6 +57,11 @@ void TES5File::SetFilter(bool inclusive, boost::unordered_set &RecordT filter_wspaces = WorldSpaces; } +StringLookups * TES5File::LookupStrings() const +{ + return this->_lookupStrings; +} + int32_t TES5File::LoadTES4() { if(TES4.IsLoaded() || !Open()) @@ -230,7 +236,8 @@ int32_t TES5File::Load(RecordOp &read_parser, RecordOp &indexer, std::vectorOpen(FileName); Flags.LoadedGRUPs = true; unsigned char *group_buffer_end = NULL; diff --git a/src/game/Skyrim/TES5File.h b/src/game/Skyrim/TES5File.h index dec3842..e7d3da8 100644 --- a/src/game/Skyrim/TES5File.h +++ b/src/game/Skyrim/TES5File.h @@ -40,6 +40,11 @@ #include "common/GenericRecord.h" #include "GRUPRecord.h" + +#include "TES5Record.h" +#include "TES5ModFile.h" +#include "SkyrimCommon.h" + // Only need to include Top Types #include "Records/AACTRecord.h" #include "Records/ACTIRecord.h" @@ -161,13 +166,17 @@ // Helper macros +#ifndef GRUP #define GRUP(Type) \ TES5GRUPRecords Type +#endif + +#ifndef GRUP_EDID #define GRUP_EDID(Type) \ TES5GRUPRecords Type +#endif - -class TES5File : public ModFile +class TES5File : public TES5ModFile { public: GRUP(AACT); @@ -304,6 +313,10 @@ class TES5File : public ModFile void VisitAllRecords(RecordOp &op); void VisitRecords(const uint32_t &RecordType, RecordOp &op); + + StringLookups *LookupStrings() const; + private: + StringLookups* _lookupStrings; }; // Clean up diff --git a/src/game/Skyrim/TES5ModFile.h b/src/game/Skyrim/TES5ModFile.h new file mode 100644 index 0000000..49a58ee --- /dev/null +++ b/src/game/Skyrim/TES5ModFile.h @@ -0,0 +1,54 @@ +/* ***** BEGIN LICENSE BLOCK ***** +* Version: MPL 1.1/GPL 2.0/LGPL 2.1 +* +* The contents of this file are subject to the Mozilla Public License Version +* 1.1 (the "License"); you may not use this file except in compliance with +* the License. You may obtain a copy of the License at +* http://www.mozilla.org/MPL/ +* +* Software distributed under the License is distributed on an "AS IS" basis, +* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License +* for the specific language governing rights and limitations under the +* License. +* +* The Original Code is CBash code. +* +* The Initial Developer of the Original Code is +* Waruddar. +* Portions created by the Initial Developer are Copyright (C) 2010 +* the Initial Developer. All Rights Reserved. +* +* Contributor(s): +* +* Alternatively, the contents of this file may be used under the terms of +* either the GNU General Public License Version 2 or later (the "GPL"), or +* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), +* in which case the provisions of the GPL or the LGPL are applicable instead +* of those above. If you wish to allow use of your version of this file only +* under the terms of either the GPL or the LGPL, and not to allow others to +* use your version of this file under the terms of the MPL, indicate your +* decision by deleting the provisions above and replace them with the notice +* and other provisions required by the GPL or the LGPL. If you do not delete +* the provisions above, a recipient may use your version of this file under +* the terms of any one of the MPL, the GPL or the LGPL. +* +* ***** END LICENSE BLOCK ***** */ + +#ifndef __CBASH_TES5_MODFILE__ +#define __CBASH_TES5_MODFILE__ + +#pragma once + +#include "common/Common.h" +#include "common/ModFile.h" +#include "SkyrimCommon.h" + +class TES5ModFile : public ModFile +{ +public: + using ModFile::ModFile; + + virtual StringLookups *LookupStrings() const abstract; +}; + +#endif \ No newline at end of file