Skip to content

Commit

Permalink
move game thread exec in Unreal code
Browse files Browse the repository at this point in the history
  • Loading branch information
sytelus committed Oct 17, 2017
1 parent ffbb8cf commit 44650eb
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
4 changes: 1 addition & 3 deletions AirLib/include/vehicles/multirotor/api/DroneApi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,7 @@ class DroneApi : public VehicleApiBase {

virtual void reset() override
{
UAirBlueprintLib::RunCommandOnGameThread([this]() {
vehicle_->reset();
});
vehicle_->reset();
}


Expand Down
5 changes: 4 additions & 1 deletion Unreal/Plugins/AirSim/Source/AirBlueprintLib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ T* UAirBlueprintLib::FindActor(const UObject* context, FString name)

void UAirBlueprintLib::RunCommandOnGameThread(TFunction<void()> InFunction, const TStatId InStatId)
{
FFunctionGraphTask::CreateAndDispatchWhenReady(MoveTemp(InFunction), InStatId, nullptr, ENamedThreads::GameThread);
if (IsInGameThread())
InFunction();
else
FFunctionGraphTask::CreateAndDispatchWhenReady(MoveTemp(InFunction), InStatId, nullptr, ENamedThreads::GameThread);
}


Expand Down
14 changes: 8 additions & 6 deletions Unreal/Plugins/AirSim/Source/Multirotor/MultiRotorConnector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,14 +273,16 @@ bool MultiRotorConnector::isApiServerStarted()
//*** Start: UpdatableState implementation ***//
void MultiRotorConnector::reset()
{
VehicleConnectorBase::reset();
UAirBlueprintLib::RunCommandOnGameThread([this]() {
VehicleConnectorBase::reset();

//TODO: should this be done in MultiRotor.hpp
//controller_->reset();
//TODO: should this be done in MultiRotor.hpp
//controller_->reset();

rc_data_ = RCData();
vehicle_pawn_wrapper_->reset(); //we do flier resetPose so that flier is placed back without collisons
vehicle_.reset();
rc_data_ = RCData();
vehicle_pawn_wrapper_->reset(); //we do flier resetPose so that flier is placed back without collisons
vehicle_.reset();
});
}

void MultiRotorConnector::update()
Expand Down
4 changes: 2 additions & 2 deletions Unreal/Plugins/AirSim/Source/Recording/RecordingFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ void RecordingFile::appendRecord(TArray<uint8>& image_data, const msr::airlib::K
std::string filename = std::string("img_").append(std::to_string(images_saved_)).append(".png");

try {
filePath = FString(common_utils::FileSystem::combine(image_path_, filename).c_str());
imageSavedOk = FFileHelper::SaveArrayToFile(image_data, *filePath);
FString image_file_path = FString(common_utils::FileSystem::combine(image_path_, filename).c_str());
imageSavedOk = FFileHelper::SaveArrayToFile(image_data, *image_file_path);
}
catch(std::exception& ex) {
UAirBlueprintLib::LogMessage(TEXT("Image file save failed"), FString(ex.what()), LogDebugLevel::Failure);
Expand Down

0 comments on commit 44650eb

Please sign in to comment.