MCPcopy Create free account
hub / github.com/OpenApoc/OpenApoc / main

Function main

tests/test_tilemap.cpp:56–127  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

54}
55
56int main(int argc, char **argv)
57{
58 if (config().parseOptions(argc, argv))
59 {
60 return EXIT_FAILURE;
61 }
62 auto filled_slice_32_32 = mksp<VoxelSlice>(Vec2<int>{32, 32});
63 for (int y = 0; y < 32; y++)
64 {
65 for (int x = 0; x < 32; x++)
66 {
67 filled_slice_32_32->setBit({x, y}, true);
68 }
69 }
70
71 auto empty_tilemap_32_32_16 = mksp<VoxelMap>(Vec3<int>{32, 32, 16});
72 auto filled_tilemap_32_32_16 = mksp<VoxelMap>(Vec3<int>{32, 32, 16});
73 for (int z = 0; z < 16; z++)
74 {
75 filled_tilemap_32_32_16->setSlice(z, filled_slice_32_32);
76 }
77
78 // LayerMap is only used for drawing
79 TileMap map{{100, 100, 10}, {1, 1, 1}, {32, 32, 16}, {{TileObject::Type::Scenery}}};
80
81 // Spawn some objects
82 std::vector<std::pair<Vec3<float>, sp<TileObject>>> objects = {
83 {Vec3<float>{2.5, 2.5, 2.5},
84 mksp<FakeSceneryTileObject>(map, Vec3<float>{1, 1, 1}, filled_tilemap_32_32_16)},
85 {Vec3<float>{99.5, 99.5, 9.5},
86 mksp<FakeSceneryTileObject>(map, Vec3<float>{1, 1, 1}, filled_tilemap_32_32_16)},
87 };
88
89 for (auto &object : objects)
90 {
91 auto initialPosition = object.first;
92 object.second->setPosition(initialPosition);
93 if (initialPosition != object.second->getPosition())
94 {
95 LogError("Object %s moved from {%f,%f,%f} to {%f,%f,%f}", object.second->getName(),
96 initialPosition.x, initialPosition.y, initialPosition.z,
97 object.second->getPosition().x, object.second->getPosition().y,
98 object.second->getPosition().z);
99 exit(EXIT_FAILURE);
100 }
101 }
102
103 // Compare some expected collisions
104 //{{line_start,line_end},expected_object}
105 std::vector<std::pair<std::array<Vec3<float>, 2>, sp<TileObject>>> collisions = {
106 {{{Vec3<float>{0, 0, 0}, Vec3<float>{1, 1, 1}}}, nullptr},
107 {{{Vec3<float>{2.1, 2.1, 0}, Vec3<float>{2.1, 2.1, 4}}}, objects[0].second},
108 {{{Vec3<float>{2.6, 2.6, 0}, Vec3<float>{2.6, 2.6, 4}}}, objects[0].second},
109 {{{Vec3<float>{2.6, 0, 2.1}, Vec3<float>{2.6, 4, 2.1}}}, objects[0].second},
110 {{{Vec3<float>{2.6, 0, 2.6}, Vec3<float>{2.6, 4, 2.6}}}, objects[0].second},
111 {{{Vec3<float>{0, 2.1, 2.1}, Vec3<float>{4, 2.1, 2.1}}}, objects[0].second},
112 {{{Vec3<float>{0, 2.6, 2.6}, Vec3<float>{4, 2.6, 2.6}}}, objects[0].second},
113 {{{Vec3<float>{2.1, 2.1, 0}, Vec3<float>{2.1, 2.6, 4}}}, objects[0].second},

Callers

nothing calls this directly

Calls 7

test_collisionFunction · 0.85
setBitMethod · 0.80
setSliceMethod · 0.80
parseOptionsMethod · 0.45
setPositionMethod · 0.45
getPositionMethod · 0.45
getNameMethod · 0.45

Tested by

no test coverage detected