123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226 |
- /**
- * @file llpathfindingnavmesh.cpp
- * @brief Implementation of llpathfindingnavmesh
- *
- * $LicenseInfo:firstyear=2012&license=viewergpl$
- *
- * Copyright (c) 2012, Linden Research, Inc.
- *
- * Second Life Viewer Source Code
- * The source code in this file ("Source Code") is provided by Linden Lab
- * to you under the terms of the GNU General Public License, version 2.0
- * ("GPL"), unless you have obtained a separate licensing agreement
- * ("Other License"), formally executed by you and Linden Lab. Terms of
- * the GPL can be found in doc/GPL-license.txt in this distribution, or
- * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
- *
- * There are special exceptions to the terms and conditions of the GPL as
- * it is applied to this Source Code. View the full text of the exception
- * in the file doc/FLOSS-exception.txt in this software distribution, or
- * online at
- * http://secondlifegrid.net/programs/open_source/licensing/flossexception
- *
- * By copying, modifying or distributing this software, you acknowledge
- * that you have read and understood your obligations described above,
- * and agree to abide by those obligations.
- *
- * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
- * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
- * COMPLETENESS OR PERFORMANCE.
- * $/LicenseInfo$
- */
- #include "llviewerprecompiledheaders.h"
- #include "llpathfindingnavmesh.h"
- #include "llsd.h"
- #include "llsdserialize.h"
- #include "llpathfindingnavmeshstatus.h"
- #define NAVMESH_VERSION_FIELD "navmesh_version"
- #define NAVMESH_DATA_FIELD "navmesh_data"
- LLPathfindingNavMesh::LLPathfindingNavMesh(const LLUUID& region_id)
- : mNavMeshStatus(region_id),
- mNavMeshRequestStatus(kNavMeshRequestUnknown),
- mNavMeshSignal(),
- mNavMeshData()
- {
- }
- LLPathfindingNavMesh::navmesh_slot_t LLPathfindingNavMesh::registerNavMeshListener(navmesh_cb_t callback)
- {
- return mNavMeshSignal.connect(callback);
- }
- bool LLPathfindingNavMesh::hasNavMeshVersion(const LLPathfindingNavMeshStatus& status) const
- {
- return mNavMeshStatus.getVersion() == status.getVersion() &&
- (mNavMeshRequestStatus == kNavMeshRequestStarted ||
- mNavMeshRequestStatus == kNavMeshRequestCompleted ||
- (mNavMeshRequestStatus == kNavMeshRequestChecking &&
- !mNavMeshData.empty()));
- }
- void LLPathfindingNavMesh::handleNavMeshWaitForRegionLoad()
- {
- setRequestStatus(kNavMeshRequestWaiting);
- }
- void LLPathfindingNavMesh::handleNavMeshCheckVersion()
- {
- setRequestStatus(kNavMeshRequestChecking);
- }
- void LLPathfindingNavMesh::handleRefresh(const LLPathfindingNavMeshStatus& status)
- {
- if (mNavMeshStatus.getRegionUUID() != status.getRegionUUID())
- {
- llwarns << "Navmesh status received for another region: ignoring."
- << llendl;
- return;
- }
- if (mNavMeshStatus.getVersion() != status.getVersion())
- {
- llwarns << "Navmesh status received with bad version: ignoring."
- << llendl;
- return;
- }
- mNavMeshStatus = status;
- if (mNavMeshRequestStatus == kNavMeshRequestChecking)
- {
- if (!mNavMeshData.empty())
- {
- setRequestStatus(kNavMeshRequestCompleted);
- }
- else
- {
- llwarns << "Empty navmesh data received !" << llendl;
- }
- }
- else
- {
- sendStatus();
- }
- }
- void LLPathfindingNavMesh::handleNavMeshNewVersion(const LLPathfindingNavMeshStatus& status)
- {
- if (mNavMeshStatus.getRegionUUID() != status.getRegionUUID())
- {
- llwarns << "Navmesh version received for another region: ignoring."
- << llendl;
- return;
- }
- if (mNavMeshStatus.getVersion() == status.getVersion())
- {
- mNavMeshStatus = status;
- sendStatus();
- }
- else
- {
- mNavMeshData.clear();
- mNavMeshStatus = status;
- setRequestStatus(kNavMeshRequestNeedsUpdate);
- }
- }
- void LLPathfindingNavMesh::handleNavMeshStart(const LLPathfindingNavMeshStatus& status)
- {
- if (mNavMeshStatus.getRegionUUID() != status.getRegionUUID())
- {
- llwarns << "Navmesh start signal received for another region: ignoring."
- << llendl;
- return;
- }
- mNavMeshStatus = status;
- setRequestStatus(kNavMeshRequestStarted);
- }
- void LLPathfindingNavMesh::handleNavMeshResult(const LLSD& content, U32 version)
- {
- if (content.has(NAVMESH_VERSION_FIELD) &&
- content.get(NAVMESH_VERSION_FIELD).isInteger() &&
- content.get(NAVMESH_VERSION_FIELD).asInteger() >= 0)
- {
- U32 advertized = (U32)content.get(NAVMESH_VERSION_FIELD).asInteger();
- if (advertized != version)
- {
- llwarns << "Mismatch between expected and embedded navmesh versions occurred"
- << llendl;
- version = advertized;
- }
- }
- else
- {
- llwarns << "Malformed navmesh data: missing version" << llendl;
- }
- if (mNavMeshStatus.getVersion() == version)
- {
- ENavMeshRequestStatus status;
- if (content.has(NAVMESH_DATA_FIELD))
- {
- const LLSD::Binary& value =
- content.get(NAVMESH_DATA_FIELD).asBinary();
- bool valid = false;
- size_t decomp_size = 0;
- U8* buffer = unzip_llsdNavMesh(valid, decomp_size, value.data(),
- value.size());
- if (!valid || !buffer)
- {
- llwarns << "Unable to decompress the navmesh llsd." << llendl;
- status = kNavMeshRequestError;
- }
- else
- {
- mNavMeshData.resize(decomp_size);
- memcpy(&mNavMeshData[0], &buffer[0], decomp_size);
- status = kNavMeshRequestCompleted;
- }
- if (buffer)
- {
- free(buffer);
- }
- }
- else
- {
- llwarns << "No mesh data received" << llendl;
- status = kNavMeshRequestError;
- }
- setRequestStatus(status);
- }
- }
- void LLPathfindingNavMesh::handleNavMeshNotEnabled()
- {
- mNavMeshData.clear();
- setRequestStatus(kNavMeshRequestNotEnabled);
- }
- void LLPathfindingNavMesh::handleNavMeshError()
- {
- mNavMeshData.clear();
- setRequestStatus(kNavMeshRequestError);
- }
- void LLPathfindingNavMesh::handleNavMeshError(U32 version)
- {
- if (mNavMeshStatus.getVersion() == version)
- {
- handleNavMeshError();
- }
- }
- void LLPathfindingNavMesh::setRequestStatus(ENavMeshRequestStatus statusp)
- {
- mNavMeshRequestStatus = statusp;
- sendStatus();
- }
- void LLPathfindingNavMesh::sendStatus()
- {
- mNavMeshSignal(mNavMeshRequestStatus, mNavMeshStatus, mNavMeshData);
- }
|