Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 20, 2017, 4:48:03 PM (6 years ago)
Author:
kohlia
Message:

Near object, near point and at area work!

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/ScriptableController_HS17/src/orxonox/scriptablecontroller/scriptable_controller_api.h

    r11562 r11583  
    44#include <functional>
    55#include "core/CoreIncludes.h"
    6 
    7 // TODO Is pos int or double?
     6#include "tools/Timer.h"
     7#include "OgreVector3.h"
    88
    99struct lua_State;
     
    1313
    1414class ScriptableController;
     15class WorldEntity;
    1516
    1617class ScriptableControllerAPI
     
    2425    void orxPrint(std::string msg);
    2526    void registerAfterTimeout(std::function<void (void)> callback, double timeout);
    26     int registerAtNearObject(std::function<void(int, int)> callback, int obj1, int obj2, double distance);
    27     int registerAtAreaEnter(std::function<void (int)> callback, int obj, int x, int y, int z, int dx, int dy, int dz);
    28     int registerAtAreaLeave(std::function<void (int)> callback, int obj, int x, int y, int z, int dx, int dy, int dz);
    29     int registerAtObjectDestroyed(std::function<void (int)> callback, int obj);
    30     int registerAtPickup(std::function<void (int)> callback, int pickup_id);
    3127
    32     int destroyObject(int obj);
    33     void removeObject(int obj);
    34     int setObjectPosition(int obj, double x, double y, double z);
     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);
    3539
    3640private:
     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
    3780    lua_State *lua_;
    3881    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);
    3988};
    4089
Note: See TracChangeset for help on using the changeset viewer.