Skip to content

Commit

Permalink
More header cleanup
Browse files Browse the repository at this point in the history
- Archive/ArchiveEntry/ArchiveDir headers no longer include eachother
- ColRGBA moved to its own minimal header
- Moved various class-embedded structs/enums out that require forward declaring (still more to do here)
- Moved various classes from headers into source files in the cases where they were only used within that source file (probably missed a bunch of these)
- Added CommonFwd.h to Main.h, which forward declares a bunch of commonly used classes etc.
- Reworked Property/PropertyList source files to make Property.h and PropertyList.h as lightweight as possible
  • Loading branch information
sirjuddington committed Mar 24, 2024
1 parent a24a0b8 commit b586eb8
Show file tree
Hide file tree
Showing 328 changed files with 4,742 additions and 4,145 deletions.
3 changes: 3 additions & 0 deletions src/Application/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@
// -----------------------------------------------------------------------------
#include "Main.h"
#include "App.h"
#include "Archive/Archive.h"
#include "Archive/ArchiveManager.h"
#include "Archive/EntryType/EntryDataFormat.h"
#include "Archive/EntryType/EntryType.h"
#include "Game/Game.h"
#include "Game/SpecialPreset.h"
#include "General/Clipboard.h"
Expand Down
27 changes: 27 additions & 0 deletions src/Application/CommonFwd.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#pragma once

// Forward declarations for commonly used classes/structs/etc.

namespace slade
{
// Archive
class Archive;
class ArchiveDir;
class ArchiveEntry;

// Graphics
class Palette;

// SLADEMap
class MapLine;
class MapObject;
class MapSector;
class MapSide;
class MapThing;
class MapVertex;
class SLADEMap;

// Utility
class ParseTreeNode;
struct ColRGBA;
} // namespace slade
3 changes: 2 additions & 1 deletion src/Application/Main.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#define __MAIN_H__

#include "Common.h"
#include "CommonFwd.h"

#if defined _MSC_VER && _MSC_VER < 1900
#define _CRT_SECURE_NO_WARNINGS 1
Expand Down Expand Up @@ -62,7 +63,7 @@ namespace slade
using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using y16 = uint16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
Expand Down
2 changes: 2 additions & 0 deletions src/Application/SLADEWxApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#include "Main.h"
#include "SLADEWxApp.h"
#include "App.h"
#include "Archive/Archive.h"
#include "Archive/ArchiveEntry.h"
#include "Archive/ArchiveManager.h"
#include "General/Console.h"
#include "General/Web.h"
Expand Down
82 changes: 58 additions & 24 deletions src/Archive/Archive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@
// -----------------------------------------------------------------------------
#include "Main.h"
#include "Archive.h"
#include "ArchiveDir.h"
#include "ArchiveEntry.h"
#include "EntryType/EntryType.h"
#include "General/UI.h"
#include "General/UndoRedo.h"
#include "MapDesc.h"
#include "Utility/FileUtils.h"
#include "Utility/Parser.h"
#include "Utility/StringUtils.h"
Expand Down Expand Up @@ -139,11 +143,11 @@ class DirRenameUS : public UndoStep
}

private:
Archive* archive_;
string path_;
string old_name_;
string new_name_;
ArchiveEntry::State prev_state_;
Archive* archive_;
string path_;
string old_name_;
string new_name_;
EntryState prev_state_;
};

class EntrySwapUS : public UndoStep
Expand Down Expand Up @@ -249,8 +253,7 @@ class DirCreateDeleteUS : public UndoStep
// Do merge
vector<shared_ptr<ArchiveEntry>> created_entries;
vector<shared_ptr<ArchiveDir>> created_dirs;
ArchiveDir::merge(
dir, tree_.get(), 0, ArchiveEntry::State::Unmodified, &created_dirs, &created_entries);
ArchiveDir::merge(dir, tree_.get(), 0, EntryState::Unmodified, &created_dirs, &created_entries);

// Signal changes
for (const auto& cdir : created_dirs)
Expand All @@ -260,7 +263,7 @@ class DirCreateDeleteUS : public UndoStep
}

