Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editor: Land and Land Texture Tables #1427

Merged
merged 25 commits into from Oct 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
5d14a2a
Initial LTEX/LAND tables
Aesylwinn Aug 24, 2017
9e41f13
Replace nonconst getId with setId, add template specialization and sp…
Aesylwinn Aug 25, 2017
1d48001
Add ability to touch records, LAND records in particular
Aesylwinn Sep 1, 2017
30ba1d4
Move touch command to creator, to allow customization and not break a…
Aesylwinn Sep 3, 2017
7cc95a1
Add more land table columns
Aesylwinn Sep 4, 2017
90c4851
Land creator
Aesylwinn Sep 4, 2017
d3014cf
Temporary fix for adding new lands, cloned lands will still reference…
Aesylwinn Sep 4, 2017
5c3e90d
Fix includes
Aesylwinn Sep 4, 2017
97d0fd7
LTEX importing
Aesylwinn Sep 4, 2017
99e90ef
Cleanup. Also modify ltex index generation.
Aesylwinn Sep 5, 2017
ab607f3
Tweaks to land loading, land cloning, terrain signals, placeholder la…
Aesylwinn Sep 8, 2017
2eacc2f
Changes to land creation, add ability to specifically clear terrain c…
Aesylwinn Sep 8, 2017
72cb405
Some bug fixes, changes to land load code.
Aesylwinn Sep 9, 2017
d030b59
Fix potential segfault, cleanup, get rid of warnings.
Aesylwinn Sep 9, 2017
25d4a03
Changes to land data access in tables, also update Land once per fram…
Aesylwinn Sep 9, 2017
09e645a
Fix careless mistake.
Aesylwinn Sep 10, 2017
2abf7f1
Remove unnecessary cache dump
Aesylwinn Sep 15, 2017
50d9d9f
Get rid of some templates, exceptions instead of assert, and other sm…
Aesylwinn Sep 18, 2017
4921e7f
Get rid of reinterpret cast.
Aesylwinn Sep 23, 2017
054e6a7
Use map for texture lookup.
Aesylwinn Sep 23, 2017
3981f79
Change flag for base land textures
Aesylwinn Sep 23, 2017
1fe1ec6
Fix Qt4 build
Aesylwinn Sep 23, 2017
dfcbee3
Ignore case when comparing textures, also add new textures to lookup …
Aesylwinn Sep 30, 2017
137ea87
Hide base land textures.
Aesylwinn Oct 2, 2017
2f5449a
Remove now unnecessary overrides.
Aesylwinn Oct 2, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/opencs/CMakeLists.txt
Expand Up @@ -18,7 +18,7 @@ opencs_hdrs_noqt (model/doc


opencs_units (model/world
idtable idtableproxymodel regionmap data commanddispatcher idtablebase resourcetable nestedtableproxymodel idtree infotableproxymodel
idtable idtableproxymodel regionmap data commanddispatcher idtablebase resourcetable nestedtableproxymodel idtree infotableproxymodel landtexturetableproxymodel
)


Expand Down Expand Up @@ -70,7 +70,7 @@ opencs_units (view/world
cellcreator pathgridcreator referenceablecreator startscriptcreator referencecreator scenesubview
infocreator scriptedit dialoguesubview previewsubview regionmap dragrecordtable nestedtable
dialoguespinbox recordbuttonbar tableeditidaction scripterrortable extendedcommandconfigurator
bodypartcreator
bodypartcreator landtexturecreator landcreator
)

opencs_units_noqt (view/world
Expand Down
3 changes: 3 additions & 0 deletions apps/opencs/model/prefs/state.cpp
Expand Up @@ -240,6 +240,8 @@ void CSMPrefs::State::declare()
declareShortcut ("document-world-cells", "Open Cell List", QKeySequence());
declareShortcut ("document-world-referencables", "Open Object List", QKeySequence());
declareShortcut ("document-world-references", "Open Instance List", QKeySequence());
declareShortcut ("document-world-lands", "Open Lands List", QKeySequence());
declareShortcut ("document-world-landtextures", "Open Land Textures List", QKeySequence());
declareShortcut ("document-world-pathgrid", "Open Pathgrid List", QKeySequence());
declareShortcut ("document-world-regionmap", "Open Region Map", QKeySequence());
declareShortcut ("document-mechanics-globals", "Open Global List", QKeySequence());
Expand Down Expand Up @@ -276,6 +278,7 @@ void CSMPrefs::State::declare()
declareShortcut ("table-edit", "Edit Record", QKeySequence());
declareShortcut ("table-add", "Add Row/Record", QKeySequence(Qt::ShiftModifier | Qt::Key_A));
declareShortcut ("table-clone", "Clone Record", QKeySequence(Qt::ShiftModifier | Qt::Key_D));
declareShortcut ("touch-record", "Touch Record", QKeySequence());
declareShortcut ("table-revert", "Revert Record", QKeySequence());
declareShortcut ("table-remove", "Remove Row/Record", QKeySequence(Qt::Key_Delete));
declareShortcut ("table-moveup", "Move Record Up", QKeySequence());
Expand Down
126 changes: 113 additions & 13 deletions apps/opencs/model/world/collection.hpp
Expand Up @@ -6,31 +6,32 @@
#include <algorithm>
#include <cctype>
#include <stdexcept>
#include <string>
#include <functional>

#include <QVariant>

#include <components/misc/stringops.hpp>

#include "columnbase.hpp"

#include "collectionbase.hpp"
#include "land.hpp"
#include "landtexture.hpp"

namespace CSMWorld
{
/// \brief Access to ID field in records
template<typename ESXRecordT>
struct IdAccessor
{
std::string& getId (ESXRecordT& record);

void setId(ESXRecordT& record, const std::string& id) const;
const std::string getId (const ESXRecordT& record) const;
};

template<typename ESXRecordT>
std::string& IdAccessor<ESXRecordT>::getId (ESXRecordT& record)
void IdAccessor<ESXRecordT>::setId(ESXRecordT& record, const std::string& id) const
{
return record.mId;
record.mId = id;
}

template<typename ESXRecordT>
Expand All @@ -39,6 +40,39 @@ namespace CSMWorld
return record.mId;
}

template<>
inline void IdAccessor<Land>::setId (Land& record, const std::string& id) const
{
int x=0, y=0;

Land::parseUniqueRecordId(id, x, y);
record.mX = x;
record.mY = y;
}

template<>
inline void IdAccessor<LandTexture>::setId (LandTexture& record, const std::string& id) const
{
int plugin = 0;
int index = 0;

LandTexture::parseUniqueRecordId(id, plugin, index);
record.mPluginIndex = plugin;
record.mIndex = index;
}

template<>
inline const std::string IdAccessor<Land>::getId (const Land& record) const
{
return Land::createUniqueRecordId(record.mX, record.mY);
}

template<>
inline const std::string IdAccessor<LandTexture>::getId (const LandTexture& record) const
{
return LandTexture::createUniqueRecordId(record.mPluginIndex, record.mIndex);
}

/// \brief Single-type record collection
template<typename ESXRecordT, typename IdAccessorT = IdAccessor<ESXRecordT> >
class Collection : public CollectionBase
Expand Down Expand Up @@ -69,6 +103,13 @@ namespace CSMWorld
///
/// \return Success?

int cloneRecordImp (const std::string& origin, const std::string& dest,
UniversalId::Type type);
///< Returns the index of the clone.

int touchRecordImp (const std::string& id);
///< Returns the index of the record on success, -1 on failure.

public:

Collection();
Expand Down Expand Up @@ -108,6 +149,10 @@ namespace CSMWorld
const std::string& destination,
const UniversalId::Type type);

virtual bool touchRecord(const std::string& id);
///< Change the state of a record from base to modified, if it is not already.
/// \return True if the record was changed.

virtual int searchId (const std::string& id) const;
////< Search record with \a id.
/// \return index of record (if found) or -1 (not found)
Expand Down Expand Up @@ -205,17 +250,72 @@ namespace CSMWorld
return true;
}

