2015-09-20 20:03:13 +02:00
|
|
|
/*
|
|
|
|
|
Copyright (C) 2015 erik
|
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program 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 General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
#include "config.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2016-03-12 14:03:48 +01:00
|
|
|
#include "AwarenessStoreProvider.h"
|
2015-09-20 20:03:13 +02:00
|
|
|
#include "common/TypeNode.h"
|
2016-03-12 14:03:48 +01:00
|
|
|
#include "common/log.h"
|
|
|
|
|
#include "common/debug.h"
|
2015-09-20 20:03:13 +02:00
|
|
|
|
|
|
|
|
#include "rulesets/BBoxProperty.h"
|
|
|
|
|
|
|
|
|
|
#include <wfmath/point.h>
|
|
|
|
|
#include <wfmath/ball.h>
|
|
|
|
|
|
2016-03-12 14:03:48 +01:00
|
|
|
static const bool debug_flag = true;
|
|
|
|
|
|
|
|
|
|
|
2015-09-23 22:03:31 +02:00
|
|
|
AwarenessStoreProvider::AwarenessStoreProvider(IHeightProvider& heightProvider)
|
|
|
|
|
: m_heightProvider(heightProvider)
|
2015-09-20 20:03:13 +02:00
|
|
|
{
|
|
|
|
|
// TODO Auto-generated constructor stub
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AwarenessStoreProvider::~AwarenessStoreProvider()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2015-09-23 22:03:31 +02:00
|
|
|
AwarenessStore& AwarenessStoreProvider::getStore(const TypeNode* type, int tileSize)
|
2015-09-20 20:03:13 +02:00
|
|
|
{
|
2016-03-12 14:03:48 +01:00
|
|
|
auto I = m_awarenessStores.find(type->name());
|
2015-09-20 20:03:13 +02:00
|
|
|
if (I != m_awarenessStores.end()) {
|
2016-03-12 23:38:13 +01:00
|
|
|
debug_print("Reusing awareness store for type " << type->name() << ".");
|
2015-09-20 20:03:13 +02:00
|
|
|
return I->second;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float agentHeight = 2;
|
|
|
|
|
float agentRadius = 0.4;
|
|
|
|
|
auto propertyI = type->defaults().find("bbox");
|
|
|
|
|
if (propertyI != type->defaults().end()) {
|
|
|
|
|
const PropertyBase* propBase = propertyI->second;
|
|
|
|
|
const BBoxProperty* bboxProp = static_cast<const BBoxProperty*>(propBase);
|
|
|
|
|
const auto& bbox = bboxProp->data();
|
|
|
|
|
agentHeight = bbox.highCorner().z() - bbox.lowCorner().z();
|
|
|
|
|
|
|
|
|
|
WFMath::AxisBox<2> agent2dBbox(WFMath::Point<2>(bbox.lowCorner().x(), bbox.lowCorner().y()), WFMath::Point<2>(bbox.highCorner().x(), bbox.highCorner().y()));
|
|
|
|
|
agentRadius = std::max(0.2f, agent2dBbox.boundingSphere().radius()); //Don't make the radius smaller than 0.2 meters, to avoid too many cells
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-12 14:03:48 +01:00
|
|
|
return m_awarenessStores.emplace(type->name(), AwarenessStore(agentRadius, agentHeight, m_heightProvider, tileSize)).first->second;
|
2015-09-20 20:03:13 +02:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|