Some improvements, added cutscene stub

This commit is contained in:
Vladislav Khorev committed 2026-05-09 23:31:49 +03:00
1 parent 72e05cdc28
commit be05643b70
27 files changed
+3480 -40

No files matched your search

+94
View File
@@ -5,6 +5,7 @@
#include <cmath>
#include <fstream>
#include <iostream>
#include <sstream>
#include <limits>
#include <queue>
@@ -94,6 +95,19 @@ void PathFinder::build(const std::string& configPath,
loadedConfigPath = configPath;
loadedZipPath = zipPath;
const bool isTxt = configPath.size() >= 4 &&
configPath.compare(configPath.size() - 4, 4, ".txt") == 0;
if (isTxt) {
if (loadGrid(configPath, zipPath)) {
ready = true;
std::cout << "[nav] Loaded precomputed grid: " << gridWidth << "x" << gridDepth
<< ", cell=" << cellSize << "\n";
} else {
std::cerr << "[nav] Failed to load precomputed grid: " << configPath << "\n";
}
return;
}
loadConfig(configPath, zipPath);
resetGridBounds();
@@ -460,6 +474,86 @@ bool PathFinder::saveConfig(const std::string& path) const
return f.good();
}
bool PathFinder::saveGrid(const std::string& path) const
{
if (!ready) return false;
std::ofstream f(path);
if (!f.is_open()) return false;
f << "cellSize " << cellSize << "\n"
<< "agentRadius " << agentRadius << "\n"
<< "floorY " << floorY << "\n"
<< "objectPadding " << objectPadding << "\n"
<< "boundaryPadding " << boundaryPadding << "\n"
<< "minX " << minX << "\n"
<< "minZ " << minZ << "\n"
<< "gridWidth " << gridWidth << "\n"
<< "gridDepth " << gridDepth << "\n";
for (int z = 0; z < gridDepth; ++z) {
for (int x = 0; x < gridWidth; ++x) {
f << (walkable[static_cast<size_t>(z * gridWidth + x)] ? '1' : '0');
}
f << '\n';
}
return f.good();
}
bool PathFinder::loadGrid(const std::string& path, const std::string& zipPath)
{
std::string content;
try {
if (!zipPath.empty()) {
const auto bytes = readFileFromZIP(path, zipPath);
content.assign(bytes.begin(), bytes.end());
} else {
content = readTextFile(path);
}
} catch (const std::exception& e) {
std::cerr << "[nav] loadGrid error: " << e.what() << "\n";
return false;
}
if (content.empty()) return false;
std::istringstream ss(content);
std::string line;
auto tryHeader = [&](const std::string& ln) -> bool {
std::istringstream ls(ln);
std::string key;
if (!(ls >> key)) return false;
if (key == "cellSize") { ls >> cellSize; return true; }
else if (key == "agentRadius") { ls >> agentRadius; return true; }
else if (key == "floorY") { ls >> floorY; return true; }
else if (key == "objectPadding") { ls >> objectPadding; return true; }
else if (key == "boundaryPadding") { ls >> boundaryPadding; return true; }
else if (key == "minX") { ls >> minX; return true; }
else if (key == "minZ") { ls >> minZ; return true; }
else if (key == "gridWidth") { ls >> gridWidth; return true; }
else if (key == "gridDepth") { ls >> gridDepth; return true; }
return false;
};
std::vector<std::string> rows;
bool headerDone = false;
while (std::getline(ss, line)) {
if (!headerDone && tryHeader(line)) continue;
headerDone = true;
if (!line.empty()) rows.push_back(line);
}
if (gridWidth <= 0 || gridDepth <= 0) return false;
walkable.assign(static_cast<size_t>(gridWidth * gridDepth), 0);
for (int z = 0; z < static_cast<int>(rows.size()) && z < gridDepth; ++z) {
const std::string& row = rows[z];
for (int x = 0; x < static_cast<int>(row.size()) && x < gridWidth; ++x) {
walkable[static_cast<size_t>(z * gridWidth + x)] = (row[x] == '1') ? 1 : 0;
}
}
return true;
}
void PathFinder::loadConfig(const std::string& configPath, const std::string& zipPath)
{
cellSize = 0.4f;
+2
View File
@@ -50,6 +50,7 @@ public:
void addObstaclePolygon(const ObstaclePolygon& polygon);
bool saveConfig(const std::string& path) const;
bool saveGrid(const std::string& path) const;
private:
@@ -72,6 +73,7 @@ private:
std::vector<NavigationArea> areas;
void loadConfig(const std::string& configPath, const std::string& zipPath);
bool loadGrid(const std::string& path, const std::string& zipPath);
void resetGridBounds();
void rebuildWalkableGrid();
void markAvailableAreasWalkable();