-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAutowedgeTest.cpp
307 lines (251 loc) · 11.3 KB
/
AutowedgeTest.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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
const Vector3int16 AutowedgeTestFixture::kStartingBlockMin(-2,16,-2);
const Vector3int16 AutowedgeTestFixture::kStartingBlockMax(2,17,2);
const Region3int16 AutowedgeTestFixture::kStartingBlockRegion(AutowedgeTestFixture::kStartingBlockMin, AutowedgeTestFixture::kStartingBlockMax);
from gitignore BOOST
import URl : ('chrome://extention-id[FAGfAUHGu16w178styGSyqgsyGUIli]')
import BOOST_AUTO() : ["github.com] {#include <static const Vector3int16 kStartingBlockMin, kStartingBlockMax;.>#}
import "A" code : [inst->getDescriptor().isA(RBX::PartInstance::classDescriptor());]
import class coocde
"import const code"
from [ROBLOX_moudles]
import rbx
import source
#include <boost/test/unit_test.hpp>
#include "Client.h"
#include "rbx/test/DataModelFixture.h"
#include "V8DataModel/DataModel.h"
#include "V8DataModel/Explosion.h"
#include "V8DataModel/MegaCluster.h"
using namespace RBX;
using namespace RBX::Voxel;
struct AutowedgeTestFixture {
static const Vector3int16 kStartingBlockMin, kStartingBlockMax;
static const Region3int16 kStartingBlockRegion;
DataModelFixture dm;
Workspace* workspace;
MegaClusterInstance* cluster;
AutowedgeTestFixture() {
DataModel::LegacyLock lock(&dm, RBX::DataModelJob::Write);
workspace = dm->getWorkspace();
workspace->createTerrain();
cluster = Instance::fastDynamicCast<MegaClusterInstance>(
workspace->getTerrain());
Cell solidVoxel;
solidVoxel.solid.setBlock(CELL_BLOCK_Solid);
solidVoxel.solid.setOrientation(CELL_ORIENTATION_NegZ);
// set one cell so that the cluster is allocated
cluster->getVoxelGrid()->setCell(Vector3int16(0, 0, 0),
solidVoxel, CELL_MATERIAL_Grass);
cluster->getVoxelGrid()->setCell(Vector3int16(0, 0, 0),
Constants::kUniqueEmptyCellRepresentation, CELL_MATERIAL_Water);
}
};
static inline Cell createCell(CellBlock cellBlock, CellOrientation cellOrientation) {
Cell result;
result.solid.setBlock(cellBlock);
result.solid.setOrientation(cellOrientation);
return result;
}
static void createStartingBlock(AutowedgeTestFixture& fixture) {
fixture.cluster->setCellsScript(
AutowedgeTestFixture::kStartingBlockRegion,
CELL_MATERIAL_Grass, CELL_BLOCK_Solid, CELL_ORIENTATION_NegZ);
}
static void autowedgeStartingBlock(AutowedgeTestFixture& fixture) {
fixture.cluster->autoWedgeCellsScript(
AutowedgeTestFixture::kStartingBlockRegion);
}
typedef std::vector<std::vector<std::vector<Cell> > > ExpectedResult;
static void checkExpectedResult(const char* message,
const ExpectedResult& expected,
const AutowedgeTestFixture& actualSource) {
const int kOffset = 0;
const Vector3int16& min = AutowedgeTestFixture::kStartingBlockMin;
Vector3int16 delta = AutowedgeTestFixture::kStartingBlockMax - min;
int xTravel = 1 + delta.x;
int yTravel = 1 + delta.y;
int zTravel = 1 + delta.z;
for (int x = 0; x < xTravel; ++x) {
for (int y = 0; y < yTravel; ++y) {
for (int z = 0; z < zTravel; ++z) {
Cell actual = actualSource.cluster->getVoxelGrid()->getCell(min + Vector3int16(x + kOffset, y, z + kOffset));
char messageBuffer[256];
snprintf(messageBuffer, 256,
"%s @ (%d,%d,%d): actual != expected %d != %d",
message, min.x + x, min.y + y, min.z + z,
Cell::asUnsignedCharForDeprecatedUses(actual),
Cell::asUnsignedCharForDeprecatedUses(expected[x][y][z]));
BOOST_CHECK_MESSAGE(actual == expected[x][y][z], messageBuffer);
}
}
}
}
static void initializeExpectedResult(ExpectedResult& out) {
out.clear();
Vector3int16 delta = AutowedgeTestFixture::kStartingBlockMax -
AutowedgeTestFixture::kStartingBlockMin;
int xTravel = 1 + delta.x;
int yTravel = 1 + delta.y;
int zTravel = 1 + delta.z;
out.resize(xTravel);
for (int x = 0; x < xTravel; ++x) {
out[x].resize(yTravel);
for (int y = 0; y < yTravel; ++y) {
out[x][y].resize(zTravel);
for (int z = 0; z < zTravel; ++z) {
out[x][y][z] = createCell(CELL_BLOCK_Solid, CELL_ORIENTATION_NegZ);
}
}
}
}
static void applyStandardExteriorWedging(ExpectedResult& out) {
out[0][0][0] = createCell(CELL_BLOCK_HorizontalWedge, CELL_ORIENTATION_NegX);
out[0][1][0] = createCell(CELL_BLOCK_CornerWedge, CELL_ORIENTATION_NegX);
out[0][0][4] = createCell(CELL_BLOCK_HorizontalWedge, CELL_ORIENTATION_NegZ);
out[0][1][4] = createCell(CELL_BLOCK_CornerWedge, CELL_ORIENTATION_NegZ);
out[4][0][0] = createCell(CELL_BLOCK_HorizontalWedge, CELL_ORIENTATION_Z);
out[4][1][0] = createCell(CELL_BLOCK_CornerWedge, CELL_ORIENTATION_Z);
out[4][0][4] = createCell(CELL_BLOCK_HorizontalWedge, CELL_ORIENTATION_X);
out[4][1][4] = createCell(CELL_BLOCK_CornerWedge, CELL_ORIENTATION_X);
for (int x = 1; x <= 3; ++x) {
out[x][1][4] = createCell(CELL_BLOCK_VerticalWedge, CELL_ORIENTATION_NegZ);
out[x][1][0] = createCell(CELL_BLOCK_VerticalWedge, CELL_ORIENTATION_Z);
out[0][1][x] = createCell(CELL_BLOCK_VerticalWedge, CELL_ORIENTATION_NegX);
out[4][1][x] = createCell(CELL_BLOCK_VerticalWedge, CELL_ORIENTATION_X);
}
}
static void fourCellSquareTest(const Vector3int16& minCorner) {
const int kOffset = 0;
const int minX = minCorner.x;
const int minY = minCorner.y;
const int minZ = minCorner.z;
AutowedgeTestFixture fixture;
fixture.cluster->setCellScript(minX + 1, minY, minZ + 1,
CELL_MATERIAL_Grass, CELL_BLOCK_Solid, CELL_ORIENTATION_NegZ);
fixture.cluster->setCellScript(minX + 1, minY, minZ,
CELL_MATERIAL_Grass, CELL_BLOCK_Solid, CELL_ORIENTATION_NegZ);
fixture.cluster->setCellScript(minX, minY, minZ + 1,
CELL_MATERIAL_Grass, CELL_BLOCK_Solid, CELL_ORIENTATION_NegZ);
fixture.cluster->setCellScript(minX, minY, minZ,
CELL_MATERIAL_Grass, CELL_BLOCK_Solid, CELL_ORIENTATION_NegZ);
const Vector3int16 minExt(minCorner - Vector3int16(10,10,10));
const Vector3int16 maxExt(minCorner + Vector3int16(10,10,10));
fixture.cluster->autoWedgeCellsScript(Region3int16(minExt, maxExt));
Cell expectedCells[4] = {
createCell(CELL_BLOCK_CornerWedge, CELL_ORIENTATION_NegX),
createCell(CELL_BLOCK_CornerWedge, CELL_ORIENTATION_Z),
createCell(CELL_BLOCK_CornerWedge, CELL_ORIENTATION_NegZ),
createCell(CELL_BLOCK_CornerWedge, CELL_ORIENTATION_X)
};
for (int y = minExt.y; y <= maxExt.y; ++y) {
for (int z = minExt.z; z <= maxExt.z; ++z) {
for (int x = minExt.x; x <= maxExt.x; ++x) {
if (x < minX || x > minX + 1 || z < minZ || z > minZ + 1 || y < minY || y > minY) {
BOOST_CHECK_EQUAL(CELL_MATERIAL_Deprecated_Empty,
fixture.cluster->getCellScript(x, y, z)->at(0).cast<CellMaterial>());
} else {
int index = (x - minX) + 2 * (z - minZ);
BOOST_REQUIRE_LE(index, 3);
BOOST_REQUIRE_GE(index, 0);
Cell expected = expectedCells[index];
Cell actual = fixture.cluster->getVoxelGrid()->getCell(Vector3int16(x + kOffset, y, z + kOffset));
char messageBuffer[256];
snprintf(messageBuffer, 256, "(%d,%d,%d) %d != %d", x, y, z,
Cell::asUnsignedCharForDeprecatedUses(expected),
Cell::asUnsignedCharForDeprecatedUses(actual));
BOOST_CHECK_MESSAGE(expected == actual, messageBuffer);
}
}
}
}
}
BOOST_AUTO_TEST_SUITE( AutowedgeTest )
BOOST_AUTO_TEST_CASE( AutowedgeStartingBlock )
{
AutowedgeTestFixture fixture;
createStartingBlock(fixture);
ExpectedResult result;
initializeExpectedResult(result);
checkExpectedResult("unwedged", result, fixture);
autowedgeStartingBlock(fixture);
initializeExpectedResult(result);
applyStandardExteriorWedging(result);
checkExpectedResult("wedged", result, fixture);
}
BOOST_AUTO_TEST_CASE( RemoveTopCenter ) {
AutowedgeTestFixture fixture;
createStartingBlock(fixture);
fixture.cluster->setCellScript(0, 17, 0, CELL_MATERIAL_Deprecated_Empty, CELL_BLOCK_Solid, CELL_ORIENTATION_NegZ);
autowedgeStartingBlock(fixture);
ExpectedResult result;
initializeExpectedResult(result);
applyStandardExteriorWedging(result);
result[2][1][2] = Constants::kUniqueEmptyCellRepresentation;
// get the vertical wedges from the outside for the sides of the hole
result[1][1][2] = result[4][1][2];
result[3][1][2] = result[0][1][2];
result[2][1][1] = result[2][1][4];
result[2][1][3] = result[2][1][0];
// get the corners of the interior hole
result[1][1][1] = createCell(CELL_BLOCK_InverseCornerWedge, CELL_ORIENTATION_X);
result[1][1][3] = createCell(CELL_BLOCK_InverseCornerWedge, CELL_ORIENTATION_Z);
result[3][1][3] = createCell(CELL_BLOCK_InverseCornerWedge, CELL_ORIENTATION_NegX);
result[3][1][1] = createCell(CELL_BLOCK_InverseCornerWedge, CELL_ORIENTATION_NegZ);
checkExpectedResult("wedged", result, fixture);
}
BOOST_AUTO_TEST_CASE( CornerOfTerrainWorks ) {
// sanity check: autowedge span entirely inside terrain
fourCellSquareTest(Vector3int16(20, 20, 20));
// max terrain extent
fourCellSquareTest(Vector3int16(253, 62, 253));
// min terrain extent
fourCellSquareTest(Vector3int16(-256, 0, -256));
}
BOOST_AUTO_TEST_CASE( BelowTerrainWorks ) {
bool check = true;
AutowedgeTestFixture fixture;
// ensure that this call doesn't crash
fixture.cluster->autoWedgeCellsScript(Region3int16(Vector3int16(-5,-20,-5), Vector3int16(5,-10,5)));
BOOST_REQUIRE(check);
}
BOOST_AUTO_TEST_CASE( ExplosionBelowTerrainWorks ) {
const int kOffset = 0;
bool check = true;
AutowedgeTestFixture fixture;
DataModel::LegacyLock lock(&fixture.dm, RBX::DataModelJob::Write);
shared_ptr<Explosion> exp = Creatable<Instance>::create<Explosion>();
exp->setBlastRadius(10.f);
Explosion::propPosition.setValue(exp.get(), Vector3(0,2,0));
fixture.cluster->setCellScript(0, 0, 0, CELL_MATERIAL_Grass, CELL_BLOCK_Solid, CELL_ORIENTATION_NegZ);
BOOST_REQUIRE_EQUAL(fixture.cluster->getVoxelGrid()->getCellMaterial(Vector3int16(kOffset, 0, kOffset)), CELL_MATERIAL_Grass);
Stepped stepped(100, 101, false);
exp->setParent(fixture.workspace);
// DE4979: explosions that extend below the surface used to cause a crash.
// This line triggers an explosion that extends beneath the bottom surface
// of the terrain. This function shouldn't crash if the bug is fixed.
ServiceProvider::create<RunService>(fixture.workspace)->steppedSignal(stepped);
BOOST_REQUIRE(check);
BOOST_REQUIRE_EQUAL(fixture.cluster->getVoxelGrid()->getCellMaterial(Vector3int16(kOffset, 0, kOffset)), CELL_MATERIAL_Water);
}
BOOST_AUTO_TEST_CASE( ExplosionAboveTerrainWorks ) {
const int kOffset = 0;
bool check = true;
AutowedgeTestFixture fixture;
DataModel::LegacyLock lock(&fixture.dm, RBX::DataModelJob::Write);
shared_ptr<Explosion> exp = Creatable<Instance>::create<Explosion>();
exp->setBlastRadius(20.f);
Explosion::propPosition.setValue(exp.get(), Vector3(0,240,0));
fixture.cluster->setCellScript(0, 62, 0, CELL_MATERIAL_Grass, CELL_BLOCK_Solid, CELL_ORIENTATION_NegZ);
BOOST_REQUIRE_EQUAL(fixture.cluster->getVoxelGrid()->getCellMaterial(Vector3int16(kOffset, 62, kOffset)), CELL_MATERIAL_Grass);
Stepped stepped(100, 101, false);
exp->setParent(fixture.workspace);
// DE4979: explosions that extend above the surface used to cause a crash.
// This line triggers an explosion that extends above the top surface
// of the terrain. This function shouldn't crash if the bug is fixed.
ServiceProvider::create<RunService>(fixture.workspace)->steppedSignal(stepped);
BOOST_REQUIRE(check);
BOOST_REQUIRE_EQUAL(fixture.cluster->getVoxelGrid()->getCellMaterial(Vector3int16(kOffset, 62, kOffset)), CELL_MATERIAL_Water);
}
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(CastTo)
__!OK <pull main=[main=brancgh]const=('https://www.github.com/480132/Source-code-of-Roblox/edit/main/InstanceTest.cpp')