From 9979ea11df42a6b45982d0e1c76308ca0cf348c3 Mon Sep 17 00:00:00 2001 From: codereader Date: Sun, 29 Aug 2021 09:42:19 +0200 Subject: [PATCH] #5711: Add separate Q3 map writer. Move common double exporter code to shared header file. --- radiantcore/map/format/Quake3MapFormat.cpp | 4 +-- radiantcore/map/format/Quake3MapWriter.h | 17 +++++++++- .../primitivewriters/BrushDef3Exporter.h | 25 +------------- .../primitivewriters/BrushDefExporter.h | 25 +------------- .../map/format/primitivewriters/ExportUtil.h | 30 ++++++++++++++++ .../primitivewriters/PatchDefExporter.h | 34 ++++--------------- tools/msvc/DarkRadiantCore.vcxproj | 1 + tools/msvc/DarkRadiantCore.vcxproj.filters | 3 ++ 8 files changed, 60 insertions(+), 79 deletions(-) create mode 100644 radiantcore/map/format/primitivewriters/ExportUtil.h diff --git a/radiantcore/map/format/Quake3MapFormat.cpp b/radiantcore/map/format/Quake3MapFormat.cpp index d025499bae..23b1fed875 100644 --- a/radiantcore/map/format/Quake3MapFormat.cpp +++ b/radiantcore/map/format/Quake3MapFormat.cpp @@ -90,7 +90,7 @@ const std::string& Quake3MapFormat::getName() const IMapWriterPtr Quake3MapFormat::getMapWriter() const { - return std::make_shared(); // TODO + return std::make_shared(); } // Quake 3 with alternate brush format @@ -115,7 +115,7 @@ const std::string& Quake3AlternateMapFormat::getName() const IMapWriterPtr Quake3AlternateMapFormat::getMapWriter() const { - return std::make_shared(); // TODO + return std::make_shared(); } module::StaticModule q3MapModule; diff --git a/radiantcore/map/format/Quake3MapWriter.h b/radiantcore/map/format/Quake3MapWriter.h index 6f806c0bcc..5d133749a0 100644 --- a/radiantcore/map/format/Quake3MapWriter.h +++ b/radiantcore/map/format/Quake3MapWriter.h @@ -27,7 +27,7 @@ class Quake3MapWriter : stream << "// brush " << _primitiveCount++ << std::endl; // Export brushDef definition to stream - BrushDefExporter::exportBrush(stream, brush); + BrushDefExporter::exportBrush(stream, brush); // TODO } virtual void beginWritePatch(const IPatchNodePtr& patch, std::ostream& stream) override @@ -40,4 +40,19 @@ class Quake3MapWriter : } }; +class Quake3AlternateMapWriter : + public Doom3MapWriter +{ +public: + // Q3 alternate is writing the newer brushDef syntax + virtual void beginWriteBrush(const IBrushNodePtr& brush, std::ostream& stream) override + { + // Primitive count comment + stream << "// brush " << _primitiveCount++ << std::endl; + + // Export brushDef definition to stream + BrushDefExporter::exportBrush(stream, brush); + } +}; + } // namespace diff --git a/radiantcore/map/format/primitivewriters/BrushDef3Exporter.h b/radiantcore/map/format/primitivewriters/BrushDef3Exporter.h index f9c3f6a71b..5071269b8c 100644 --- a/radiantcore/map/format/primitivewriters/BrushDef3Exporter.h +++ b/radiantcore/map/format/primitivewriters/BrushDef3Exporter.h @@ -3,34 +3,11 @@ #include "ibrush.h" #include "math/Plane3.h" #include "math/Matrix4.h" +#include "ExportUtil.h" namespace map { -namespace -{ - // Writes a double to the given stream and checks for NaN and infinity - inline void writeDoubleSafe(const double d, std::ostream& os) - { - if (isValid(d)) - { - if (d == -0.0) - { - os << 0; // convert -0 to 0 - } - else - { - os << d; - } - } - else - { - // Is infinity or NaN, write 0 - os << "0"; - } - } -} - class BrushDef3Exporter { public: diff --git a/radiantcore/map/format/primitivewriters/BrushDefExporter.h b/radiantcore/map/format/primitivewriters/BrushDefExporter.h index fb73cd75d3..fd413a19e6 100644 --- a/radiantcore/map/format/primitivewriters/BrushDefExporter.h +++ b/radiantcore/map/format/primitivewriters/BrushDefExporter.h @@ -6,34 +6,11 @@ #include "shaderlib.h" #include "string/predicate.h" +#include "ExportUtil.h" namespace map { -namespace -{ - // Writes a double to the given stream and checks for NaN and infinity - inline void writeDoubleSafe(const double d, std::ostream& os) - { - if (isValid(d)) - { - if (d == -0.0) - { - os << 0; // convert -0 to 0 - } - else - { - os << d; - } - } - else - { - // Is infinity or NaN, write 0 - os << "0"; - } - } -} - class BrushDefExporter { public: diff --git a/radiantcore/map/format/primitivewriters/ExportUtil.h b/radiantcore/map/format/primitivewriters/ExportUtil.h new file mode 100644 index 0000000000..857b9752e5 --- /dev/null +++ b/radiantcore/map/format/primitivewriters/ExportUtil.h @@ -0,0 +1,30 @@ +#pragma once + +#include +#include "math/FloatTools.h" + +namespace map +{ + +// Writes a double to the given stream and checks for NaN and infinity +inline void writeDoubleSafe(const double d, std::ostream& os) +{ + if (isValid(d)) + { + if (d == -0.0) + { + os << 0; // convert -0 to 0 + } + else + { + os << d; + } + } + else + { + // Is infinity or NaN, write 0 + os << "0"; + } +} + +} diff --git a/radiantcore/map/format/primitivewriters/PatchDefExporter.h b/radiantcore/map/format/primitivewriters/PatchDefExporter.h index ef9a8d411b..54d90c4b61 100644 --- a/radiantcore/map/format/primitivewriters/PatchDefExporter.h +++ b/radiantcore/map/format/primitivewriters/PatchDefExporter.h @@ -4,33 +4,11 @@ #include "ipatch.h" #include "string/predicate.h" +#include "ExportUtil.h" namespace map { -namespace -{ - inline void writePatchDouble(const double d, std::ostream& os) - { - if (isValid(d)) - { - if (d == -0.0) - { - os << 0; // convert -0 to 0 - } - else - { - os << d; - } - } - else - { - // Is infinity or NaN, write 0 - os << "0"; - } - } -} - class PatchDefExporter { public: @@ -181,15 +159,15 @@ class PatchDefExporter for (std::size_t r = 0; r < patch.getHeight(); r++) { stream << "( "; - writePatchDouble(patch.ctrlAt(r,c).vertex[0], stream); + writeDoubleSafe(patch.ctrlAt(r,c).vertex[0], stream); stream << " "; - writePatchDouble(patch.ctrlAt(r,c).vertex[1], stream); + writeDoubleSafe(patch.ctrlAt(r,c).vertex[1], stream); stream << " "; - writePatchDouble(patch.ctrlAt(r,c).vertex[2], stream); + writeDoubleSafe(patch.ctrlAt(r,c).vertex[2], stream); stream << " "; - writePatchDouble(patch.ctrlAt(r,c).texcoord[0], stream); + writeDoubleSafe(patch.ctrlAt(r,c).texcoord[0], stream); stream << " "; - writePatchDouble(patch.ctrlAt(r,c).texcoord[1], stream); + writeDoubleSafe(patch.ctrlAt(r,c).texcoord[1], stream); stream << " ) "; } diff --git a/tools/msvc/DarkRadiantCore.vcxproj b/tools/msvc/DarkRadiantCore.vcxproj index 05ebfefddd..02822d2ea6 100644 --- a/tools/msvc/DarkRadiantCore.vcxproj +++ b/tools/msvc/DarkRadiantCore.vcxproj @@ -847,6 +847,7 @@ + diff --git a/tools/msvc/DarkRadiantCore.vcxproj.filters b/tools/msvc/DarkRadiantCore.vcxproj.filters index abee6b8f40..33809bd60b 100644 --- a/tools/msvc/DarkRadiantCore.vcxproj.filters +++ b/tools/msvc/DarkRadiantCore.vcxproj.filters @@ -2184,5 +2184,8 @@ src\map\autosaver + + src\map\format\primitivewriters + \ No newline at end of file