Skip to content

Commit

Permalink
#5711: Add separate Q3 map writer. Move common double exporter code t…
Browse files Browse the repository at this point in the history
…o shared header file.
  • Loading branch information
codereader committed Aug 29, 2021
1 parent 795f65f commit 9979ea1
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 79 deletions.
4 changes: 2 additions & 2 deletions radiantcore/map/format/Quake3MapFormat.cpp
Expand Up @@ -90,7 +90,7 @@ const std::string& Quake3MapFormat::getName() const

IMapWriterPtr Quake3MapFormat::getMapWriter() const
{
return std::make_shared<Quake3MapWriter>(); // TODO
return std::make_shared<Quake3MapWriter>();
}

// Quake 3 with alternate brush format
Expand All @@ -115,7 +115,7 @@ const std::string& Quake3AlternateMapFormat::getName() const

IMapWriterPtr Quake3AlternateMapFormat::getMapWriter() const
{
return std::make_shared<Quake3MapWriter>(); // TODO
return std::make_shared<Quake3AlternateMapWriter>();
}

module::StaticModule<Quake3MapFormat> q3MapModule;
Expand Down
17 changes: 16 additions & 1 deletion radiantcore/map/format/Quake3MapWriter.h
Expand Up @@ -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
Expand All @@ -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
25 changes: 1 addition & 24 deletions radiantcore/map/format/primitivewriters/BrushDef3Exporter.h
Expand Up @@ -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:
Expand Down
25 changes: 1 addition & 24 deletions radiantcore/map/format/primitivewriters/BrushDefExporter.h
Expand Up @@ -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:
Expand Down
30 changes: 30 additions & 0 deletions radiantcore/map/format/primitivewriters/ExportUtil.h
@@ -0,0 +1,30 @@
#pragma once

#include <ostream>
#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";
}
}

}
34 changes: 6 additions & 28 deletions radiantcore/map/format/primitivewriters/PatchDefExporter.h
Expand Up @@ -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:
Expand Down Expand Up @@ -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 << " ) ";
}

Expand Down
1 change: 1 addition & 0 deletions tools/msvc/DarkRadiantCore.vcxproj
Expand Up @@ -847,6 +847,7 @@
<ClInclude Include="..\..\radiantcore\map\format\primitiveparsers\PatchDef3.h" />
<ClInclude Include="..\..\radiantcore\map\format\primitivewriters\BrushDef3Exporter.h" />
<ClInclude Include="..\..\radiantcore\map\format\primitivewriters\BrushDefExporter.h" />
<ClInclude Include="..\..\radiantcore\map\format\primitivewriters\ExportUtil.h" />
<ClInclude Include="..\..\radiantcore\map\format\primitivewriters\PatchDefExporter.h" />
<ClInclude Include="..\..\radiantcore\map\format\Quake3MapFormat.h" />
<ClInclude Include="..\..\radiantcore\map\format\Quake3MapReader.h" />
Expand Down
3 changes: 3 additions & 0 deletions tools/msvc/DarkRadiantCore.vcxproj.filters
Expand Up @@ -2184,5 +2184,8 @@
<ClInclude Include="..\..\radiantcore\map\autosaver\AutoSaver.h">
<Filter>src\map\autosaver</Filter>
</ClInclude>
<ClInclude Include="..\..\radiantcore\map\format\primitivewriters\ExportUtil.h">
<Filter>src\map\format\primitivewriters</Filter>
</ClInclude>
</ItemGroup>
</Project>

0 comments on commit 9979ea1

Please sign in to comment.