Commit 21a89535 authored by VAN TOLL Wouter's avatar VAN TOLL Wouter
Browse files

Merge branch 'master' into 89-visualize-cost-functions

parents 45e59b3e 4177748f
......@@ -21,7 +21,6 @@
#include <core/agent.h>
#include <core/worldBase.h>
#include <3rd-party/ORCA/ORCASolver.h>
Agent::Agent(size_t id, const Agent::Settings& settings) :
id_(id), settings_(settings),
......
......@@ -22,12 +22,10 @@
#ifndef LIB_AGENT_H
#define LIB_AGENT_H
#include <iostream>
#include <tools/vector2D.h>
#include <core/policy.h>
#include <memory>
#include <3rd-party/ORCA/ORCALine.h>
#include <random>
#include "../3rd-party/ORCA/ORCALine.h"
class WorldBase;
......
......@@ -23,13 +23,7 @@
#define LIB_COST_FUNCTION_H
#include <core/costFunctionParameters.h>
#include <tools/vector2D.h>
#include <vector>
#include <string>
#include <map>
#include <memory>
#include <limits> // std::reference_wrapper
class WorldBase;
class Agent;
......@@ -43,8 +37,6 @@ typedef std::pair<AgentNeighborList, ObstacleNeighborList> NeighborList;
typedef std::vector<std::pair<const CostFunction*, float>> CostFunctionList;
const float MaxFloat = std::numeric_limits<float>::max();
/// @defgroup costfunctions Cost functions
/// Implementations of specific cost functions for local navigation.
......
......@@ -22,10 +22,10 @@
#ifndef LIB_CROWD_SIMULATOR_H
#define LIB_CROWD_SIMULATOR_H
#include <memory>
#include <core/worldBase.h>
#include <core/agent.h>
#include <fstream>
#include <map>
class CSVWriter;
/// <summary>Wrapper object that manages the overall crowd simulation.</summary>
......
......@@ -22,12 +22,9 @@
#ifndef LIB_POLICY_H
#define LIB_POLICY_H
#include <3rd-party/tinyxml/tinyxml2.h>
#include <core/costFunction.h>
#include <tools/vector2D.h>
#include <vector>
#include <memory>
#include <string>
#include <core/costFunction.h>
#include <3rd-party/tinyxml/tinyxml2.h>
class WorldBase;
class Agent;
......
......@@ -22,19 +22,14 @@
#ifndef LIB_WORLD_BASE_H
#define LIB_WORLD_BASE_H
#include <vector>
#include <memory>
#include <string>
#include <queue>
#include <limits>
#include <unordered_map>
typedef std::unordered_map<size_t, size_t> AgentIDMap;
#include <tools/Polygon2D.h>
#include <core/agent.h>
#include <core/AgentKDTree.h>
#include <queue>
#include <unordered_map>
typedef std::unordered_map<size_t, size_t> AgentIDMap;
/// <summary>A reference to an agent in the simulation, possibly with a transposed position.
/// Nearest-neighbor queries in WorldBase return results of this type.</summary>
struct PhantomAgent
......
......@@ -27,6 +27,8 @@
const double PI = 3.1415926535897;
const float MaxFloat = std::numeric_limits<float>::max();
/// <summary>A 2D vector, used for representing positions, velocities, etc.</summary>
class Vector2D
{
......
......@@ -133,6 +133,11 @@ void UMANSOpenGLWidget::startNewSimulation(const std::string& scenarioFilename)
setActiveAgent(nullptr);
simulator = newSimulator;
// Prepare a timer for update events, using the current value of playbackMultiplier.
// This works for the very first simulation, because playbackMultiplier=1 by default.
// In other cases, the new simulation may use a different framerate than the previous one, so we need to re-initialize the timer.
SetPlaybackMultiplier(playbackMultiplier);
}
else
{
......@@ -203,28 +208,25 @@ void UMANSOpenGLWidget::SetPlaybackMultiplier(int value)
{
playbackMultiplier = value;
bool simulationWasPlaying = false;
// prepare a timer for automatically running the simulation
if (simulationTimer == nullptr)
simulationTimer = new QTimer(this);
else
{
disconnect(simulationTimer, SIGNAL(timeout()), this, SLOT(updateSimulation()));
if (simulationTimer->isActive())
{
simulationWasPlaying = true;
simulationTimer->stop();
}
}
simulationTimer->setInterval((int)(1000 * simulator->GetWorld()->GetDeltaTime() / playbackMultiplier));
connect(simulationTimer, SIGNAL(timeout()), this, SLOT(updateSimulation()));
// determine how many milliseconds should be between two simulation updates
int desiredRefreshTime = (int)(1000 * simulator->GetWorld()->GetDeltaTime() / playbackMultiplier);
// schedule a Qt timer for periodically updating the simulation
simulationTimer->setInterval(desiredRefreshTime);
connect(simulationTimer, SIGNAL(timeout()), this, SLOT(updateSimulation()));
// if the simulation was running before we changed this multiplier, make sure it continues running
if (simulationWasPlaying)
if (simulationRunning)
simulationTimer->start();
}
......@@ -682,9 +684,6 @@ void UMANSOpenGLWidget::initializeGL()
// initialize the simulation
startNewSimulation(DefaultScenarioFile);
// prepare a timer for updating the simulation
SetPlaybackMultiplier(1);
program.release();
}
......
......@@ -114,7 +114,7 @@ private:
bool inAgentSelectMode;
bool panning;
bool simulationRunning;
int playbackMultiplier;
int playbackMultiplier = 1;
bool makeScreenshotsPerFrame;
bool writeCSVOutput;
......
......@@ -21,6 +21,7 @@
#include "UMANSQtGuiApplication.h"
#include <QtWidgets/QApplication>
#include <iostream>
void printBasicInfo()
{
......
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