From 1757f3967874a2885b45e3324bf19f677e76f6bc Mon Sep 17 00:00:00 2001 From: Todd Stinson Date: Tue, 21 Feb 2012 18:40:40 -0800 Subject: PATH-296: Refining the behavior of the freeze/unfreeze functionality to support both basic and edit/test pathfinding floaters open at the same time. --- indra/newview/llpathfindingmanager.cpp | 104 +++++++++++++++++++++++++-------- 1 file changed, 80 insertions(+), 24 deletions(-) (limited to 'indra/newview/llpathfindingmanager.cpp') diff --git a/indra/newview/llpathfindingmanager.cpp b/indra/newview/llpathfindingmanager.cpp index e46ec0e171..3905e6d9f3 100644 --- a/indra/newview/llpathfindingmanager.cpp +++ b/indra/newview/llpathfindingmanager.cpp @@ -27,8 +27,6 @@ #include -#include - #include "llviewerprecompiledheaders.h" #include "llpathfindingmanager.h" #include "llsingleton.h" @@ -36,6 +34,9 @@ #include "llagent.h" #include "llviewerregion.h" +#include +#include + #define CAP_SERVICE_RETRIEVE_NAVMESH "RetrieveNavMeshSrc" #define CAP_SERVICE_AGENT_STATE "AgentPreferences" @@ -48,7 +49,7 @@ class AgentStateResponder : public LLHTTPClient::Responder { public: - AgentStateResponder(LLPathfindingManager::agent_state_callback_t pAgentStateCB, const std::string &pCapabilityURL); + AgentStateResponder(const std::string &pCapabilityURL, LLPathfindingManager::EAgentState pRequestedAgentState = LLPathfindingManager::kAgentStateUnknown); virtual ~AgentStateResponder(); virtual void result(const LLSD &pContent); @@ -57,8 +58,8 @@ public: protected: private: - LLPathfindingManager::agent_state_callback_t mAgentStateCB; - std::string mCapabilityURL; + std::string mCapabilityURL; + LLPathfindingManager::EAgentState mRequestedAgentState; }; //--------------------------------------------------------------------------- @@ -66,6 +67,10 @@ private: //--------------------------------------------------------------------------- LLPathfindingManager::LLPathfindingManager() + : LLSingleton(), + mAgentStateSignal(), + mAgentState(kAgentStateUnknown), + mLastKnownNonErrorAgentState(kAgentStateUnknown) { } @@ -79,52 +84,103 @@ bool LLPathfindingManager::isPathfindingEnabledForCurrentRegion() const return !retrieveNavMeshURL.empty(); } -void LLPathfindingManager::requestGetAgentState(agent_state_callback_t pAgentStateCB) const +LLPathfindingManager::agent_state_slot_t LLPathfindingManager::registerAgentStateSignal(agent_state_callback_t pAgentStateCallback) { - std::string agentStateURL = getAgentStateURLForCurrentRegion(); + return mAgentStateSignal.connect(pAgentStateCallback); +} - if (agentStateURL.empty()) +LLPathfindingManager::EAgentState LLPathfindingManager::getAgentState() +{ + if (!isPathfindingEnabledForCurrentRegion()) { - pAgentStateCB(kAgentStateError); + setAgentState(kAgentStateNotEnabled); } else { - LLHTTPClient::ResponderPtr responder = new AgentStateResponder(pAgentStateCB, agentStateURL); - LLHTTPClient::get(agentStateURL, responder); + if (!isValidAgentState(mAgentState)) + { + requestGetAgentState(); + } } + + return mAgentState; } -void LLPathfindingManager::requestSetAgentState(EAgentState pAgentState, agent_state_callback_t pAgentStateCB) const +LLPathfindingManager::EAgentState LLPathfindingManager::getLastKnownNonErrorAgentState() const { + return mLastKnownNonErrorAgentState; +} + +void LLPathfindingManager::requestSetAgentState(EAgentState pRequestedAgentState) +{ + llassert(isValidAgentState(pRequestedAgentState)); std::string agentStateURL = getAgentStateURLForCurrentRegion(); if (agentStateURL.empty()) { - pAgentStateCB(kAgentStateError); + setAgentState(kAgentStateNotEnabled); } else { LLSD request; - request[ALTER_PERMANENT_OBJECTS_FIELD] = static_cast(pAgentState == kAgentStateUnfrozen); + request[ALTER_PERMANENT_OBJECTS_FIELD] = static_cast(pRequestedAgentState == kAgentStateUnfrozen); - LLHTTPClient::ResponderPtr responder = new AgentStateResponder(pAgentStateCB, agentStateURL); + LLHTTPClient::ResponderPtr responder = new AgentStateResponder(agentStateURL, pRequestedAgentState); LLHTTPClient::post(agentStateURL, request, responder); } } -void LLPathfindingManager::handleAgentStateResult(const LLSD &pContent, agent_state_callback_t pAgentStateCB) const +bool LLPathfindingManager::isValidAgentState(EAgentState pAgentState) +{ + return ((pAgentState == kAgentStateFrozen) || (pAgentState == kAgentStateUnfrozen)); +} + +void LLPathfindingManager::requestGetAgentState() +{ + std::string agentStateURL = getAgentStateURLForCurrentRegion(); + + if (agentStateURL.empty()) + { + setAgentState(kAgentStateNotEnabled); + } + else + { + LLHTTPClient::ResponderPtr responder = new AgentStateResponder(agentStateURL); + LLHTTPClient::get(agentStateURL, responder); + } +} + +void LLPathfindingManager::setAgentState(EAgentState pAgentState) +{ + mAgentState = pAgentState; + + if (mAgentState != kAgentStateError) + { + mLastKnownNonErrorAgentState = mAgentState; + } + + mAgentStateSignal(mAgentState); +} + +void LLPathfindingManager::handleAgentStateResult(const LLSD &pContent, EAgentState pRequestedAgentState) { llassert(pContent.has(ALTER_PERMANENT_OBJECTS_FIELD)); llassert(pContent.get(ALTER_PERMANENT_OBJECTS_FIELD).isBoolean()); EAgentState agentState = (pContent.get(ALTER_PERMANENT_OBJECTS_FIELD).asBoolean() ? kAgentStateUnfrozen : kAgentStateFrozen); - pAgentStateCB(agentState); + if (isValidAgentState(pRequestedAgentState) && (agentState != pRequestedAgentState)) + { + agentState = kAgentStateError; + llassert(0); + } + + setAgentState(agentState); } -void LLPathfindingManager::handleAgentStateError(U32 pStatus, const std::string &pReason, const std::string &pURL, agent_state_callback_t pAgentStateCB) const +void LLPathfindingManager::handleAgentStateError(U32 pStatus, const std::string &pReason, const std::string &pURL) { llwarns << "error with request to URL '" << pURL << "' because " << pReason << " (statusCode:" << pStatus << ")" << llendl; - pAgentStateCB(kAgentStateError); + setAgentState(kAgentStateError); } std::string LLPathfindingManager::getRetrieveNavMeshURLForCurrentRegion() const @@ -160,9 +216,9 @@ std::string LLPathfindingManager::getCapabilityURLForCurrentRegion(const std::st // AgentStateResponder //--------------------------------------------------------------------------- -AgentStateResponder::AgentStateResponder(LLPathfindingManager::agent_state_callback_t pAgentStateCB, const std::string &pCapabilityURL) - : mAgentStateCB(pAgentStateCB), - mCapabilityURL(pCapabilityURL) +AgentStateResponder::AgentStateResponder(const std::string &pCapabilityURL, LLPathfindingManager::EAgentState pRequestedAgentState) + : mCapabilityURL(pCapabilityURL), + mRequestedAgentState(pRequestedAgentState) { } @@ -172,10 +228,10 @@ AgentStateResponder::~AgentStateResponder() void AgentStateResponder::result(const LLSD &pContent) { - LLPathfindingManager::getInstance()->handleAgentStateResult(pContent, mAgentStateCB); + LLPathfindingManager::getInstance()->handleAgentStateResult(pContent, mRequestedAgentState); } void AgentStateResponder::error(U32 pStatus, const std::string &pReason) { - LLPathfindingManager::getInstance()->handleAgentStateError(pStatus, pReason, mCapabilityURL, mAgentStateCB); + LLPathfindingManager::getInstance()->handleAgentStateError(pStatus, pReason, mCapabilityURL); } -- cgit v1.2.3