add SurroundMap.resize(...)

This commit is contained in:
MihailRis
2024-09-10 23:02:15 +03:00
parent ab110ab8bf
commit 80d8a6738b
2 changed files with 15 additions and 4 deletions
+8 -3
View File
@@ -4,9 +4,9 @@
#include <cstring> #include <cstring>
#include <stdexcept> #include <stdexcept>
SurroundMap::SurroundMap(int loadDistance, int8_t maxLevel) SurroundMap::SurroundMap(int maxLevelRadius, int8_t maxLevel)
: areaMap((loadDistance + maxLevel) * 2 + 1, : areaMap((maxLevelRadius + maxLevel) * 2 + 1,
(loadDistance + maxLevel) * 2 + 1), (maxLevelRadius + maxLevel) * 2 + 1),
levelCallbacks(maxLevel), levelCallbacks(maxLevel),
maxLevel(maxLevel) maxLevel(maxLevel)
{} {}
@@ -43,6 +43,11 @@ void SurroundMap::upgrade(int x, int y, int8_t level) {
} }
} }
void SurroundMap::resize(int maxLevelRadius) {
areaMap.resize((maxLevelRadius + maxLevel) * 2 + 1,
(maxLevelRadius + maxLevel) * 2 + 1);
}
void SurroundMap::completeAt(int x, int y) { void SurroundMap::completeAt(int x, int y) {
if (!areaMap.isInside(x - maxLevel + 1, y - maxLevel + 1) || if (!areaMap.isInside(x - maxLevel + 1, y - maxLevel + 1) ||
!areaMap.isInside(x + maxLevel - 1, y + maxLevel - 1)) { !areaMap.isInside(x + maxLevel - 1, y + maxLevel - 1)) {
+7 -1
View File
@@ -23,7 +23,7 @@ private:
void upgrade(int x, int y, int8_t level); void upgrade(int x, int y, int8_t level);
public: public:
SurroundMap(int loadDistance, int8_t maxLevel); SurroundMap(int maxLevelRadius, int8_t maxLevel);
/// @brief Callback called on point level increments /// @brief Callback called on point level increments
void setLevelCallback(int8_t level, LevelCallback callback); void setLevelCallback(int8_t level, LevelCallback callback);
@@ -38,7 +38,13 @@ public:
/// @brief Set map area center /// @brief Set map area center
void setCenter(int x, int y); void setCenter(int x, int y);
void resize(int maxLevelRadius);
/// @brief Get level at position /// @brief Get level at position
/// @throws std::invalid_argument - position is out of area /// @throws std::invalid_argument - position is out of area
int8_t at(int x, int y); int8_t at(int x, int y);
const util::AreaMap2D<int8_t>& getArea() const {
return areaMap;
}
}; };