Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 6, 2017, 5:23:08 PM (7 years ago)
Author:
kohlia
Message:

Not working yet

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/ScriptableController_HS17/src/orxonox/scriptablecontroller/scriptable_controller.cc

    r11519 r11549  
    66{
    77
     8RegisterUnloadableClass(ScriptableController);
     9
    810// Used https://csl.name/post/lua-and-cpp/ as a reference
     11ScriptableController::ScriptableController(Context* context)
     12    : BaseObject(context)
     13{
     14    RegisterObject(ScriptableController);
     15}
     16
    917int ScriptableController::runScript(const std::string &file_path)
    1018{
     
    7179}
    7280
     81void ScriptableController::registerTimeout(std::function<void ()> callback, double timeout)
     82{
     83    this->timeouts.push_back(std::make_pair(callback, static_cast<float>(timeout)));
     84    orxout(user_warning) << "Calling should work..." << std::endl;
     85    callback();
     86}
     87
     88void ScriptableController::tick(float dt)
     89{
     90    auto timeout = this->timeouts.begin();
     91
     92    while(timeout != this->timeouts.end())
     93    {
     94        timeout->second -= dt;
     95        if(timeout->second <= 0)
     96        {
     97            orxout(user_warning) << "Calling..." << std::endl;
     98            timeout->first();
     99            timeout = this->timeouts.erase(timeout);
     100        }
     101        else
     102        {
     103            timeout++;
     104        }
     105    }
     106
     107    Tickable::tick(dt);
     108}
     109
    73110void ScriptableController::printLuaError(lua_State *lua)
    74111{
Note: See TracChangeset for help on using the changeset viewer.