Commit 5bb0cd68 authored by VAN TOLL Wouter's avatar VAN TOLL Wouter

Made the CSV writer optional again.

This is crucial for the DLL!
parent 6e3a5f53
......@@ -30,13 +30,13 @@
#include <core/worldBase.h>
#include <core/agent.h>
#include <fstream>
#include "tools/csvwriter.h"
class CSVWriter;
class CrowdSimulator {
private:
std::unique_ptr<WorldBase> world_;
CSVWriter writer;
CSVWriter* writer;
public:
......
......@@ -32,11 +32,13 @@
CrowdSimulator::CrowdSimulator()
{
//createNewWorld(WorldType::INFINITE);
writer = nullptr;
}
CrowdSimulator::~CrowdSimulator()
{
if (writer != nullptr)
delete writer;
}
void CrowdSimulator::loadConfigFile(const std::string &filename)
......@@ -65,7 +67,9 @@ void CrowdSimulator::runMasterConfigFile(const std::string &filename)
void CrowdSimulator::setOutputDir(const std::string &dirname)
{
writer.setDirectory(dirname);
if (writer == nullptr)
writer = new CSVWriter();
writer->setDirectory(dirname);
}
void CrowdSimulator::AppendPosInOutput(std::ofstream &outfile, double time, Agent* agent)
......@@ -93,12 +97,15 @@ void CrowdSimulator::stepWorld()
float t = world_->getTime();
const std::vector<Agent*>& agents = world_->getAgents();
std::map<int, Vector2D> poss;
for (const Agent* agent : agents)
poss[agent->getID()] = agent->getPosition();
if (writer != nullptr)
{
std::map<int, Vector2D> poss;
for (const Agent* agent : agents)
poss[agent->getID()] = agent->getPosition();
writer.appendPedPositions(poss, t);
//writer.flush(); //! @todo: should be removed after test
writer->appendPedPositions(poss, t);
//writer.flush(); //! @todo: should be removed after test
}
}
/**
......@@ -111,10 +118,11 @@ void CrowdSimulator::runWorld(int steps)
std::cout << "|--------------------------------------------------|100%" << std::endl << "[";
for (int i = 0; i < steps; ++i){
stepWorld();
if(i%p == 0) std::cout << "#" << std::flush;
//if(i%p == 0) std::cout << "#" << std::flush;
}
std::cout << "]" << std::endl;
writer.flush();
if (writer != nullptr)
writer->flush();
}
void CrowdSimulator::createNewWorld(WorldType type) {
......
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