Skip to content
Snippets Groups Projects
Commit 516ad5b3 authored by Todd Stinson's avatar Todd Stinson
Browse files

PATH-292: Implementing the new freeze/unfreeze functionality on the basic panel.

parent 35b09a72
No related branches found
No related tags found
No related merge requests found
......@@ -420,6 +420,7 @@ set(viewer_SOURCE_FILES
llpatchvertexarray.cpp
llpathfindingcharacter.cpp
llpathfindinglinkset.cpp
llpathfindingmanager.cpp
llphysicsmotion.cpp
llphysicsshapebuilderutil.cpp
llplacesinventorybridge.cpp
......@@ -973,6 +974,7 @@ set(viewer_HEADER_FILES
llpatchvertexarray.h
llpathfindingcharacter.h
llpathfindinglinkset.h
llpathfindingmanager.h
llphysicsmotion.h
llphysicsshapebuilderutil.h
llplacesinventorybridge.h
......
......@@ -25,14 +25,14 @@
* $/LicenseInfo$
*/
#include <boost/bind.hpp>
#include "llviewerprecompiledheaders.h"
#include "llfloaterpathfindingbasic.h"
#include "llsd.h"
#include "llagent.h"
#include "lltextbase.h"
#include "llbutton.h"
#include "llviewerregion.h"
#include "llpathfindingmanager.h"
//---------------------------------------------------------------------------
// LLFloaterPathfindingBasic
......@@ -40,8 +40,8 @@
BOOL LLFloaterPathfindingBasic::postBuild()
{
mRegionNotEnabledText = findChild<LLTextBase>("disabled_warning_label");
llassert(mRegionNotEnabledText != NULL);
mStatusText = findChild<LLTextBase>("status_label");
llassert(mStatusText != NULL);
mUnfreezeLabel = findChild<LLTextBase>("unfreeze_label");
llassert(mUnfreezeLabel != NULL);
......@@ -57,23 +57,32 @@ BOOL LLFloaterPathfindingBasic::postBuild()
llassert(mFreezeButton != NULL);
mFreezeButton->setCommitCallback(boost::bind(&LLFloaterPathfindingBasic::onFreezeClicked, this));
updateOnFrozenState();
return LLFloater::postBuild();
}
void LLFloaterPathfindingBasic::onOpen(const LLSD& key)
{
LLPathfindingManager *pathfindingManager = LLPathfindingManager::getInstance();
if (pathfindingManager->isPathfindingEnabledForCurrentRegion())
{
LLPathfindingManager::getInstance()->requestGetAgentState(boost::bind(&LLFloaterPathfindingBasic::onAgentStateCB, this, _1));
}
else
{
setAgentState(LLPathfindingManager::kAgentStateNotEnabled);
}
LLFloater::onOpen(key);
}
LLFloaterPathfindingBasic::LLFloaterPathfindingBasic(const LLSD& pSeed)
: LLFloater(pSeed),
mRegionNotEnabledText(NULL),
mStatusText(NULL),
mUnfreezeLabel(NULL),
mUnfreezeButton(NULL),
mFreezeLabel(NULL),
mFreezeButton(NULL),
mIsRegionFrozenXXX(true)
mAgentState(LLPathfindingManager::kAgentStateNotEnabled)
{
}
......@@ -81,61 +90,68 @@ LLFloaterPathfindingBasic::~LLFloaterPathfindingBasic()
{
}
std::string LLFloaterPathfindingBasic::getCapabilityURL() const
void LLFloaterPathfindingBasic::onUnfreezeClicked()
{
std::string capURL("");
mUnfreezeButton->setEnabled(FALSE);
LLPathfindingManager::getInstance()->requestSetAgentState(LLPathfindingManager::kAgentStateUnfrozen, boost::bind(&LLFloaterPathfindingBasic::onAgentStateCB, this, _1));
}
LLViewerRegion *region = gAgent.getRegion();
if (region != NULL)
{
capURL = region->getCapability("RetrieveNavMeshSrc");
}
void LLFloaterPathfindingBasic::onFreezeClicked()
{
mUnfreezeButton->setEnabled(FALSE);
LLPathfindingManager::getInstance()->requestSetAgentState(LLPathfindingManager::kAgentStateFrozen, boost::bind(&LLFloaterPathfindingBasic::onAgentStateCB, this, _1));
}
return capURL;
void LLFloaterPathfindingBasic::onAgentStateCB(LLPathfindingManager::EAgentState pAgentState)
{
setAgentState(pAgentState);
}
void LLFloaterPathfindingBasic::updateOnFrozenState()
void LLFloaterPathfindingBasic::setAgentState(LLPathfindingManager::EAgentState pAgentState)
{
std::string capURL = getCapabilityURL();
switch (pAgentState)
{
case LLPathfindingManager::kAgentStateNotEnabled :
mStatusText->setVisible(TRUE);
mStatusText->setText((LLStringExplicit)getString("pathfinding_not_enabled"));
mAgentState = pAgentState;
break;
case LLPathfindingManager::kAgentStateError :
mStatusText->setVisible(TRUE);
mStatusText->setText((LLStringExplicit)getString("unable_to_change_state"));
// Do not actually change the current state in the error case allowing user to retry previous command
break;
default :
mStatusText->setVisible(FALSE);
mAgentState = pAgentState;
break;
}
if (capURL.empty())
switch (mAgentState)
{
mRegionNotEnabledText->setVisible(TRUE);
case LLPathfindingManager::kAgentStateNotEnabled :
mUnfreezeLabel->setEnabled(FALSE);
mUnfreezeButton->setEnabled(FALSE);
mFreezeLabel->setEnabled(FALSE);
mFreezeButton->setEnabled(FALSE);
break;
case LLPathfindingManager::kAgentStateFrozen :
mUnfreezeLabel->setEnabled(TRUE);
mUnfreezeButton->setEnabled(TRUE);
mFreezeLabel->setEnabled(FALSE);
mFreezeButton->setEnabled(FALSE);
break;
case LLPathfindingManager::kAgentStateUnfrozen :
mUnfreezeLabel->setEnabled(FALSE);
mUnfreezeButton->setEnabled(FALSE);
mFreezeLabel->setEnabled(TRUE);
mFreezeButton->setEnabled(TRUE);
break;
case LLPathfindingManager::kAgentStateError :
llassert(0);
break;
default :
llassert(0);
break;
}
else
{
mRegionNotEnabledText->setVisible(FALSE);
if (mIsRegionFrozenXXX)
{
mUnfreezeLabel->setEnabled(TRUE);
mUnfreezeButton->setEnabled(TRUE);
mFreezeLabel->setEnabled(FALSE);
mFreezeButton->setEnabled(FALSE);
}
else
{
mUnfreezeLabel->setEnabled(FALSE);
mUnfreezeButton->setEnabled(FALSE);
mFreezeLabel->setEnabled(TRUE);
mFreezeButton->setEnabled(TRUE);
}
}
}
void LLFloaterPathfindingBasic::onUnfreezeClicked()
{
mIsRegionFrozenXXX = false;
updateOnFrozenState();
llwarns << "functionality has not yet been implemented to set unfrozen state" << llendl;
}
void LLFloaterPathfindingBasic::onFreezeClicked()
{
mIsRegionFrozenXXX = true;
updateOnFrozenState();
llwarns << "functionality has not yet been implemented to set frozen state" << llendl;
}
......@@ -29,7 +29,7 @@
#define LL_LLFLOATERPATHFINDINGBASIC_H
#include "llfloater.h"
#include "llhandle.h"
#include "llpathfindingmanager.h"
class LLSD;
class LLTextBase;
......@@ -55,16 +55,16 @@ class LLFloaterPathfindingBasic
void onUnfreezeClicked();
void onFreezeClicked();
std::string getCapabilityURL() const;
void onAgentStateCB(LLPathfindingManager::EAgentState pAgentState);
void updateOnFrozenState();
void setAgentState(LLPathfindingManager::EAgentState pAgentState);
LLTextBase *mRegionNotEnabledText;
LLTextBase *mUnfreezeLabel;
LLButton *mUnfreezeButton;
LLTextBase *mFreezeLabel;
LLButton *mFreezeButton;
bool mIsRegionFrozenXXX; // XXX stinson : Feb 15, 2012 : I think this will be unneeded with the service
LLTextBase *mStatusText;
LLTextBase *mUnfreezeLabel;
LLButton *mUnfreezeButton;
LLTextBase *mFreezeLabel;
LLButton *mFreezeButton;
LLPathfindingManager::EAgentState mAgentState;
};
#endif // LL_LLFLOATERPATHFINDINGBASIC_H
/**
* @file llpathfindinglinksets.cpp
* @file llpathfindingcharacter.cpp
* @author William Todd Stinson
* @brief Definition of a pathfinding character that contains various properties required for havok pathfinding.
*
......
/**
* @file llpathfindingmanager.cpp
* @author William Todd Stinson
* @brief A state manager for the various pathfinding states.
*
* $LicenseInfo:firstyear=2002&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#include <string>
#include <boost/function.hpp>
#include "llviewerprecompiledheaders.h"
#include "llpathfindingmanager.h"
#include "llsingleton.h"
#include "llhttpclient.h"
#include "llagent.h"
#include "llviewerregion.h"
#define CAP_SERVICE_RETRIEVE_NAVMESH "RetrieveNavMeshSrc"
#define CAP_SERVICE_AGENT_STATE "AgentPreferences"
#define ALTER_PERMANENT_OBJECTS_FIELD "alter_permanent_objects"
//---------------------------------------------------------------------------
// AgentStateResponder
//---------------------------------------------------------------------------
class AgentStateResponder : public LLHTTPClient::Responder
{
public:
AgentStateResponder(LLPathfindingManager::agent_state_callback_t pAgentStateCB, const std::string &pCapabilityURL);
virtual ~AgentStateResponder();
virtual void result(const LLSD &pContent);
virtual void error(U32 pStatus, const std::string& pReason);
protected:
private:
LLPathfindingManager::agent_state_callback_t mAgentStateCB;
std::string mCapabilityURL;
};
//---------------------------------------------------------------------------
// LLPathfindingManager
//---------------------------------------------------------------------------
LLPathfindingManager::LLPathfindingManager()
{
}
LLPathfindingManager::~LLPathfindingManager()
{
}
bool LLPathfindingManager::isPathfindingEnabledForCurrentRegion() const
{
std::string retrieveNavMeshURL = getRetrieveNavMeshURLForCurrentRegion();
return !retrieveNavMeshURL.empty();
}
void LLPathfindingManager::requestGetAgentState(agent_state_callback_t pAgentStateCB) const
{
std::string agentStateURL = getAgentStateURLForCurrentRegion();
if (agentStateURL.empty())
{
pAgentStateCB(kAgentStateError);
}
else
{
LLHTTPClient::ResponderPtr responder = new AgentStateResponder(pAgentStateCB, agentStateURL);
LLHTTPClient::get(agentStateURL, responder);
}
}
void LLPathfindingManager::requestSetAgentState(EAgentState pAgentState, agent_state_callback_t pAgentStateCB) const
{
std::string agentStateURL = getAgentStateURLForCurrentRegion();
if (agentStateURL.empty())
{
pAgentStateCB(kAgentStateError);
}
else
{
LLSD request;
request[ALTER_PERMANENT_OBJECTS_FIELD] = static_cast<LLSD::Boolean>(pAgentState == kAgentStateUnfrozen);
LLHTTPClient::ResponderPtr responder = new AgentStateResponder(pAgentStateCB, agentStateURL);
LLHTTPClient::post(agentStateURL, request, responder);
}
}
void LLPathfindingManager::handleAgentStateResult(const LLSD &pContent, agent_state_callback_t pAgentStateCB) const
{
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);
}
void LLPathfindingManager::handleAgentStateError(U32 pStatus, const std::string &pReason, const std::string &pURL, agent_state_callback_t pAgentStateCB) const
{
llwarns << "error with request to URL '" << pURL << "' because " << pReason << " (statusCode:" << pStatus << ")" << llendl;
pAgentStateCB(kAgentStateError);
}
std::string LLPathfindingManager::getRetrieveNavMeshURLForCurrentRegion() const
{
return getCapabilityURLForCurrentRegion(CAP_SERVICE_RETRIEVE_NAVMESH);
}
std::string LLPathfindingManager::getAgentStateURLForCurrentRegion() const
{
return getCapabilityURLForCurrentRegion(CAP_SERVICE_AGENT_STATE);
}
std::string LLPathfindingManager::getCapabilityURLForCurrentRegion(const std::string &pCapabilityName) const
{
std::string capabilityURL("");
LLViewerRegion* region = gAgent.getRegion();
if (region != NULL)
{
capabilityURL = region->getCapability(pCapabilityName);
}
if (capabilityURL.empty())
{
llwarns << "cannot find capability '" << pCapabilityName << "' for current region '"
<< ((region != NULL) ? region->getName() : "<null>") << "'" << llendl;
}
return capabilityURL;
}
//---------------------------------------------------------------------------
// AgentStateResponder
//---------------------------------------------------------------------------
AgentStateResponder::AgentStateResponder(LLPathfindingManager::agent_state_callback_t pAgentStateCB, const std::string &pCapabilityURL)
: mAgentStateCB(pAgentStateCB),
mCapabilityURL(pCapabilityURL)
{
}
AgentStateResponder::~AgentStateResponder()
{
}
void AgentStateResponder::result(const LLSD &pContent)
{
LLPathfindingManager::getInstance()->handleAgentStateResult(pContent, mAgentStateCB);
}
void AgentStateResponder::error(U32 pStatus, const std::string &pReason)
{
LLPathfindingManager::getInstance()->handleAgentStateError(pStatus, pReason, mCapabilityURL, mAgentStateCB);
}
/**
* @file llpathfindingmanager.h
* @author William Todd Stinson
* @brief A state manager for the various pathfinding states.
*
* $LicenseInfo:firstyear=2002&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#ifndef LL_LLPATHFINDINGMANAGER_H
#define LL_LLPATHFINDINGMANAGER_H
#include <string>
#include <boost/function.hpp>
#include "llsingleton.h"
class LLFloater;
class LLPathfindingManager : public LLSingleton<LLPathfindingManager>
{
public:
typedef enum {
kAgentStateNotEnabled = 0,
kAgentStateFrozen = 1,
kAgentStateUnfrozen = 2,
kAgentStateError = 3
} EAgentState;
typedef boost::function<void (EAgentState pAgentState)> agent_state_callback_t;
LLPathfindingManager();
virtual ~LLPathfindingManager();
bool isPathfindingEnabledForCurrentRegion() const;
void requestGetAgentState(agent_state_callback_t pAgentStateCB) const;
void requestSetAgentState(EAgentState, agent_state_callback_t pAgentStateCB) const;
void handleAgentStateResult(const LLSD &pContent, agent_state_callback_t pAgentStateCB) const;
void handleAgentStateError(U32 pStatus, const std::string &pReason, const std::string &pURL, agent_state_callback_t pAgentStateCB) const;
protected:
private:
std::string getRetrieveNavMeshURLForCurrentRegion() const;
std::string getAgentStateURLForCurrentRegion() const;
std::string getCapabilityURLForCurrentRegion(const std::string &pCapabilityName) const;
};
#endif // LL_LLPATHFINDINGMANAGER_H
......@@ -1489,6 +1489,7 @@ void LLViewerRegion::unpackRegionHandshake()
void LLViewerRegionImpl::buildCapabilityNames(LLSD& capabilityNames)
{
capabilityNames.append("AgentPreferences");
capabilityNames.append("AttachmentResources");
capabilityNames.append("AvatarPickerSearch");
capabilityNames.append("CharacterProperties");
......
......@@ -11,6 +11,8 @@
single_instance="true"
title="Basic pathfinding setup"
width="312">
<floater.string name="pathfinding_not_enabled">This region is not enabled for pathfinding.</floater.string>
<floater.string name="unable_to_change_state">Unable to change modes successfully.</floater.string>
<text
height="13"
word_wrap="false"
......@@ -21,10 +23,9 @@
follows="left|top"
layout="topleft"
left="15"
name="disabled_warning_label"
name="status_label"
top="8"
width="289">
This region is not enabled for pathfinding.
</text>
<text
height="13"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment