1 | #ifndef SCRIPTABLE_CONTROLLER_H |
---|
2 | #define SCRIPTABLE_CONTROLLER_H |
---|
3 | |
---|
4 | #include <lua.hpp> |
---|
5 | #include <string> |
---|
6 | #include <list> |
---|
7 | #include <map> |
---|
8 | #include <memory> |
---|
9 | #include "scriptable_controller_api.h" |
---|
10 | #include "core/CoreIncludes.h" |
---|
11 | #include "worldentities/WorldEntity.h" |
---|
12 | #include "worldentities/ControllableEntity.h" |
---|
13 | |
---|
14 | struct lua_State; |
---|
15 | |
---|
16 | namespace orxonox |
---|
17 | { |
---|
18 | |
---|
19 | class ScriptableController |
---|
20 | { |
---|
21 | public: |
---|
22 | struct NearObjectHandler |
---|
23 | { |
---|
24 | NearObjectHandler(WorldEntity *otherObject, double distance, std::function<void (int, int)> callback) |
---|
25 | : otherObject_(otherObject), distance_(distance), callback_(callback) |
---|
26 | {} |
---|
27 | |
---|
28 | WorldEntity *otherObject_; |
---|
29 | double distance_; |
---|
30 | std::function<void (int, int)> callback_; |
---|
31 | std::list<std::unique_ptr<NearObjectHandler> >::iterator otherHandler_; |
---|
32 | }; |
---|
33 | |
---|
34 | int runScript(const std::string &file_path); |
---|
35 | |
---|
36 | void setPlayer(PlayerInfo *player); |
---|
37 | void registerWorldEntity(int id, WorldEntity *obj); |
---|
38 | void registerControllableEntity(int id, ControllableEntity *obj); |
---|
39 | |
---|
40 | WorldEntity *getWorldEntityByID(int id) const; |
---|
41 | ControllableEntity *getControllableEntityByID(int id) const; |
---|
42 | |
---|
43 | void addNearObjectHandler(int obj1, int obj2, double distance, std::function<void (int, int)> callback); |
---|
44 | |
---|
45 | void objectMoved(WorldEntity *obj); |
---|
46 | |
---|
47 | private: |
---|
48 | std::list<std::unique_ptr<ScriptableControllerAPI> > apis_; |
---|
49 | PlayerInfo *player_; |
---|
50 | std::map<int, WorldEntity*> worldEntities_; |
---|
51 | std::map<int, ControllableEntity*> controllabelEntities_; |
---|
52 | |
---|
53 | std::map<WorldEntity*, std::list<std::unique_ptr<NearObjectHandler> > > nearObjectHandlers_; |
---|
54 | |
---|
55 | void printLuaError(lua_State *lua); |
---|
56 | }; |
---|
57 | |
---|
58 | } |
---|
59 | |
---|
60 | #endif // SCRIPTABLE_CONTROLLER_H |
---|