Skip to content
This repository has been archived by the owner on Sep 5, 2020. It is now read-only.

Commit

Permalink
(#6) Cleaned TES4Record of Skyrim dependencies
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
leandor committed Jul 1, 2017
1 parent 68a1a9b commit 6f908f8
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 35 deletions.
27 changes: 2 additions & 25 deletions src/common/TES4Record.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -110,7 +107,6 @@ TES4Record::TES4Record(TES4Record *srcRecord):

TES4Record::~TES4Record()
{
delete LookupStrings;
}

bool TES4Record::VisitFormIDs(FormIDOp &op)
Expand All @@ -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()
{
Expand Down
5 changes: 0 additions & 5 deletions src/common/TES4Record.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
13 changes: 10 additions & 3 deletions src/game/Skyrim/TES5File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t> &RecordTypes, boost::unordered_set<FORMID> &WorldSpaces) {
Expand All @@ -56,6 +57,11 @@ void TES5File::SetFilter(bool inclusive, boost::unordered_set<uint32_t> &RecordT
filter_wspaces = WorldSpaces;
}

StringLookups * TES5File::LookupStrings() const
{
return this->_lookupStrings;
}

int32_t TES5File::LoadTES4()
{
if(TES4.IsLoaded() || !Open())
Expand Down Expand Up @@ -230,7 +236,8 @@ int32_t TES5File::Load(RecordOp &read_parser, RecordOp &indexer, std::vector<For
}

// Load translation strings
TES4.LoadStringLookups(FileName);
_lookupStrings = new StringLookups();
_lookupStrings->Open(FileName);

Flags.LoadedGRUPs = true;
unsigned char *group_buffer_end = NULL;
Expand Down
17 changes: 15 additions & 2 deletions src/game/Skyrim/TES5File.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -161,13 +166,17 @@


// Helper macros
#ifndef GRUP
#define GRUP(Type) \
TES5GRUPRecords<Sk::Type##Record, REV32(Type), 5> Type
#endif

#ifndef GRUP_EDID
#define GRUP_EDID(Type) \
TES5GRUPRecords<Sk::Type##Record, REV32(Type), 5, true> Type
#endif


class TES5File : public ModFile
class TES5File : public TES5ModFile
{
public:
GRUP(AACT);
Expand Down Expand Up @@ -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
Expand Down
54 changes: 54 additions & 0 deletions src/game/Skyrim/TES5ModFile.h
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 6f908f8

Please sign in to comment.