2
* arena component doing all the basic stuff
4
* @author Adrian Friebel
7
#ifndef SIMULATIONARENACOMPONENT_H_
8
#define SIMULATIONARENACOMPONENT_H_
10
#include <srCore/export.h>
11
#include <srCore/robot/robotActorBase.h>
12
//#include "controller/controllers.h"
13
//#include "controller/controllerComponentBase.h"
14
#include <srCore/simulationRobotSelectionComponent.h>
15
#include <srCore/simulationUtils.h>
16
#include <srCore/xmlConfig.h>
18
#include <dtGame/gmcomponent.h>
20
#include <dtDAL/gameeventmanager.h>
22
/* TODO: Implementing other components for offline/offboard learning, i.e. such as
23
* - logging robot behaviours (see dtUtils::Log)
24
* - Evaluating the (offboard) fitness
27
* These components can use this class for accessing all robots and controllers.
29
* To get access to this component use the following line:
30
* SimulationArenaComponent *comp = static_cast<SimulationArenaComponent*>(GetGameManager()->GetComponentByName(SimulationArenaComponent::DEFAULT_NAME));
37
* class for handling the simulation
39
class ROBOT_EXPORT SimulationArenaComponent : public dtGame::GMComponent
43
static const std::string DEFAULT_NAME;
45
SimulationArenaComponent(const std::string &name);
47
//! loads a new scene during runtime - TODO: the map keeps the same
48
void loadScene(std::string file);
50
//! initlize the simulation
53
void ProcessMessage(const dtGame::Message &message);
55
//! creates robot according to the description in the given scene file.
56
void createRobotsFromSceneFile(const GetConfig &appConfig);
58
//! Creates a new robot
59
void createRobot(RobotInitData rid);
61
//! Returns the number of robots that currently in the scene
62
int getNumRobots() { return numRobots; };
64
//! Returns the index of the currently selected robot
65
int getRobFocIndex() {return robotFocusIndex; };
67
//! Disconnects the robot from other robots, deletes and removes it from the scene
68
void destroyRobot(srCore::RobotActorBase &robotActor);
70
//! Returns the selected robot
71
dtCore::RefPtr<srCore::RobotActorBase> getSelectedRobot();
73
//! Selects another robot
74
void selectRobot(dtCore::RefPtr<srCore::RobotActorBase> robotToSelect);
76
//! Selects the next robot in the list
77
void selectNextRobot();
79
//! Resets the simulation
82
//! Removes all robots and controllers from the scene
85
//! toggles the screenshot saver
86
void toggleScreenShots(bool toggle);
88
//! Returns all Robots in the scene
89
std::vector<dtCore::RefPtr<RobotActorBase> > getRobotsInScene();
91
//! Returns a robot by its name
92
dtCore::RefPtr<RobotActorBase> getRobot(const std::string &name);
95
virtual ~SimulationArenaComponent() { }
98
void sendMessageToAll(dtDAL::GameEvent &event);
100
float getZPos(float x, float y, dtCore::Scene &scene);
102
//! Starts or resumes the simulation
105
//! Pauses the simulation. Can only be activated invoking a game message.
108
//! Destroys selected robot
111
bool isResettingTheScene;
117
int numRobots, numRobotsAtBeginOfFrame;
118
std::vector<int> freedInd;
119
dtCore::RefPtr<dtDAL::GameEvent> mActorDestroyed;
120
dtCore::RefPtr<dtDAL::GameEvent> mFocusChanged;
122
std::vector<dtCore::RefPtr<RobotActorBase> > robotsInScene;
126
#endif /*SIMULATIONARENACOMPONENT_H_*/