From 5f7a108154c51b2d5752bdda33d5f70ed72ca4e1 Mon Sep 17 00:00:00 2001 From: David Markowitz Date: Wed, 9 Aug 2023 00:34:39 -0700 Subject: [PATCH] woirking --- .../ControllablePhysicsComponent.cpp | 6 +++++- dGame/dComponents/MovementAIComponent.cpp | 20 +++++++++++++++++-- dGame/dComponents/MovementAIComponent.h | 8 +++++++- dMasterServer/MasterServer.cpp | 3 +-- dNavigation/dNavMesh.cpp | 18 +++++++++-------- 5 files changed, 41 insertions(+), 14 deletions(-) diff --git a/dGame/dComponents/ControllablePhysicsComponent.cpp b/dGame/dComponents/ControllablePhysicsComponent.cpp index a658ccd7..3c081aa2 100644 --- a/dGame/dComponents/ControllablePhysicsComponent.cpp +++ b/dGame/dComponents/ControllablePhysicsComponent.cpp @@ -71,7 +71,10 @@ ControllablePhysicsComponent::~ControllablePhysicsComponent() { } void ControllablePhysicsComponent::Update(float deltaTime) { - + if (m_Velocity == NiPoint3::ZERO) return; + m_Position += m_Velocity * deltaTime; + m_DirtyPosition = true; + Game::entityManager->SerializeEntity(m_Parent); } void ControllablePhysicsComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) { @@ -153,6 +156,7 @@ void ControllablePhysicsComponent::Serialize(RakNet::BitStream* outBitStream, bo } outBitStream->Write0(); + if (!bIsInitialUpdate) m_DirtyPosition = false; } if (!bIsInitialUpdate) { diff --git a/dGame/dComponents/MovementAIComponent.cpp b/dGame/dComponents/MovementAIComponent.cpp index d1773f73..5e14050c 100644 --- a/dGame/dComponents/MovementAIComponent.cpp +++ b/dGame/dComponents/MovementAIComponent.cpp @@ -63,7 +63,14 @@ void MovementAIComponent::SetupPath(const std::string& pathname) { } const Path* pathData = Game::zoneManager->GetZone()->GetPath(path); if (pathData) { - Game::logger->Log("MovementAIComponent", "found path %s", path.c_str()); + Game::logger->Log("MovementAIComponent", "found path %i %s", m_Parent->GetLOT(), path.c_str()); + m_Path = pathData; + std::vector waypoints; + for (auto& waypoint : m_Path->pathWaypoints) { + waypoints.push_back(waypoint.position); + } + SetPath(waypoints); + SetMaxSpeed(3.0f); } else { Game::logger->Log("MovementAIComponent", "No path found for %i:%llu", m_Parent->GetLOT(), m_Parent->GetObjectID()); } @@ -144,7 +151,16 @@ void MovementAIComponent::Update(const float deltaTime) { // Check if there are more waypoints in the queue, if so set our next destination to the next waypoint HandleWaypointArrived(); if (!AdvancePathWaypointIndex()) { - Stop(); + if (m_Path && m_Path->pathBehavior == PathBehavior::Bounce) { + ReversePath(); // untested. + } else if (m_Path && m_Path->pathBehavior == PathBehavior::Loop) { + m_CurrentPathWaypointIndex = 0; + m_NextPathWaypointIndex = 0; + AdvancePathWaypointIndex(); + SetDestination(GetCurrentPathWaypoint()); + } else { + Stop(); + } return; } SetDestination(GetCurrentPathWaypoint()); diff --git a/dGame/dComponents/MovementAIComponent.h b/dGame/dComponents/MovementAIComponent.h index b53cd02b..0120340b 100644 --- a/dGame/dComponents/MovementAIComponent.h +++ b/dGame/dComponents/MovementAIComponent.h @@ -18,6 +18,7 @@ class ControllablePhysicsComponent; class BaseCombatAIComponent; +class Path; /** * Information that describes the different variables used to make an entity move around @@ -265,7 +266,7 @@ private: /** * The path this entity is currently traversing */ - uint32_t m_PathIndex; + int32_t m_PathIndex; /** * If the entity has reached it last waypoint @@ -346,6 +347,11 @@ private: * Whether or not the current movement via pathing is paused. */ bool m_IsPaused; + + /** + * The optional path this component will follow. + */ + const Path* m_Path = nullptr; }; #endif // MOVEMENTAICOMPONENT_H diff --git a/dMasterServer/MasterServer.cpp b/dMasterServer/MasterServer.cpp index ad46aa4a..84bd154c 100644 --- a/dMasterServer/MasterServer.cpp +++ b/dMasterServer/MasterServer.cpp @@ -347,8 +347,7 @@ int main(int argc, char** argv) { StartChatServer(); Game::im->GetInstance(0, false, 0); - Game::im->GetInstance(1000, false, 0); - Game::im->GetInstance(1300, false, 0); + Game::im->GetInstance(1800, false, 0); StartAuthServer(); } diff --git a/dNavigation/dNavMesh.cpp b/dNavigation/dNavMesh.cpp index eda370a1..d8c384c8 100644 --- a/dNavigation/dNavMesh.cpp +++ b/dNavigation/dNavMesh.cpp @@ -30,7 +30,7 @@ dNavMesh::dNavMesh(uint32_t zoneId) { dNavMesh::~dNavMesh() { // Clean up Recast information - if(m_Solid) rcFreeHeightField(m_Solid); + if (m_Solid) rcFreeHeightField(m_Solid); if (m_CHF) rcFreeCompactHeightfield(m_CHF); if (m_CSet) rcFreeContourSet(m_CSet); if (m_PMesh) rcFreePolyMesh(m_PMesh); @@ -135,17 +135,19 @@ float dNavMesh::GetHeightAtPoint(const NiPoint3& location, const float halfExten float nearestPoint[3] = { 0.0f, 0.0f, 0.0f }; dtQueryFilter filter{}; - auto res = m_NavQuery->findNearestPoly(pos, polyPickExt, &filter, &nearestRef, nearestPoint); - res = m_NavQuery->getPolyHeight(nearestRef, pos, &toReturn); + auto hasPoly = m_NavQuery->findNearestPoly(pos, polyPickExt, &filter, &nearestRef, nearestPoint); + m_NavQuery->getPolyHeight(nearestRef, pos, &toReturn); if (toReturn != 0.0f) { DluAssert(toReturn == nearestPoint[1]); } if (toReturn == 0.0f) { - toReturn = location.y; - // If we were unable to get the poly height, but the query returned a success, just use the height of the nearest point. - // This is what seems to happen anyways and it is better than returning zero. - } else if (res == DT_SUCCESS) { - toReturn = nearestPoint[1]; + // If we were unable to get the poly height, but the query returned a success, just use the height of the nearest point. + // This is what seems to happen anyways and it is better than returning zero. + if (hasPoly == DT_SUCCESS) { + toReturn = nearestPoint[1]; + } else { + toReturn = location.y; + } } // If we failed to even find a poly, do not change the height since we have no idea what it should be.