template<typename ESXRecordT, typename IdAccessorT>
int Collection<ESXRecordT, IdAccessorT>::cloneRecordImp(const std::string& origin,
const std::string& destination, UniversalId::Type type)
{
Record<ESXRecordT> copy;
copy.mModified = getRecord(origin).get();
copy.mState = RecordBase::State_ModifiedOnly;
IdAccessorT().setId(copy.get(), destination);

int index = getAppendIndex(destination, type);
insertRecord(copy, getAppendIndex(destination, type));

return index;
}

template<typename ESXRecordT, typename IdAccessorT>
int Collection<ESXRecordT, IdAccessorT>::touchRecordImp(const std::string& id)
{
int index = getIndex(id);
Record<ESXRecordT>& record = mRecords.at(index);
if (record.isDeleted())
{
throw std::runtime_error("attempt to touch deleted record");
}

if (!record.isModified())
{
record.setModified(record.get());
return index;
}

return -1;
}

template<typename ESXRecordT, typename IdAccessorT>
void Collection<ESXRecordT, IdAccessorT>::cloneRecord(const std::string& origin,
const std::string& destination,
const UniversalId::Type type)
const std::string& destination, const UniversalId::Type type)
{
Record<ESXRecordT> copy;
copy.mModified = getRecord(origin).get();
copy.mState = RecordBase::State_ModifiedOnly;
copy.get().mId = destination;
cloneRecordImp(origin, destination, type);
}

insertRecord(copy, getAppendIndex(destination, type));
template<>
inline void Collection<Land, IdAccessor<Land> >::cloneRecord(const std::string& origin,
const std::string& destination, const UniversalId::Type type)
{
int index = cloneRecordImp(origin, destination, type);
mRecords.at(index).get().mPlugin = 0;
}

template<typename ESXRecordT, typename IdAccessorT>
bool Collection<ESXRecordT, IdAccessorT>::touchRecord(const std::string& id)
{
return touchRecordImp(id) != -1;
}

template<>
inline bool Collection<Land, IdAccessor<Land> >::touchRecord(const std::string& id)
{
int index = touchRecordImp(id);
if (index >= 0)
{
mRecords.at(index).get().mPlugin = 0;
return true;
}

return false;
}

template<typename ESXRecordT, typename IdAccessorT>
Expand Down Expand Up @@ -366,7 +466,7 @@ namespace CSMWorld
UniversalId::Type type)
{
ESXRecordT record;
IdAccessorT().getId (record) = id;
IdAccessorT().setId(record, id);
record.blank();

Record<ESXRecordT> record2;
Expand Down
2 changes: 2 additions & 0 deletions apps/opencs/model/world/collectionbase.hpp
Expand Up @@ -78,6 +78,8 @@ namespace CSMWorld
const std::string& destination,
const UniversalId::Type type) = 0;

virtual bool touchRecord(const std::string& id) = 0;

virtual const RecordBase& getRecord (const std::string& id) const = 0;

virtual const RecordBase& getRecord (int index) const = 0;
Expand Down