Skip to content

Commit 6b01e00

Browse files
committed
Forward declare Semver200_version to not include it in our headers
Being a shit when not ptr, and unique_ptr is also being a shit and I don't want to define a custom deleter, so just use good ol' raw ptrs
1 parent 1fcdf42 commit 6b01e00

File tree

2 files changed

+25
-17
lines changed

2 files changed

+25
-17
lines changed

System/DataModule.cpp

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "LuaMan.h"
55
#include "GameVersion.h"
66

7+
#include <System/Semver200/semver200.h>
78

89
namespace RTE {
910

@@ -17,7 +18,7 @@ namespace RTE {
1718
m_FriendlyName.clear();
1819
m_Author.clear();
1920
m_Description.clear();
20-
m_SupportedGameVersion = version::Semver200_version();
21+
m_SupportedGameVersion = nullptr;
2122
m_Version = 1;
2223
m_ModuleID = -1;
2324
m_IconFile.Reset();
@@ -93,6 +94,7 @@ namespace RTE {
9394
for (const PresetEntry &preset : m_PresetList){
9495
delete preset.m_EntityPreset;
9596
}
97+
delete m_SupportedGameVersion;
9698
Clear();
9799
}
98100

@@ -145,10 +147,13 @@ namespace RTE {
145147
} else if (propName == "SupportedGameVersion") {
146148
std::string versionText;
147149
reader >> versionText;
148-
try {
149-
m_SupportedGameVersion = version::Semver200_version(versionText);
150-
} catch (version::Parse_error &) {
151-
reader.ReportError("Couldn't parse the supported game version from the value provided: \"" + versionText + "\"!\nThe supported game version must be a valid semantic version number.\n");
150+
// TODO: Need to proceed reading the includes after ReadModuleProperties so we don't read the properties again when fully creating.
151+
if (!m_SupportedGameVersion) {
152+
try {
153+
m_SupportedGameVersion = new version::Semver200_version(versionText);
154+
} catch (version::Parse_error &) {
155+
reader.ReportError("Couldn't parse the supported game version from the value provided: \"" + versionText + "\"!\nThe supported game version must be a valid semantic version number.\n");
156+
}
152157
}
153158
} else if (propName == "Version") {
154159
reader >> m_Version;
@@ -208,7 +213,7 @@ namespace RTE {
208213
writer.NewPropertyWithValue("Author", m_Author);
209214
writer.NewPropertyWithValue("Description", m_Description);
210215
writer.NewPropertyWithValue("IsFaction", m_IsFaction);
211-
writer.NewPropertyWithValue("SupportedGameVersion", m_SupportedGameVersion.str());
216+
writer.NewPropertyWithValue("SupportedGameVersion", m_SupportedGameVersion->str());
212217
writer.NewPropertyWithValue("Version", m_Version);
213218
writer.NewPropertyWithValue("IconFile", m_IconFile);
214219

@@ -489,25 +494,25 @@ namespace RTE {
489494
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
490495

491496
void DataModule::CheckSupportedGameVersion() const {
492-
if (m_SupportedGameVersion != c_GameVersion) {
497+
if (*m_SupportedGameVersion != c_GameVersion) {
493498
static const std::string contactAuthor = "Please contact the mod author or ask for help in the CCCP discord server.";
494499

495-
RTEAssert(m_SupportedGameVersion != version::Semver200_version(), m_FileName + " does not specify a supported Cortex Command version, so it is not compatible with this version of Cortex Command (" + c_GameVersion.str() + ").\n\n" + contactAuthor);
500+
RTEAssert(*m_SupportedGameVersion != version::Semver200_version(), m_FileName + " does not specify a supported Cortex Command version, so it is not compatible with this version of Cortex Command (" + c_GameVersion.str() + ").\n\n" + contactAuthor);
496501

497-
bool modulePrereleaseVersionMismatch = !m_SupportedGameVersion.prerelease().empty();
498-
bool moduleBuildVersionMismatch = !m_SupportedGameVersion.build().empty();
499-
RTEAssert(!modulePrereleaseVersionMismatch && !moduleBuildVersionMismatch, m_FileName + " was developed for pre-release build of Cortex Command v" + m_SupportedGameVersion.str() + ", this game version (v" + c_GameVersion.str() + ") is incompatible.\n\nMods developed on a pre-release must match the game version exactly.\n" + contactAuthor);
502+
bool modulePrereleaseVersionMismatch = !m_SupportedGameVersion->prerelease().empty();
503+
bool moduleBuildVersionMismatch = !m_SupportedGameVersion->build().empty();
504+
RTEAssert(!modulePrereleaseVersionMismatch && !moduleBuildVersionMismatch, m_FileName + " was developed for pre-release build of Cortex Command v" + m_SupportedGameVersion->str() + ", this game version (v" + c_GameVersion.str() + ") is incompatible.\n\nMods developed on a pre-release must match the game version exactly.\n" + contactAuthor);
500505

501506
bool gamePrereleaseVersionMismatch = !c_GameVersion.prerelease().empty();
502507
bool gameBuildVersionMismatch = !c_GameVersion.build().empty();
503-
RTEAssert(!gamePrereleaseVersionMismatch && !gameBuildVersionMismatch, m_FileName + " was developed for Cortex Command v" + m_SupportedGameVersion.str() + ", this pre-release version of the game (v" + c_GameVersion.str() + ") may not support it.\n\nMods must match the game version exactly to use pre-release builds.\n" + contactAuthor);
508+
RTEAssert(!gamePrereleaseVersionMismatch && !gameBuildVersionMismatch, m_FileName + " was developed for Cortex Command v" + m_SupportedGameVersion->str() + ", this pre-release version of the game (v" + c_GameVersion.str() + ") may not support it.\n\nMods must match the game version exactly to use pre-release builds.\n" + contactAuthor);
504509

505510
// Game engine is the same major version as the Module
506-
bool majorVersionMatch = c_GameVersion.major() == m_SupportedGameVersion.major();
511+
bool majorVersionMatch = c_GameVersion.major() == m_SupportedGameVersion->major();
507512
// Game engine is at least the minor version the Module requires (allow patch mismatch)
508-
bool minorVersionInRange = m_SupportedGameVersion.inc_minor() <= c_GameVersion.inc_minor();
513+
bool minorVersionInRange = m_SupportedGameVersion->inc_minor() <= c_GameVersion.inc_minor();
509514

510-
RTEAssert(majorVersionMatch && minorVersionInRange, m_FileName + " was developed for Cortex Command v" + m_SupportedGameVersion.str() + ", so this version of Cortex Command (v" + c_GameVersion.str() + ") may not support it.\n" + contactAuthor);
515+
RTEAssert(majorVersionMatch && minorVersionInRange, m_FileName + " was developed for Cortex Command v" + m_SupportedGameVersion->str() + ", so this version of Cortex Command (v" + c_GameVersion.str() + ") may not support it.\n" + contactAuthor);
511516
}
512517
}
513518
}

System/DataModule.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33

44
#include "ContentFile.h"
55
#include "Constants.h"
6-
#include <System/Semver200/semver200.h>
76

87
//struct DATAFILE; // DataFile loading not implemented.
98
struct BITMAP;
109

10+
namespace version {
11+
class Semver200_version;
12+
}
13+
1114
namespace RTE {
1215

1316
class Entity;
@@ -321,7 +324,7 @@ namespace RTE {
321324
std::string m_ScriptPath; //!< Path to script to execute when this module is loaded.
322325
bool m_IsFaction; //!< Whether this data module is considered a faction.
323326
bool m_IsMerchant; //!< Whether this data module is considered a merchant.
324-
version::Semver200_version m_SupportedGameVersion; //!< Game version this DataModule supports. Needs to satisfy Caret Version Range for this DataModule to be allowed. Base DataModules don't need this.
327+
version::Semver200_version *m_SupportedGameVersion; //!< Game version this DataModule supports. Needs to satisfy Caret Version Range for this DataModule to be allowed. Base DataModules don't need this.
325328
int m_Version; //!< Version number, starting with 1.
326329
int m_ModuleID; //!< ID number assigned to this upon loading, for internal use only, don't reflect in ini's.
327330

0 commit comments

Comments
 (0)