Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/ScriptableController_HS17/src/orxonox/scriptablecontroller/scriptable_controller_api.h @ 11583

Last change on this file since 11583 was 11583, checked in by kohlia, 6 years ago

Near object, near point and at area work!

File size: 3.3 KB
Line 
1#ifndef SCRIPTABLE_CONTROLLER_API_H
2#define SCRIPTABLE_CONTROLLER_API_H
3
4#include <functional>
5#include "core/CoreIncludes.h"
6#include "tools/Timer.h"
7#include "OgreVector3.h"
8
9struct lua_State;
10
11namespace orxonox
12{
13
14class ScriptableController;
15class WorldEntity;
16
17class ScriptableControllerAPI
18{
19public:
20    ScriptableControllerAPI(lua_State *lua, ScriptableController *controller);
21    ~ScriptableControllerAPI();
22
23    void testOutput(std::function<void(std::string)> callback);
24
25    void orxPrint(std::string msg);
26    void registerAfterTimeout(std::function<void (void)> callback, double timeout);
27
28    void registerAtNearObject(std::function<void(std::string, std::string)> callback, std::string id1, std::string id2, double distance);
29    void registerAtNearPoint(std::function<void (std::string)> callback, std::string id, double x, double y, double z, double distance);
30    void registerAtAreaEnter(std::function<void (std::string)> callback, std::string obj, int x, int y, int z, int dx, int dy, int dz);
31    void registerAtAreaLeave(std::function<void (std::string)> callback, std::string obj, int x, int y, int z, int dx, int dy, int dz);
32
33    void registerAtObjectDestroyed(std::function<void (std::string)> callback, std::string obj);
34    void registerAtPickup(std::function<void (int)> callback, int pickup_id);
35
36    void destroyObject(std::string obj);
37    void removeObject(std::string obj);
38    void setObjectPosition(std::string obj, double x, double y, double z);
39
40private:
41    struct NearObjectHandler
42    {
43        NearObjectHandler(WorldEntity *entity1, WorldEntity *entity2, std::string id1, std::string id2, double distance, std::function<void (std::string, std::string)> callback)
44            : entity1_(entity1), entity2_(entity2), id1_(id1), id2_(id2), distance_(distance), callback_(callback)
45        {}
46
47        WorldEntity *entity1_, *entity2_;
48        std::string id1_, id2_;
49        double distance_;
50        std::function<void (std::string, std::string)> callback_;
51    };
52
53    struct NearPointHandler
54    {
55        NearPointHandler(WorldEntity *entity, std::string id, double x, double y, double z, double distance, std::function<void (std::string)> callback)
56            : entity_(entity), id_(id), point_(x, y, z), distance_(distance), callback_(callback)
57        {}
58
59        WorldEntity *entity_;
60        std::string id_;
61        Vector3 point_;
62        double distance_;
63        std::function<void (std::string)> callback_;
64    };
65
66    struct AreaHandler
67    {
68        AreaHandler(WorldEntity *entity, std::string id, double x, double y, double z, double dx, double dy, double dz, bool atEnter, std::function<void (std::string)> callback)
69            : entity_(entity), id_(id), start_point_(x, y, z), atEnter_(atEnter), callback_(callback)
70        { this-> end_point_ = this->start_point_ + Vector3(dx, dy, dz); }
71
72        WorldEntity *entity_;
73        std::string id_;
74        Vector3 start_point_, end_point_;
75        bool atEnter_;
76        std::function<void (std::string)> callback_;
77    };
78
79
80    lua_State *lua_;
81    ScriptableController *controller_;
82    std::list<NearObjectHandler> nearObjectHandlers_;
83    std::list<NearPointHandler> nearPointHandlers_;
84    std::list<AreaHandler> areaHandlers_;
85    Timer areaCheckTimer;
86
87    void checkAreas(void);
88};
89
90}
91
92#endif // SCRIPTABLE_CONTROLLER_API_H
Note: See TracBrowser for help on using the repository browser.