~robot3d-team/robot3d/trunk

« back to all changes in this revision

Viewing changes to inc/srCore/simulationArenaComponent.h

  • Committer: Anne van Rossum
  • Date: 2010-08-10 15:58:55 UTC
  • Revision ID: anne@gamix-20100810155855-kve7x2vwouagdij9
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * arena component doing all the basic stuff
 
3
 *
 
4
 * @author Adrian Friebel
 
5
 */
 
6
 
 
7
#ifndef SIMULATIONARENACOMPONENT_H_
 
8
#define SIMULATIONARENACOMPONENT_H_
 
9
 
 
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>
 
17
 
 
18
#include <dtGame/gmcomponent.h>
 
19
 
 
20
#include <dtDAL/gameeventmanager.h>
 
21
 
 
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
 
25
 *                      - ...
 
26
 *
 
27
 * These components can use this class for accessing all robots and controllers.
 
28
 *
 
29
 * To get access to this component use the following line:
 
30
 * SimulationArenaComponent *comp = static_cast<SimulationArenaComponent*>(GetGameManager()->GetComponentByName(SimulationArenaComponent::DEFAULT_NAME));
 
31
 *
 
32
 */
 
33
 
 
34
namespace srCore {
 
35
 
 
36
/**
 
37
 * class for handling the simulation
 
38
 */
 
39
class ROBOT_EXPORT SimulationArenaComponent : public dtGame::GMComponent
 
40
{
 
41
        public:
 
42
 
 
43
                static const std::string DEFAULT_NAME;
 
44
 
 
45
                SimulationArenaComponent(const std::string &name);
 
46
 
 
47
                //! loads a new scene during runtime  -  TODO: the map keeps the same
 
48
                void loadScene(std::string file);
 
49
 
 
50
                //! initlize the simulation
 
51
                void init();
 
52
 
 
53
                void ProcessMessage(const dtGame::Message &message);
 
54
 
 
55
                //! creates robot according to the description in the given scene file.
 
56
                void createRobotsFromSceneFile(const GetConfig &appConfig);
 
57
 
 
58
                //! Creates a new robot
 
59
                void createRobot(RobotInitData rid);
 
60
 
 
61
                //! Returns the number of robots that currently in the scene
 
62
                int getNumRobots() { return numRobots; };
 
63
 
 
64
                //! Returns the index of the currently selected robot
 
65
                int getRobFocIndex() {return robotFocusIndex; };
 
66
 
 
67
                //! Disconnects the robot from other robots, deletes and removes it from the scene
 
68
                void destroyRobot(srCore::RobotActorBase &robotActor);
 
69
 
 
70
                //! Returns the selected robot
 
71
                dtCore::RefPtr<srCore::RobotActorBase> getSelectedRobot();
 
72
 
 
73
                //! Selects another robot
 
74
                void selectRobot(dtCore::RefPtr<srCore::RobotActorBase> robotToSelect);
 
75
 
 
76
                //! Selects the next robot in the list
 
77
                void selectNextRobot();
 
78
 
 
79
                //! Resets the simulation
 
80
                void reset();
 
81
 
 
82
                //! Removes all robots and controllers from the scene
 
83
                void clear();
 
84
 
 
85
                //! toggles the screenshot saver
 
86
                void toggleScreenShots(bool toggle);
 
87
 
 
88
                //! Returns all Robots in the scene
 
89
                std::vector<dtCore::RefPtr<RobotActorBase> > getRobotsInScene();
 
90
 
 
91
                //! Returns a robot by its name
 
92
                dtCore::RefPtr<RobotActorBase> getRobot(const std::string &name);
 
93
 
 
94
        protected:
 
95
                virtual ~SimulationArenaComponent() { }
 
96
 
 
97
        private:
 
98
              void sendMessageToAll(dtDAL::GameEvent &event);
 
99
 
 
100
              float getZPos(float x, float y, dtCore::Scene &scene);
 
101
 
 
102
              //! Starts or resumes the simulation
 
103
              void start();
 
104
 
 
105
              //! Pauses the simulation. Can only be activated invoking a game message.
 
106
              void pause();
 
107
 
 
108
              //! Destroys selected robot
 
109
              void destroyRobot();
 
110
 
 
111
              bool isResettingTheScene;
 
112
 
 
113
              int robotFocus;
 
114
              int robotFocusIndex;
 
115
              bool paused;
 
116
              double timeScale;
 
117
              int numRobots, numRobotsAtBeginOfFrame;
 
118
              std::vector<int> freedInd;
 
119
              dtCore::RefPtr<dtDAL::GameEvent> mActorDestroyed;
 
120
              dtCore::RefPtr<dtDAL::GameEvent> mFocusChanged;
 
121
 
 
122
              std::vector<dtCore::RefPtr<RobotActorBase> > robotsInScene;
 
123
};
 
124
}
 
125
 
 
126
#endif /*SIMULATIONARENACOMPONENT_H_*/