Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 14, 2017, 4:04:14 PM (7 years ago)
Author:
kohlia
Message:

The ScriptableController should work now. A demo level called scriptableControllerTest exists as well.

File:
1 edited

Legend:

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

    r11662 r11673  
    1818    this->controller_ = controller;
    1919
    20     // Haven't found a shorter way yet to write that...
     20    // Haven't found a shorter way yet to write that... We need C++17!
    2121    LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::orxPrint)>::registerFunction<&ScriptableControllerAPI::orxPrint>(this, lua, "orxPrint");
    2222
     
    101101void ScriptableControllerAPI::killPawn(std::string id)
    102102{
    103     // We don't kill the pawn here directly, because this function is called from LUA and thus
    104     // runs in a different thread. So we schedule the kill for later in the main thread
    105     // (in 'periodic').
    106     this->pawnsToKill_.push_back(id);
     103    Pawn *pawn = this->controller_->getPawnByID(id);
     104    if(pawn == nullptr)
     105        orxout(user_warning) << "Trying to kill an unknown pawn" << std::endl;
     106    else
     107        pawn->kill();
    107108}
    108109
     
    168169    const Vector3 &old = entity->getPosition();
    169170
     171    // If one of the values is NaN, don't change that value
    170172    x = std::isnan(x) ? old.x : x;
    171173    y = std::isnan(y) ? old.y : y;
     
    189191    entity->getOrientation().ToAngleAxis(old_angle, old_axis);
    190192
     193    // If one of the values is NaN, don't change that value
    191194    x = std::isnan(x) ? old_axis.x : x;
    192195    y = std::isnan(y) ? old_axis.y : y;
     
    194197    angle = std::isnan(x) ? old_angle.valueDegrees() : angle;
    195198
     199
    196200    entity->setOrientation(Vector3(x, y, z), Degree(angle));
    197201}
     
    208212    const Vector3 &old = entity->getVelocity();
    209213
     214    // If one of the values is NaN, don't change that value
    210215    x = std::isnan(x) ? old.x : x;
    211216    y = std::isnan(y) ? old.y : y;
     
    226231    const Vector3 &old = entity->getAngularVelocity();
    227232
     233    // If one of the values is NaN, don't change that value
    228234    x = std::isnan(x) ? old.x : x;
    229235    y = std::isnan(y) ? old.y : y;
     
    248254        else
    249255            near_obj_handler++;
     256    }
     257
     258    auto near_point_handler = this->nearPointHandlers_.begin();
     259    while(near_point_handler != this->nearPointHandlers_.end())
     260    {
     261        if(near_point_handler->entity_ == pawn)
     262            near_point_handler = this->nearPointHandlers_.erase(near_point_handler);
     263        else
     264            near_point_handler++;
     265    }
     266
     267    auto area_handler = this->areaHandlers_.begin();
     268    while(area_handler != this->areaHandlers_.end())
     269    {
     270        if(area_handler->entity_ == pawn)
     271            area_handler = this->areaHandlers_.erase(area_handler);
     272        else
     273            area_handler++;
    250274    }
    251275}
     
    319343        }
    320344    }
    321 
    322     // Pawns to kill
    323     // TODO Possible race condidtion when the player destroys the pawn
    324     // between the callback and the next periodic call.
    325     for(auto &pawn : this->pawnsToKill_)
    326         this->controller_->killPawn(pawn);
    327 
    328     this->pawnsToKill_.clear();
    329 }
    330 
    331 }
     345}
     346
     347}
Note: See TracChangeset for help on using the changeset viewer.