if (dir)
dir->dirEntry()->setState(ArchiveEntry::State::Unmodified);
dir->dirEntry()->setState(EntryState::Unmodified);

return !!dir;
}
Expand Down Expand Up @@ -451,6 +454,14 @@ string Archive::filename(bool full) const
return full ? filename_ : string{ strutil::Path::fileNameOf(filename_) };
}

// -----------------------------------------------------------------------------
// Returns the archive's parent archive (if it is embedded)
// -----------------------------------------------------------------------------
Archive* Archive::parentArchive() const
{
return parent_.lock() ? parent_.lock()->parent() : nullptr;
}

// -----------------------------------------------------------------------------
// Reads an archive from disk
// Returns true if successful, false otherwise
Expand Down Expand Up @@ -657,7 +668,7 @@ bool Archive::save(string_view filename)
if (auto parent = parent_.lock())
{
success = write(parent->data_);
parent->setState(ArchiveEntry::State::Modified);
parent->setState(EntryState::Modified);
}
else
{
Expand Down Expand Up @@ -739,7 +750,7 @@ void Archive::entryStateChanged(ArchiveEntry* entry)
signals_.entry_state_changed(*this, *entry);

// If entry was set to unmodified, don't set the archive to modified
if (entry->state() == ArchiveEntry::State::Unmodified)
if (entry->state() == EntryState::Unmodified)
return;

// Set the archive state to modified
Expand Down Expand Up @@ -799,7 +810,7 @@ bool Archive::paste(ArchiveDir* tree, unsigned position, shared_ptr<ArchiveDir>
// Do merge
vector<shared_ptr<ArchiveEntry>> created_entries;
vector<shared_ptr<ArchiveDir>> created_dirs;
if (!ArchiveDir::merge(base, tree, position, ArchiveEntry::State::New, &created_dirs, &created_entries))
if (!ArchiveDir::merge(base, tree, position, EntryState::New, &created_dirs, &created_entries))
return false;

// Signal changes
Expand Down Expand Up @@ -921,7 +932,7 @@ bool Archive::renameDir(ArchiveDir* dir, string_view new_name)
undoredo::currentManager()->recordUndoStep(std::make_unique<DirRenameUS>(dir, new_name));

dir->setName(new_name);
dir->dirEntry()->setState(ArchiveEntry::State::Modified);
dir->dirEntry()->setState(EntryState::Modified);
}
else
return true;
Expand Down Expand Up @@ -960,7 +971,7 @@ shared_ptr<ArchiveEntry> Archive::addEntry(shared_ptr<ArchiveEntry> entry, unsig

// Update variables etc
setModified(true);
entry->state_ = ArchiveEntry::State::New;
entry->state_ = EntryState::New;

// Signal entry addition
signals_.entry_added(*this, *entry);
Expand Down Expand Up @@ -1053,7 +1064,7 @@ bool Archive::removeEntry(ArchiveEntry* entry, bool set_deleted)
{
// Set state
if (set_deleted)
entry_shared->setState(ArchiveEntry::State::Deleted);
entry_shared->setState(EntryState::Deleted);

signals_.entry_removed(*this, *dir, *entry); // Signal entry removed
setModified(true); // Update variables etc
Expand Down Expand Up @@ -1233,7 +1244,7 @@ bool Archive::renameEntry(ArchiveEntry* entry, string_view name, bool force)
entry->formatName(fmt_desc);
if (!force && !fmt_desc.allow_duplicate_names)
entry->parentDir()->ensureUniqueName(entry);
entry->setState(ArchiveEntry::State::Modified, true);
entry->setState(EntryState::Modified, true);

// Announce modification
signals_.entry_renamed(*this, *entry, prev_name);
Expand Down Expand Up @@ -1300,8 +1311,8 @@ bool Archive::importDir(string_view directory, bool ignore_hidden, shared_ptr<Ar
log::error(global::error);

// Set unmodified
entry->setState(ArchiveEntry::State::Unmodified);
dir->dirEntry()->setState(ArchiveEntry::State::Unmodified);
entry->setState(EntryState::Unmodified);
dir->dirEntry()->setState(EntryState::Unmodified);
}

return true;
Expand All @@ -1323,7 +1334,7 @@ bool Archive::revertEntry(ArchiveEntry* entry)
return false;

// No point if entry is unmodified or newly created
if (entry->state() != ArchiveEntry::State::Modified)
if (entry->state() != EntryState::Modified)
return true;

// Reload entry data from the archive on disk
Expand All @@ -1332,13 +1343,31 @@ bool Archive::revertEntry(ArchiveEntry* entry)
{
entry->importMemChunk(entry_data);
EntryType::detectEntryType(*entry);
entry->setState(ArchiveEntry::State::Unmodified);
entry->setState(EntryState::Unmodified);
return true;
}

return false;
}

// -----------------------------------------------------------------------------
// Returns the MapDesc information about the map beginning at [maphead].
// To be implemented in Archive sub-classes.
// -----------------------------------------------------------------------------
MapDesc Archive::mapDesc(ArchiveEntry* maphead)
{
return {};
}

// -----------------------------------------------------------------------------
// Returns the MapDesc information about all maps in the Archive.
// To be implemented in Archive sub-classes.
// -----------------------------------------------------------------------------
vector<MapDesc> Archive::detectMaps()
{
return {};
}

// -----------------------------------------------------------------------------
// Returns the namespace of the entry at [index] within [dir]
// -----------------------------------------------------------------------------
Expand Down Expand Up @@ -1379,7 +1408,7 @@ string Archive::detectNamespace(ArchiveEntry* entry)
// Returns the first entry matching the search criteria in [options], or null if
// no matching entry was found
// -----------------------------------------------------------------------------
ArchiveEntry* Archive::findFirst(SearchOptions& options)
ArchiveEntry* Archive::findFirst(ArchiveSearchOptions& options)
{
// Init search variables
auto dir = options.dir;
Expand Down Expand Up @@ -1448,7 +1477,7 @@ ArchiveEntry* Archive::findFirst(SearchOptions& options)
// Returns the last entry matching the search criteria in [options], or null if
// no matching entry was found
// -----------------------------------------------------------------------------
ArchiveEntry* Archive::findLast(SearchOptions& options)
ArchiveEntry* Archive::findLast(ArchiveSearchOptions& options)
{
// Init search variables
auto dir = options.dir;
Expand Down Expand Up @@ -1516,7 +1545,7 @@ ArchiveEntry* Archive::findLast(SearchOptions& options)
// -----------------------------------------------------------------------------
// Returns a list of entries matching the search criteria in [options]
// -----------------------------------------------------------------------------
vector<ArchiveEntry*> Archive::findAll(SearchOptions& options)
vector<ArchiveEntry*> Archive::findAll(ArchiveSearchOptions& options)
{
// Init search variables
auto dir = options.dir;
Expand Down Expand Up @@ -1599,7 +1628,7 @@ vector<ArchiveEntry*> Archive::findModifiedEntries(ArchiveDir* dir)
auto entry = dir->entryAt(a);

// Add new and modified entries
if (entry->state() != ArchiveEntry::State::Unmodified)
if (entry->state() != EntryState::Unmodified)
ret.push_back(entry);
}

Expand Down Expand Up @@ -1687,7 +1716,7 @@ void Archive::detectAllEntryTypes() const
{
ui::setSplashProgress(i, n_entries);
EntryType::detectEntryType(*entries[i]);
entries[i]->setState(ArchiveEntry::State::Unmodified);
entries[i]->setState(EntryState::Unmodified);
}
}

Expand Down Expand Up @@ -1807,6 +1836,11 @@ ArchiveFormat* Archive::formatFromId(string_view id)
// -----------------------------------------------------------------------------


unsigned TreelessArchive::numEntries()
{
return rootDir()->numEntries();
}

// -----------------------------------------------------------------------------
// Treeless version of Archive::paste.
// Pastes all entries in [tree] and its subdirectories straight into the root
Expand Down
Loading

0 comments on commit b586eb8

Please sign in to comment.