Commit 7dea319f authored by Thomas's avatar Thomas
Browse files

micro modif

parent 27e8ba8b
......@@ -53,7 +53,7 @@ public :
unsigned int mapMemoryCost();
Dart getBelongingCell(const PFP::VEC3& pos);
void init();
void foreach_neighborFace(Dart d, FunctorType& f);
......@@ -123,23 +123,29 @@ inline void EnvMap::pushAgentInCells(Agent* agent, Dart d)
} while(dd != d);
}
inline void EnvMap::popAgentInCells(Agent* agent, Dart d)
inline void removeAgentFromVector(PFP::AGENTS& a, Agent * ag)
{
assert(map.getCurrentLevel() == map.getMaxLevel());
assert(std::find(agentvect[d].begin(), agentvect[d].end(), agent) != agentvect[d].end());
PFP::AGENTS& a = agentvect[d];
PFP::AGENTS::iterator end = a.end();
bool found = false;
for(PFP::AGENTS::iterator it = a.begin(); it != end && !found; ++it)
{
if(*it == agent)
if(*it == ag)
{
*it = a.back();
a.pop_back();
found = true;
}
}
}
inline void EnvMap::popAgentInCells(Agent* agent, Dart d)
{
assert(map.getCurrentLevel() == map.getMaxLevel());
assert(std::find(agentvect[d].begin(), agentvect[d].end(), agent) != agentvect[d].end());
PFP::AGENTS& a = agentvect[d];
removeAgentFromVector(a,agent);
Dart dd = d;
do
......@@ -147,18 +153,9 @@ inline void EnvMap::popAgentInCells(Agent* agent, Dart d)
Dart ddd = map.alpha1(map.alpha1(dd));
while(ddd != dd)
{
bool found = false;
PFP::AGENTS& na = neighborAgentvect[ddd];
PFP::AGENTS::iterator end = na.end();
for(PFP::AGENTS::iterator it = na.begin(); it != end && !found; ++it)
{
if(*it == agent)
{
*it = na.back();
na.pop_back();
found = true;
}
}
removeAgentFromVector(na,agent);
ddd = map.alpha1(ddd);
}
dd = map.phi1(dd);
......
......@@ -45,7 +45,8 @@ void Agent::updateAgentNeighbors()
{
VEC3 pop = part_.m_position - (*it)->part_.m_position;
float distSq = pop.norm2();
if(agentNeighbors_.size()<maxNeighbors_ || distSq<maxDist) {
if(*it!=this && (agentNeighbors_.size()<maxNeighbors_ || distSq<maxDist) && distSq<neighborDistSq_)
{
if(distSq>maxDist)
maxDist=distSq;
agentNeighbors_.push_back(std::make_pair(distSq, *it));
......@@ -56,14 +57,17 @@ void Agent::updateAgentNeighbors()
{
VEC3 pop = part_.m_position - (*it)->part_.m_position;
float distSq = pop.norm2();
if(agentNeighbors_.size()<maxNeighbors_ || distSq<maxDist) {
if((agentNeighbors_.size()<maxNeighbors_ || distSq<maxDist) && distSq<neighborDistSq_)
{
if(distSq>maxDist)
maxDist=distSq;
agentNeighbors_.push_back(std::make_pair(distSq, *it));
}
}
std::sort(agentNeighbors_.begin(), agentNeighbors_.end(), agentSort);
if(agentNeighbors_.size()>maxNeighbors_) {
std::sort(agentNeighbors_.begin(), agentNeighbors_.end(), agentSort);
}
}
void Agent::updateObstacleNeighbors()
......@@ -79,7 +83,7 @@ void Agent::updateObstacleNeighbors()
obstacleNeighbors_.push_back(std::make_pair(distSq, *it));
}
std::sort(obstacleNeighbors_.begin(), obstacleNeighbors_.end(), obstacleSort);
// std::sort(obstacleNeighbors_.begin(), obstacleNeighbors_.end(), obstacleSort);
}
void Agent::update()
......
......@@ -46,16 +46,17 @@ Dart EnvMap::getBelongingCell(const PFP::VEC3& pos)
void EnvMap::init()
{
float sideSize = 70.0f;
unsigned int nbSquares = 10;
unsigned int nbSquares = 15;
CityGenerator::generateCity<PFP>(map, position, obstacleMark, buildingMark, sideSize, nbSquares);
// CityGenerator::generateMall<PFP>(map, position, obstacleMark, buildingMark, sideSize);
CityGenerator::simplifyFreeSpace<PFP>(map, position, obstacleMark, buildingMark);
// CityGenerator::simplifyFreeSpace<PFP>(map, position, obstacleMark, buildingMark);
map.init();
registerObstaclesInFaces();
for(unsigned int i = subdivisableFace.begin(); i < subdivisableFace.end(); subdivisableFace.next(i))
subdivisableFace[i].first = false ;
// Algo::Geometry::computeNormalFaces<PFP>(map,position,normal);
}
void EnvMap::foreach_neighborFace(Dart d, FunctorType& f)
......
......@@ -39,8 +39,8 @@ public :
// Thread execution stuff goes here
for (unsigned int i = 0; i < ag_.size(); ++i)
{
ag_[i]->updateObstacleNeighbors();
ag_[i]->updateAgentNeighbors();
// ag_[i]->updateObstacleNeighbors();
// ag_[i]->updateAgentNeighbors();
ag_[i]->computePrefVelocity();
ag_[i]->computeNewVelocity();
}
......@@ -75,18 +75,18 @@ void Simulator::doStep()
envMap_.clearUpdateCandidates();
envMap_.map.setCurrentLevel(0);
// for (unsigned int i = 0; i < agents_.size(); ++i)
// {
// agents_[i]->updateObstacleNeighbors();
// agents_[i]->updateAgentNeighbors();
// agents_[i]->computePrefVelocity();
// agents_[i]->computeNewVelocity();
// }
for (unsigned int i = 0; i < agents_.size(); ++i)
{
agents_[i]->updateObstacleNeighbors();
agents_[i]->updateAgentNeighbors();
agents_[i]->computePrefVelocity();
agents_[i]->computeNewVelocity();
}
ThreadUpdateInfo tc1(agents_,0,agents_.size()/2);
ThreadUpdateInfo tc2(agents_,agents_.size()/2,agents_.size());
boost::thread thread1(&ThreadUpdateInfo::run, &tc1);
boost::thread thread2(&ThreadUpdateInfo::run, &tc2);
// ThreadUpdateInfo tc1(agents_,0,agents_.size()/2);
// ThreadUpdateInfo tc2(agents_,agents_.size()/2,agents_.size());
// boost::thread thread1(&ThreadUpdateInfo::run, &tc1);
// boost::thread thread2(&ThreadUpdateInfo::run, &tc2);
// std::vector<Dart> oldDarts;
// oldDarts.reserve(agents_.size());
......@@ -95,8 +95,8 @@ void Simulator::doStep()
// oldDarts.push_back(agents_[i]->part_.d);
// }
thread1.join();
thread2.join();
// thread1.join();
// thread2.join();
envMap_.map.setCurrentLevel(envMap_.map.getMaxLevel());
......@@ -107,6 +107,7 @@ void Simulator::doStep()
// thread3.join();
// thread4.join();
for (unsigned int i = 0; i < agents_.size(); ++i)
{
Dart oldFace = agents_[i]->part_.d;
......@@ -145,10 +146,10 @@ void Simulator::setupScenario(unsigned int nbMaxAgent)
* opposite side of the environment.
*/
Dart d = envMap_.map.begin();
DartMarkerStore filled(envMap_.map);
CellMarker filled(envMap_.map,FACE_ORBIT);
unsigned int nbx = 10;
unsigned int nby = 10;
unsigned int nbx = 5;
unsigned int nby = 5;
unsigned int bMax = nbMaxAgent / (nbx*nby);
......@@ -161,7 +162,7 @@ void Simulator::setupScenario(unsigned int nbMaxAgent)
{
if(!filled.isMarked(d) && !envMap_.buildingMark.isMarked(d))
{
filled.markOrbit(FACE_ORBIT, d);
filled.mark(d);
pos = Algo::Geometry::faceCentroid<PFP>(envMap_.map, d, envMap_.position);
pos[2] = 0;
dCell = d;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment