2013-04-22 17:49:28 +03:00
|
|
|
/*
|
|
|
|
* CMapEditManagerTest.cpp, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "StdInc.h"
|
|
|
|
|
2023-08-23 14:07:50 +02:00
|
|
|
#include "../lib/filesystem/ResourcePath.h"
|
2013-04-22 17:49:28 +03:00
|
|
|
#include "../lib/mapping/CMapService.h"
|
|
|
|
#include "../lib/mapping/CMap.h"
|
2023-02-28 13:29:35 +02:00
|
|
|
#include "../lib/TerrainHandler.h"
|
2013-04-22 17:49:28 +03:00
|
|
|
#include "../lib/mapping/CMapEditManager.h"
|
|
|
|
#include "../lib/int3.h"
|
|
|
|
#include "../lib/CRandomGenerator.h"
|
2013-08-17 15:46:48 +03:00
|
|
|
#include "../lib/VCMI_Lib.h"
|
2013-04-22 17:49:28 +03:00
|
|
|
|
2017-06-14 10:56:35 +02:00
|
|
|
|
2017-07-04 13:29:50 +02:00
|
|
|
TEST(MapManager, DrawTerrain_Type)
|
2013-05-03 13:15:59 +03:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2024-01-10 21:30:12 +02:00
|
|
|
auto map = std::make_unique<CMap>(nullptr);
|
2024-07-19 14:17:06 +02:00
|
|
|
CRandomGenerator rand;
|
2015-08-11 21:50:08 +02:00
|
|
|
map->width = 52;
|
|
|
|
map->height = 52;
|
2013-05-03 13:15:59 +03:00
|
|
|
map->initTerrain();
|
|
|
|
auto editManager = map->getEditManager();
|
2024-07-19 14:17:06 +02:00
|
|
|
editManager->clearTerrain(&rand);
|
2013-05-03 13:15:59 +03:00
|
|
|
|
|
|
|
// 1x1 Blow up
|
|
|
|
editManager->getTerrainSelection().select(int3(5, 5, 0));
|
2024-07-19 14:17:06 +02:00
|
|
|
editManager->drawTerrain(ETerrainId::GRASS, 10, &rand);
|
2013-05-03 13:15:59 +03:00
|
|
|
static const int3 squareCheck[] = { int3(5,5,0), int3(5,4,0), int3(4,4,0), int3(4,5,0) };
|
2023-04-25 11:02:31 +02:00
|
|
|
for(const auto & tile : squareCheck)
|
2013-05-03 13:15:59 +03:00
|
|
|
{
|
2023-04-25 11:02:31 +02:00
|
|
|
EXPECT_EQ(map->getTile(tile).terType->getId(), ETerrainId::GRASS);
|
2013-05-03 13:15:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Concat to square
|
|
|
|
editManager->getTerrainSelection().select(int3(6, 5, 0));
|
2024-07-19 14:17:06 +02:00
|
|
|
editManager->drawTerrain(ETerrainId::GRASS, 10, &rand);
|
2023-02-28 13:29:35 +02:00
|
|
|
EXPECT_EQ(map->getTile(int3(6, 4, 0)).terType->getId(), ETerrainId::GRASS);
|
2013-05-03 13:15:59 +03:00
|
|
|
editManager->getTerrainSelection().select(int3(6, 5, 0));
|
2024-07-19 14:17:06 +02:00
|
|
|
editManager->drawTerrain(ETerrainId::LAVA, 10, &rand);
|
2023-02-28 13:29:35 +02:00
|
|
|
EXPECT_EQ(map->getTile(int3(4, 4, 0)).terType->getId(), ETerrainId::GRASS);
|
|
|
|
EXPECT_EQ(map->getTile(int3(7, 4, 0)).terType->getId(), ETerrainId::LAVA);
|
2013-05-03 13:15:59 +03:00
|
|
|
|
|
|
|
// Special case water,rock
|
|
|
|
editManager->getTerrainSelection().selectRange(MapRect(int3(10, 10, 0), 10, 5));
|
2024-07-19 14:17:06 +02:00
|
|
|
editManager->drawTerrain(ETerrainId::GRASS, 10, &rand);
|
2013-05-03 13:15:59 +03:00
|
|
|
editManager->getTerrainSelection().selectRange(MapRect(int3(15, 17, 0), 10, 5));
|
2024-07-19 14:17:06 +02:00
|
|
|
editManager->drawTerrain(ETerrainId::GRASS, 10, &rand);
|
2013-05-03 13:15:59 +03:00
|
|
|
editManager->getTerrainSelection().select(int3(21, 16, 0));
|
2024-07-19 14:17:06 +02:00
|
|
|
editManager->drawTerrain(ETerrainId::GRASS, 10, &rand);
|
2023-02-28 13:29:35 +02:00
|
|
|
EXPECT_EQ(map->getTile(int3(20, 15, 0)).terType->getId(), ETerrainId::GRASS);
|
2013-05-03 13:15:59 +03:00
|
|
|
|
|
|
|
// Special case non water,rock
|
|
|
|
static const int3 diagonalCheck[] = { int3(31,42,0), int3(32,42,0), int3(32,43,0), int3(33,43,0), int3(33,44,0),
|
2017-07-04 13:29:50 +02:00
|
|
|
int3(34,44,0), int3(34,45,0), int3(35,45,0), int3(35,46,0), int3(36,46,0),
|
|
|
|
int3(36,47,0), int3(37,47,0)};
|
2023-04-25 11:02:31 +02:00
|
|
|
for(const auto & tile : diagonalCheck)
|
2013-05-03 13:15:59 +03:00
|
|
|
{
|
2023-04-25 11:02:31 +02:00
|
|
|
editManager->getTerrainSelection().select(tile);
|
2013-05-03 13:15:59 +03:00
|
|
|
}
|
2024-07-19 14:17:06 +02:00
|
|
|
editManager->drawTerrain(ETerrainId::GRASS, 10, &rand);
|
2023-02-28 13:29:35 +02:00
|
|
|
EXPECT_EQ(map->getTile(int3(35, 44, 0)).terType->getId(), ETerrainId::WATER);
|
2015-03-22 21:32:22 +02:00
|
|
|
|
|
|
|
// Rock case
|
|
|
|
editManager->getTerrainSelection().selectRange(MapRect(int3(1, 1, 1), 15, 15));
|
2024-07-19 14:17:06 +02:00
|
|
|
editManager->drawTerrain(ETerrainId::SUBTERRANEAN, 10, &rand);
|
2015-03-22 21:32:22 +02:00
|
|
|
std::vector<int3> vec({ int3(6, 6, 1), int3(7, 6, 1), int3(8, 6, 1), int3(5, 7, 1), int3(6, 7, 1), int3(7, 7, 1),
|
|
|
|
int3(8, 7, 1), int3(4, 8, 1), int3(5, 8, 1), int3(6, 8, 1)});
|
|
|
|
editManager->getTerrainSelection().setSelection(vec);
|
2024-07-19 14:17:06 +02:00
|
|
|
editManager->drawTerrain(ETerrainId::ROCK, 10, &rand);
|
2022-09-21 11:34:23 +02:00
|
|
|
EXPECT_TRUE(!map->getTile(int3(5, 6, 1)).terType->isPassable() || !map->getTile(int3(7, 8, 1)).terType->isPassable());
|
2015-03-22 21:32:22 +02:00
|
|
|
|
2015-08-11 21:50:08 +02:00
|
|
|
//todo: add checks here and enable, also use smaller size
|
2015-11-13 16:47:47 +02:00
|
|
|
#if 0
|
|
|
|
|
2015-03-22 21:32:22 +02:00
|
|
|
// next check
|
|
|
|
auto map2 = make_unique<CMap>();
|
|
|
|
map2->width = 128;
|
|
|
|
map2->height = 128;
|
|
|
|
map2->initTerrain();
|
|
|
|
auto editManager2 = map2->getEditManager();
|
|
|
|
|
|
|
|
editManager2->getTerrainSelection().selectRange(MapRect(int3(0, 0, 1), 128, 128));
|
2022-06-20 16:39:50 +02:00
|
|
|
editManager2->drawTerrain(CTerrainType("subterra"));
|
2015-03-22 21:32:22 +02:00
|
|
|
|
|
|
|
std::vector<int3> selection({ int3(95, 43, 1), int3(95, 44, 1), int3(94, 45, 1), int3(95, 45, 1), int3(96, 45, 1),
|
|
|
|
int3(93, 46, 1), int3(94, 46, 1), int3(95, 46, 1), int3(96, 46, 1), int3(97, 46, 1),
|
|
|
|
int3(98, 46, 1), int3(99, 46, 1)});
|
|
|
|
editManager2->getTerrainSelection().setSelection(selection);
|
2022-06-20 16:39:50 +02:00
|
|
|
editManager2->drawTerrain(CTerrainType("rock"));
|
2015-08-11 21:50:08 +02:00
|
|
|
#endif // 0
|
2015-03-22 21:32:22 +02:00
|
|
|
|
2013-05-03 13:15:59 +03:00
|
|
|
}
|
|
|
|
catch(const std::exception & e)
|
|
|
|
{
|
2017-07-18 21:18:37 +02:00
|
|
|
FAIL()<<e.what();
|
2015-08-11 21:50:08 +02:00
|
|
|
throw;
|
2015-11-13 16:47:47 +02:00
|
|
|
}
|
2013-05-03 13:15:59 +03:00
|
|
|
}
|
|
|
|
|
2017-07-04 13:29:50 +02:00
|
|
|
TEST(MapManager, DrawTerrain_View)
|
2013-04-22 17:49:28 +03:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2023-08-23 14:07:50 +02:00
|
|
|
const ResourcePath testMap("test/TerrainViewTest", EResType::MAP);
|
2015-03-22 21:32:22 +02:00
|
|
|
// Load maps and json config
|
2017-07-20 06:08:49 +02:00
|
|
|
CMapService mapService;
|
2024-01-10 21:30:12 +02:00
|
|
|
const auto originalMap = mapService.loadMap(testMap, nullptr);
|
|
|
|
auto map = mapService.loadMap(testMap, nullptr);
|
2013-04-22 17:49:28 +03:00
|
|
|
|
|
|
|
// Validate edit manager
|
|
|
|
auto editManager = map->getEditManager();
|
|
|
|
CRandomGenerator gen;
|
2023-09-01 23:26:14 +02:00
|
|
|
const JsonNode viewNode(JsonPath::builtin("test/terrainViewMappings"));
|
2013-04-22 17:49:28 +03:00
|
|
|
const auto & mappingsNode = viewNode["mappings"].Vector();
|
2013-07-06 19:10:20 +03:00
|
|
|
for (const auto & node : mappingsNode)
|
2013-04-22 17:49:28 +03:00
|
|
|
{
|
|
|
|
// Get terrain group and id
|
|
|
|
const auto & patternStr = node["pattern"].String();
|
|
|
|
std::vector<std::string> patternParts;
|
|
|
|
boost::split(patternParts, patternStr, boost::is_any_of("."));
|
|
|
|
if(patternParts.size() != 2) throw std::runtime_error("A pattern should consist of two parts, the group and the id. Continue with next pattern.");
|
|
|
|
const auto & groupStr = patternParts[0];
|
|
|
|
const auto & id = patternParts[1];
|
|
|
|
|
|
|
|
// Get mapping range
|
2022-06-28 10:05:30 +02:00
|
|
|
const auto & pattern = VLC->terviewh->getTerrainViewPatternById(groupStr, id);
|
2023-04-25 11:02:31 +02:00
|
|
|
const auto & mapping = pattern->get().mapping;
|
2013-04-22 17:49:28 +03:00
|
|
|
|
|
|
|
const auto & positionsNode = node["pos"].Vector();
|
2013-07-06 19:10:20 +03:00
|
|
|
for (const auto & posNode : positionsNode)
|
2013-04-22 17:49:28 +03:00
|
|
|
{
|
|
|
|
const auto & posVector = posNode.Vector();
|
|
|
|
if(posVector.size() != 3) throw std::runtime_error("A position should consist of three values x,y,z. Continue with next position.");
|
Fixed a bad fix. Fixed more warnings.
These warnings have not been fixed because the are legitimate and/or I don't know how to fix them:
test\googletest\googletest\include\gtest/gtest-printers.h(888,43): warning C4996: 'std::tr1': warning STL4002: The non-Standard std::tr1 namespace and TR1-only machinery are deprecated and will be REMOVED.
lib\serializer\JsonSerializeFormat.h(523,26): warning C4244: 'argument': conversion from 'type1' to 'type2', possible loss of data
include\boost/iostreams/positioning.hpp(96,15): warning C4996: 'std::fpos<_Mbstatet>::seekpos': warning STL4019: The member std::fpos::seekpos() is non-Standard, ...
source\lib\filesystem\FileStream.h(39,69): warning C4910: 'boost::iostreams::stream<FileBuf,std::char_traits<char>,std::allocator<char>>': '__declspec(dllexport)' and 'extern' are incompatible on an explicit instantiation
include\boost/optional/optional.hpp(274,53): warning C4244: 'argument': conversion from 'T' to 'T', possible loss of data
client\widgets\../gui/SDL_Extensions.h(112,14): warning C4244: 'initializing': conversion from 'type1' to 'type2', possible loss of data
client\CServerHandler.cpp(421,24): warning C4834: discarding return value of function with 'nodiscard' attribute (see https://bugs.vcmi.eu/view.php?id=3144)
client\CVideoHandler.cpp(130,25): warning C4996: 'AVStream::codec': was declared deprecated
2020-10-05 01:00:38 +02:00
|
|
|
int3 pos((si32)posVector[0].Float(), (si32)posVector[1].Float(), (si32)posVector[2].Float());
|
2013-04-22 17:49:28 +03:00
|
|
|
const auto & originalTile = originalMap->getTile(pos);
|
2013-04-29 18:51:39 +03:00
|
|
|
editManager->getTerrainSelection().selectRange(MapRect(pos, 1, 1));
|
2023-12-22 17:56:43 +02:00
|
|
|
editManager->drawTerrain(originalTile.terType->getId(), 10, &gen);
|
2013-04-22 17:49:28 +03:00
|
|
|
const auto & tile = map->getTile(pos);
|
|
|
|
bool isInRange = false;
|
2013-07-06 19:10:20 +03:00
|
|
|
for(const auto & range : mapping)
|
2013-04-22 17:49:28 +03:00
|
|
|
{
|
|
|
|
if(tile.terView >= range.first && tile.terView <= range.second)
|
|
|
|
{
|
|
|
|
isInRange = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-07-04 13:29:50 +02:00
|
|
|
EXPECT_TRUE(isInRange);
|
2016-08-11 10:06:06 +02:00
|
|
|
if(!isInRange)
|
2017-07-18 21:18:37 +02:00
|
|
|
FAIL()<<("No or invalid pattern found for current position.");
|
2013-04-22 17:49:28 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(const std::exception & e)
|
|
|
|
{
|
2017-07-18 21:18:37 +02:00
|
|
|
FAIL()<<e.what();
|
2015-08-11 21:50:08 +02:00
|
|
|
throw;
|
2013-04-22 17:49:28 +03:00
|
|
|
}
|
|
|
|
}
|