little cleanup
This commit is contained in:
1 parent
13ef92160d
commit
72e05cdc28
15 files changed
+323
-197
No files matched your search
+31
-36
@@ -158,38 +158,32 @@ namespace ZL
|
||||
|
||||
std::cout << "Load resurces step 4" << std::endl;
|
||||
|
||||
LocationSetup params1;
|
||||
params1.roomMeshPath = "resources/w/room003.txt";
|
||||
params1.roomTexturePath = "resources/w/room005.png";
|
||||
params1.gameObjectsJsonPath = "resources/config2/gameobjects.json";
|
||||
params1.npcsJsonPath = "resources/config2/npcs.json";
|
||||
params1.dialoguesJsonPath = "resources/dialogue/sample_dialogues.json";
|
||||
params1.navigationJsonPaths = {"resources/config2/navigation.json"};
|
||||
params1.teleportsJsonPath = "resources/config2/teleports.json";
|
||||
params1.triggerZonesJsonPath = "resources/config2/trigger_zones.json";
|
||||
params1.scriptPath = "resources/start.lua";
|
||||
params1.playerPosition = Eigen::Vector3f(0.942694, 0, -9.63104);
|
||||
LocationSetup uniInteriorParams;
|
||||
uniInteriorParams.gameObjectsJsonPath = "resources/config2/gameobjects.json";
|
||||
uniInteriorParams.npcsJsonPath = "resources/config2/npcs_uni_interior.json";
|
||||
uniInteriorParams.dialoguesJsonPath = "resources/dialogue/uni_interior_dialogues.json";
|
||||
uniInteriorParams.navigationJsonPaths = {"resources/config2/navigation.json"};
|
||||
uniInteriorParams.teleportsJsonPath = "resources/config2/teleports.json";
|
||||
uniInteriorParams.triggerZonesJsonPath = "resources/config2/trigger_zones_uni_interior.json";
|
||||
uniInteriorParams.scriptPath = "resources/start_uni_interior.lua";
|
||||
uniInteriorParams.playerPosition = Eigen::Vector3f(0.942694, 0, -9.63104);
|
||||
|
||||
locations["location1"] = std::make_shared<Location>(renderer, inventory);
|
||||
locations["location1"]->setup(params1);
|
||||
locations["uni_interior"] = std::make_shared<Location>(renderer, inventory);
|
||||
locations["uni_interior"]->setup(uniInteriorParams);
|
||||
|
||||
LocationSetup params2 = params1;
|
||||
params2.roomMeshPath = "resources/w/exterior/Segmented_Plane002.txt";
|
||||
params2.roomTexturePath = "resources/w/exterior/Segmented_Plane002.png";
|
||||
params2.gameObjectsJsonPath = "resources/config2/gameobjects2.json";
|
||||
params2.navigationJsonPaths = {"resources/config2/navigation2.json"};
|
||||
params2.teleportsJsonPath = "resources/config2/teleports2.json";
|
||||
params2.triggerZonesJsonPath = "resources/config2/trigger_zones2.json";
|
||||
params2.scriptPath = "resources/start2.lua";
|
||||
params2.playerPosition = Eigen::Vector3f(5, 0, -18.4);
|
||||
params2.npcsJsonPath = "resources/config2/npcs2.json";
|
||||
LocationSetup uniExteriorParams = uniInteriorParams;
|
||||
uniExteriorParams.gameObjectsJsonPath = "resources/config2/gameobjects2.json";
|
||||
uniExteriorParams.navigationJsonPaths = {"resources/config2/navigation2.json"};
|
||||
uniExteriorParams.teleportsJsonPath = "resources/config2/teleports2.json";
|
||||
uniExteriorParams.triggerZonesJsonPath = "resources/config2/trigger_zones2.json";
|
||||
uniExteriorParams.scriptPath = "resources/start2.lua";
|
||||
uniExteriorParams.playerPosition = Eigen::Vector3f(5, 0, -18.4);
|
||||
uniExteriorParams.npcsJsonPath = "resources/config2/npcs2.json";
|
||||
locations["uni_exterior"] = std::make_shared<Location>(renderer, inventory);
|
||||
locations["uni_exterior"]->setup(uniExteriorParams);
|
||||
|
||||
locations["location2"] = std::make_shared<Location>(renderer, inventory);
|
||||
locations["location2"]->setup(params2);
|
||||
|
||||
LocationSetup params_dorm;
|
||||
params_dorm.roomMeshPath = "";
|
||||
params_dorm.roomTexturePath = "";
|
||||
params_dorm.gameObjectsJsonPath = "resources/config2/gameobjects_dorm.json";
|
||||
params_dorm.npcsJsonPath = "resources/config2/npcs_dorm.json";
|
||||
params_dorm.dialoguesJsonPath = "resources/dialogue/dorm_dialogues.json";
|
||||
@@ -203,9 +197,8 @@ namespace ZL
|
||||
locations["location_dorm"]->setup(params_dorm);
|
||||
|
||||
// Teleport callbacks: destination name and position come from the teleport zone data.
|
||||
auto makeTeleportCallback = [this](const std::string& sourceName) {
|
||||
return [this, sourceName](const std::string& destName, const Eigen::Vector3f& destPos, float destRotY) {
|
||||
std::cout << "[TELEPORT] " << sourceName << " -> " << destName << std::endl;
|
||||
auto teleportCallback = [this](const std::string& destName, const Eigen::Vector3f& destPos, float destRotY) {
|
||||
std::cout << "[TELEPORT] " << " -> " << destName << std::endl;
|
||||
auto it = locations.find(destName);
|
||||
if (it == locations.end()) {
|
||||
std::cerr << "[TELEPORT] Unknown destination location: " << destName << std::endl;
|
||||
@@ -219,12 +212,12 @@ namespace ZL
|
||||
currentLocation->player->targetFacingAngle = destRotY;
|
||||
}
|
||||
currentLocation->cameraAzimuth = destRotY;
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
locations["location1"]->onTeleport = makeTeleportCallback("location1");
|
||||
locations["location2"]->onTeleport = makeTeleportCallback("location2");
|
||||
locations["location_dorm"]->onTeleport = makeTeleportCallback("location_dorm");
|
||||
locations["uni_exterior"]->onTeleport = teleportCallback;
|
||||
locations["uni_interior"]->onTeleport = teleportCallback;
|
||||
locations["location_dorm"]->onTeleport = teleportCallback;
|
||||
|
||||
currentLocation = locations["location_dorm"];
|
||||
|
||||
@@ -548,8 +541,10 @@ namespace ZL
|
||||
break;
|
||||
|
||||
case SDLK_p:
|
||||
currentLocation = (currentLocation == locations["location1"]) ? locations["location2"] : locations["location1"];
|
||||
std::cout << "Switched to location " << ((currentLocation == locations["location1"]) ? "1" : "2") << std::endl;
|
||||
currentLocation = locations["uni_interior"];
|
||||
currentLocation->player->position = Eigen::Vector3f(-0.0189243, 0, -13.4314);
|
||||
currentLocation->player->setTarget(currentLocation->player->position);
|
||||
//std::cout << "Switched to location " << ((currentLocation == locations["location1"]) ? "1" : "2") << std::endl;
|
||||
break;
|
||||
|
||||
case SDLK_l:
|
||||
|
||||
+1
-30
@@ -52,11 +52,6 @@ namespace ZL
|
||||
|
||||
void Location::setup(const LocationSetup& params)
|
||||
{
|
||||
/*
|
||||
roomTexture = renderer.textureManager.LoadFromPng(params.roomTexturePath, CONST_ZIP_FILE);
|
||||
roomMesh.data = LoadFromTextFile02(params.roomMeshPath, CONST_ZIP_FILE);
|
||||
roomMesh.data.RotateByMatrix(Eigen::Quaternionf(Eigen::AngleAxisf(-M_PI * 0.5, Eigen::Vector3f::UnitY())).toRotationMatrix());
|
||||
roomMesh.RefreshVBO();*/
|
||||
|
||||
// Load static game objects
|
||||
gameObjects = GameObjectLoader::loadAndCreateGameObjects(params.gameObjectsJsonPath, renderer, CONST_ZIP_FILE);
|
||||
@@ -64,22 +59,12 @@ namespace ZL
|
||||
// Load interactive objects
|
||||
interactiveObjects = GameObjectLoader::loadAndCreateInteractiveObjects(params.gameObjectsJsonPath, renderer, CONST_ZIP_FILE);
|
||||
|
||||
|
||||
//auto playerTexture = std::make_shared<Texture>(CreateTextureDataFromPng("resources/w/gg/IMG_20260413_182354_992.png", CONST_ZIP_FILE));
|
||||
auto playerTexture = renderer.textureManager.LoadFromPng("resources/w/gg/UniV_Grid_2K_Base_color.png", CONST_ZIP_FILE);
|
||||
|
||||
auto sparkTexture = renderer.textureManager.LoadFromPng("resources/w/spark.png", CONST_ZIP_FILE);
|
||||
|
||||
player = std::make_unique<Character>();
|
||||
/*
|
||||
player->loadBinaryAnimation(AnimationState::STAND, "resources/w/gg/gg_stand_idle001.anim", CONST_ZIP_FILE);
|
||||
player->loadBinaryAnimation(AnimationState::WALK, "resources/w/gg/gg_walking001.anim", CONST_ZIP_FILE);
|
||||
player->loadBinaryAnimation(AnimationState::STAND_TO_ACTION, "resources/w/gg/gg_stand_to_action002.anim", CONST_ZIP_FILE);
|
||||
player->loadBinaryAnimation(AnimationState::ACTION_ATTACK, "resources/w/gg/gg_action_attack001.anim", CONST_ZIP_FILE);
|
||||
player->loadBinaryAnimation(AnimationState::ACTION_IDLE, "resources/w/gg/gg_action_idle001.anim", CONST_ZIP_FILE);
|
||||
player->loadBinaryAnimation(AnimationState::ACTION_TO_STAND, "resources/w/gg/gg_action_to_stand001.anim", CONST_ZIP_FILE);
|
||||
*/
|
||||
|
||||
|
||||
player->loadBinaryAnimation(AnimationState::STAND, "resources/w/gg/new/gg_stand_idle001.anim", CONST_ZIP_FILE);
|
||||
player->loadBinaryAnimation(AnimationState::WALK, "resources/w/gg/new/gg_walk001.anim", CONST_ZIP_FILE);
|
||||
@@ -95,11 +80,8 @@ namespace ZL
|
||||
|
||||
|
||||
player->weaponTexture = renderer.textureManager.LoadFromPng("resources/w/white.png", CONST_ZIP_FILE);
|
||||
//player->weaponMesh.AssignFrom(LoadFromTextFile02("resources/w/gg/knife001.txt", CONST_ZIP_FILE));
|
||||
|
||||
player->weaponMesh.data = LoadFromTextFile02("resources/w/gg/knife002.txt", CONST_ZIP_FILE);
|
||||
player->weaponMesh.data.Scale(0.1f);
|
||||
//player->weaponMesh.data.RotateByMatrix(Eigen::Quaternionf(Eigen::AngleAxisf(-M_PI * 0.5, Eigen::Vector3f::UnitY())).toRotationMatrix());
|
||||
player->weaponMesh.RefreshVBO();
|
||||
player->weaponAttachBoneName = "RightHand";
|
||||
player->weaponInitialRotation = Eigen::AngleAxisf(-M_PI * 0.5, Eigen::Vector3f::UnitZ()).toRotationMatrix();
|
||||
@@ -156,17 +138,6 @@ namespace ZL
|
||||
std::cerr << "Failed to init NPC name TextRenderer" << std::endl;
|
||||
npcNameText.reset();
|
||||
}
|
||||
//dialogueSystem.loadDatabase("resources/dialogue/sample_dialogues.json");
|
||||
/*dialogueSystem.addTriggerZone({
|
||||
"ghost_room_trigger",
|
||||
"test_line_dialogue",
|
||||
Eigen::Vector3f(0.0f, 0.0f, -8.5f),
|
||||
2.0f,
|
||||
true,
|
||||
false
|
||||
});*/
|
||||
|
||||
// navigationMapPaths is already populated by setupNavigation
|
||||
|
||||
scriptEngine.init(this, &inventory, params.scriptPath);
|
||||
|
||||
@@ -303,7 +274,7 @@ namespace ZL
|
||||
navigationMaps.resize(paths.size());
|
||||
|
||||
for (size_t i = 0; i < paths.size(); ++i) {
|
||||
navigationMaps[i].build({}, paths[i], CONST_ZIP_FILE);
|
||||
navigationMaps[i].build(paths[i], CONST_ZIP_FILE);
|
||||
}
|
||||
|
||||
activeNavigationIndex = 0;
|
||||
|
||||
@@ -31,8 +31,6 @@ namespace ZL
|
||||
|
||||
struct LocationSetup
|
||||
{
|
||||
std::string roomMeshPath;
|
||||
std::string roomTexturePath;
|
||||
std::string gameObjectsJsonPath;
|
||||
std::string npcsJsonPath;
|
||||
std::string dialoguesJsonPath;
|
||||
@@ -48,10 +46,6 @@ namespace ZL
|
||||
public:
|
||||
Location(Renderer& iRenderer, Inventory& iInventory);
|
||||
|
||||
|
||||
//std::shared_ptr<Texture> roomTexture;
|
||||
//VertexRenderStruct roomMesh;
|
||||
|
||||
std::unordered_map<std::string, LoadedGameObject> gameObjects;
|
||||
|
||||
std::vector<InteractiveObject> interactiveObjects;
|
||||
|
||||
@@ -87,14 +87,12 @@ namespace {
|
||||
}
|
||||
}
|
||||
|
||||
void PathFinder::build(const std::vector<ObstacleMesh>& obstacleMeshes,
|
||||
const std::string& configPath,
|
||||
void PathFinder::build(const std::string& configPath,
|
||||
const std::string& zipPath)
|
||||
{
|
||||
ready = false;
|
||||
loadedConfigPath = configPath;
|
||||
loadedZipPath = zipPath;
|
||||
obstacles = obstacleMeshes;
|
||||
|
||||
loadConfig(configPath, zipPath);
|
||||
resetGridBounds();
|
||||
@@ -563,16 +561,6 @@ void PathFinder::resetGridBounds()
|
||||
}
|
||||
}
|
||||
|
||||
for (const ObstacleMesh& obstacle : obstacles) {
|
||||
if (!obstacle.mesh) {
|
||||
continue;
|
||||
}
|
||||
for (const Eigen::Vector3f& point : obstacle.mesh->PositionData) {
|
||||
const Eigen::Vector3f worldPoint = point + obstacle.offset;
|
||||
includePoint(worldPoint.x(), worldPoint.z());
|
||||
}
|
||||
}
|
||||
|
||||
for (const ObstaclePolygon& obstacle : obstaclePolygons) {
|
||||
for (const Eigen::Vector2f& point : obstacle.polygon) {
|
||||
includePoint(point.x(), point.y());
|
||||
@@ -593,7 +581,6 @@ void PathFinder::rebuildWalkableGrid()
|
||||
{
|
||||
walkable.assign(static_cast<size_t>(gridWidth * gridDepth), 0);
|
||||
markAvailableAreasWalkable();
|
||||
markObstacleMeshesBlocked();
|
||||
markObstaclePolygonsBlocked();
|
||||
}
|
||||
|
||||
@@ -708,49 +695,6 @@ void PathFinder::markObstaclePolygonsBlocked()
|
||||
}
|
||||
}
|
||||
|
||||
void PathFinder::markObstacleMeshesBlocked()
|
||||
{
|
||||
if (!obstaclePolygons.empty()) {
|
||||
// Prefer JSON-defined obstacle polygons over mesh-derived blockers.
|
||||
// Mesh blockers tend to over-block (e.g. tree crowns) and are harder to author/tune.
|
||||
return;
|
||||
}
|
||||
|
||||
const float padding = agentRadius + objectPadding;
|
||||
|
||||
for (const ObstacleMesh& obstacle : obstacles) {
|
||||
if (!obstacle.mesh || obstacle.mesh->PositionData.empty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Eigen::Vector3f minPoint = obstacle.mesh->PositionData[0] + obstacle.offset;
|
||||
Eigen::Vector3f maxPoint = minPoint;
|
||||
for (const Eigen::Vector3f& localPoint : obstacle.mesh->PositionData) {
|
||||
const Eigen::Vector3f point = localPoint + obstacle.offset;
|
||||
minPoint = minPoint.cwiseMin(point);
|
||||
maxPoint = maxPoint.cwiseMax(point);
|
||||
}
|
||||
|
||||
Cell from;
|
||||
Cell to;
|
||||
worldToCell({ minPoint.x() - padding, floorY, minPoint.z() - padding }, from);
|
||||
worldToCell({ maxPoint.x() + padding, floorY, maxPoint.z() + padding }, to);
|
||||
from.x = (std::max)(from.x, 0);
|
||||
from.z = (std::max)(from.z, 0);
|
||||
to.x = (std::min)(to.x, gridWidth - 1);
|
||||
to.z = (std::min)(to.z, gridDepth - 1);
|
||||
|
||||
for (int z = from.z; z <= to.z; ++z) {
|
||||
for (int x = from.x; x <= to.x; ++x) {
|
||||
const Cell cell{ x, z };
|
||||
if (isInsideGrid(cell)) {
|
||||
walkable[static_cast<size_t>(indexOf(cell))] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool PathFinder::worldToCell(const Eigen::Vector3f& point, Cell& out) const
|
||||
{
|
||||
if (gridWidth <= 0 || gridDepth <= 0) {
|
||||
|
||||
@@ -9,10 +9,6 @@ namespace ZL {
|
||||
|
||||
class PathFinder {
|
||||
public:
|
||||
struct ObstacleMesh {
|
||||
const VertexDataStruct* mesh = nullptr;
|
||||
Eigen::Vector3f offset = Eigen::Vector3f::Zero();
|
||||
};
|
||||
|
||||
struct ObstaclePolygon {
|
||||
std::string name;
|
||||
@@ -35,8 +31,7 @@ public:
|
||||
std::vector<Eigen::Vector2f> polygon;
|
||||
};
|
||||
|
||||
void build(const std::vector<ObstacleMesh>& obstacleMeshes,
|
||||
const std::string& configPath,
|
||||
void build(const std::string& configPath,
|
||||
const std::string& zipPath = "");
|
||||
|
||||
std::vector<Eigen::Vector3f> findPath(const Eigen::Vector3f& start,
|
||||
@@ -72,7 +67,6 @@ private:
|
||||
|
||||
std::string loadedConfigPath;
|
||||
std::string loadedZipPath;
|
||||
std::vector<ObstacleMesh> obstacles;
|
||||
std::vector<ObstaclePolygon> obstaclePolygons;
|
||||
std::vector<unsigned char> walkable;
|
||||
std::vector<NavigationArea> areas;
|
||||
@@ -81,7 +75,6 @@ private:
|
||||
void resetGridBounds();
|
||||
void rebuildWalkableGrid();
|
||||
void markAvailableAreasWalkable();
|
||||
void markObstacleMeshesBlocked();
|
||||
void markObstaclePolygonsBlocked();
|
||||
|
||||
bool worldToCell(const Eigen::Vector3f& point, Cell& out) const;
|
||||
|
||||
Reference in new issue
Block a user