/
Doom3MapWriter.cpp
88 lines (68 loc) · 2.06 KB
/
Doom3MapWriter.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "Doom3MapWriter.h"
#include "igame.h"
#include "ientity.h"
#include "mapdoom3/primitivewriters/BrushDef3Exporter.h"
#include "mapdoom3/primitivewriters/PatchDefExporter.h"
#include "Doom3MapFormat.h"
namespace map
{
Doom3MapWriter::Doom3MapWriter() :
_entityCount(0),
_primitiveCount(0)
{}
void Doom3MapWriter::beginWriteMap(std::ostream& stream)
{
// Write the version tag
stream << "Version " << MAP_VERSION_D3 << std::endl;
}
void Doom3MapWriter::endWriteMap(std::ostream& stream)
{
// nothing
}
void Doom3MapWriter::beginWriteEntity(const IEntityNodePtr& entity, std::ostream& stream)
{
// Write out the entity number comment
stream << "// entity " << _entityCount++ << std::endl;
// Entity opening brace
stream << "{" << std::endl;
// Entity key values
writeEntityKeyValues(entity, stream);
}
void Doom3MapWriter::writeEntityKeyValues(const IEntityNodePtr& entity, std::ostream& stream)
{
// Export the entity key values
entity->getEntity().forEachKeyValue([&](const std::string& key, const std::string& value)
{
stream << "\"" << key << "\" \"" << value << "\"" << std::endl;
});
}
void Doom3MapWriter::endWriteEntity(const IEntityNodePtr& entity, std::ostream& stream)
{
// Write the closing brace for the entity
stream << "}" << std::endl;
// Reset the primitive count again
_primitiveCount = 0;
}
void Doom3MapWriter::beginWriteBrush(const IBrushNodePtr& brush, std::ostream& stream)
{
// Primitive count comment
stream << "// primitive " << _primitiveCount++ << std::endl;
// Export brushDef3 definition to stream
BrushDef3Exporter::exportBrush(stream, brush);
}
void Doom3MapWriter::endWriteBrush(const IBrushNodePtr& brush, std::ostream& stream)
{
// nothing
}
void Doom3MapWriter::beginWritePatch(const IPatch& patch, std::ostream& stream)
{
// Primitive count comment
stream << "// primitive " << _primitiveCount++ << std::endl;
// Export patch here _mapStream
PatchDefExporter::exportPatch(stream, patch);
}
void Doom3MapWriter::endWritePatch(const IPatch& patch, std::ostream& stream)
{
// nothing
}
} // namespace