[11519] | 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 | |
---|
[11562] | 19 | class ScriptableController |
---|
[11519] | 20 | { |
---|
| 21 | public: |
---|
[11562] | 22 | struct NearObjectHandler |
---|
| 23 | { |
---|
| 24 | NearObjectHandler(WorldEntity *otherObject, double distance, std::function<void (int, int)> callback) |
---|
| 25 | : otherObject_(otherObject), distance_(distance), callback_(callback) |
---|
| 26 | {} |
---|
[11549] | 27 | |
---|
[11562] | 28 | WorldEntity *otherObject_; |
---|
| 29 | double distance_; |
---|
| 30 | std::function<void (int, int)> callback_; |
---|
| 31 | std::list<std::unique_ptr<NearObjectHandler> >::iterator otherHandler_; |
---|
| 32 | }; |
---|
| 33 | |
---|
[11519] | 34 | int runScript(const std::string &file_path); |
---|
| 35 | |
---|
[11562] | 36 | void setPlayer(PlayerInfo *player); |
---|
[11519] | 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 | |
---|
[11562] | 43 | void addNearObjectHandler(int obj1, int obj2, double distance, std::function<void (int, int)> callback); |
---|
[11549] | 44 | |
---|
[11562] | 45 | void objectMoved(WorldEntity *obj); |
---|
[11549] | 46 | |
---|
[11519] | 47 | private: |
---|
| 48 | std::list<std::unique_ptr<ScriptableControllerAPI> > apis_; |
---|
[11562] | 49 | PlayerInfo *player_; |
---|
[11519] | 50 | std::map<int, WorldEntity*> worldEntities_; |
---|
| 51 | std::map<int, ControllableEntity*> controllabelEntities_; |
---|
| 52 | |
---|
[11562] | 53 | std::map<WorldEntity*, std::list<std::unique_ptr<NearObjectHandler> > > nearObjectHandlers_; |
---|
| 54 | |
---|
[11519] | 55 | void printLuaError(lua_State *lua); |
---|
| 56 | }; |
---|
| 57 | |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | #endif // SCRIPTABLE_CONTROLLER_H |
---|