/
MapMerging.cpp
165 lines (117 loc) · 5.92 KB
/
MapMerging.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#include "RadiantTest.h"
#include "icommandsystem.h"
#include "itransformable.h"
#include "ibrush.h"
#include "ipatch.h"
#include "icomparablenode.h"
#include "algorithm/Scene.h"
#include "registry/registry.h"
namespace test
{
using MapMergeTest = RadiantTest;
TEST_F(MapMergeTest, BrushFingerprint)
{
GlobalCommandSystem().executeCommand("OpenMap", cmd::Argument("maps/fingerprinting.mapx"));
auto originalMaterial = "textures/numbers/1";
auto brush = std::dynamic_pointer_cast<IBrushNode>(algorithm::findFirstBrushWithMaterial(
GlobalMapModule().findOrInsertWorldspawn(), originalMaterial));
auto comparable = std::dynamic_pointer_cast<scene::IComparableNode>(brush);
EXPECT_TRUE(comparable) << "BrushNode is not implementing IComparableNode";
auto originalFingerprint = comparable->getFingerprint();
EXPECT_NE(originalFingerprint, 0); // shouldn't be empty
// Calling it twice shouldn't change the value
EXPECT_EQ(comparable->getFingerprint(), originalFingerprint);
// Change the material of this brush, the fingerprint should change now
brush->getIBrush().setShader("textures/somethingelse");
EXPECT_NE(comparable->getFingerprint(), originalFingerprint);
// Change it back
brush->getIBrush().setShader(originalMaterial);
EXPECT_EQ(comparable->getFingerprint(), originalFingerprint);
// Change the contents flags, fingerprint should change
brush->getIBrush().setDetailFlag(IBrush::Detail);
EXPECT_NE(comparable->getFingerprint(), originalFingerprint);
// Change it back
brush->getIBrush().setDetailFlag(IBrush::Structural);
EXPECT_EQ(comparable->getFingerprint(), originalFingerprint);
// Get the first face and tinker with it
auto& face = brush->getIBrush().getFace(0);
auto lastFingerprint = comparable->getFingerprint();
// Changing the texture should modify the fingerprint
face.flipTexture(0);
EXPECT_NE(comparable->getFingerprint(), lastFingerprint);
lastFingerprint = comparable->getFingerprint();
// Disable texture lock
registry::setValue(RKEY_ENABLE_TEXTURE_LOCK, false);
// Changing the planes
auto transformable = std::dynamic_pointer_cast<ITransformable>(brush);
transformable->setTranslation(Vector3(10,0,0));
transformable->freezeTransform();
EXPECT_NE(comparable->getFingerprint(), lastFingerprint);
lastFingerprint = comparable->getFingerprint();
}
TEST_F(MapMergeTest, PatchFingerprint)
{
GlobalCommandSystem().executeCommand("OpenMap", cmd::Argument("maps/fingerprinting.mapx"));
auto originalMaterial = "textures/numbers/1";
auto patch = std::dynamic_pointer_cast<IPatchNode>(algorithm::findFirstPatchWithMaterial(
GlobalMapModule().findOrInsertWorldspawn(), originalMaterial));
auto comparable = std::dynamic_pointer_cast<scene::IComparableNode>(patch);
EXPECT_TRUE(comparable) << "PatchNode is not implementing IComparableNode";
auto originalFingerprint = comparable->getFingerprint();
EXPECT_NE(originalFingerprint, 0); // shouldn't be empty
// Calling it twice shouldn't change the value
EXPECT_EQ(comparable->getFingerprint(), originalFingerprint);
// Change the material of this patch, the fingerprint should change now
patch->getPatch().setShader("textures/somethingelse");
EXPECT_NE(comparable->getFingerprint(), originalFingerprint);
// Change it back
patch->getPatch().setShader(originalMaterial);
EXPECT_EQ(comparable->getFingerprint(), originalFingerprint);
// Change a single control vertex
auto& control = patch->getPatch().ctrlAt(0, 0);
auto lastFingerprint = comparable->getFingerprint();
// Change a 3D coordinate
control.vertex.x() += 0.1;
EXPECT_NE(comparable->getFingerprint(), lastFingerprint);
lastFingerprint = comparable->getFingerprint();
// Change a 2D component
control.texcoord.x() += 0.1;
EXPECT_NE(comparable->getFingerprint(), lastFingerprint);
lastFingerprint = comparable->getFingerprint();
// Append vertices
patch->getPatch().appendPoints(true, false);
EXPECT_NE(comparable->getFingerprint(), lastFingerprint);
}
TEST_F(MapMergeTest, EntityFingerprint)
{
GlobalCommandSystem().executeCommand("OpenMap", cmd::Argument("maps/fingerprinting.mapx"));
auto entityNode = algorithm::getEntityByName(GlobalMapModule().getRoot(), "func_static_1");
auto comparable = std::dynamic_pointer_cast<scene::IComparableNode>(entityNode);
EXPECT_TRUE(comparable) << "EntityNode is not implementing IComparableNode";
auto entity = std::dynamic_pointer_cast<IEntityNode>(entityNode);
auto originalFingerprint = comparable->getFingerprint();
EXPECT_NE(originalFingerprint, 0); // shouldn't be empty
// Calling it twice shouldn't change the value
EXPECT_EQ(comparable->getFingerprint(), originalFingerprint);
// Change a spawnarg slightly
auto oldOrigin = entity->getEntity().getKeyValue("origin");
entity->getEntity().setKeyValue("origin", "96 -32 53");
EXPECT_NE(comparable->getFingerprint(), originalFingerprint);
// Change it back
entity->getEntity().setKeyValue("origin", oldOrigin);
EXPECT_EQ(comparable->getFingerprint(), originalFingerprint);
// Add a new spawnarg
entity->getEntity().setKeyValue("origin22", "whatever");
EXPECT_NE(comparable->getFingerprint(), originalFingerprint);
// Change it back
entity->getEntity().setKeyValue("origin22", "");
EXPECT_EQ(comparable->getFingerprint(), originalFingerprint);
// Remove a spawnarg, this alters the order of keyvalues
auto originalValue = entity->getEntity().getKeyValue("dummyspawnarg");
entity->getEntity().setKeyValue("dummyspawnarg", "");
EXPECT_NE(comparable->getFingerprint(), originalFingerprint);
// Change it back, even though the order is different, the fingerprint should be the same
entity->getEntity().setKeyValue("dummyspawnarg", originalValue);
EXPECT_EQ(comparable->getFingerprint(), originalFingerprint);
}
}