Skip to content

Commit

Permalink
Merge pull request #4266 from rajat2004/multi-vehicle-trace
Browse files Browse the repository at this point in the history
Fix trace toggling for multiple vehicles
  • Loading branch information
zimmy87 authored Jan 12, 2022
2 parents c23a3a5 + d90a5a1 commit 0becf91
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 74 deletions.
21 changes: 0 additions & 21 deletions Unity/AirLibWrapper/AirsimWrapper/Source/SimHUD/SimHUD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,6 @@ void SimHUD::EndPlay()
}
}

SimHUD::ImageType SimHUD::getSubwindowCameraType(int window_index)
{
//TODO: index check
return getSubWindowSettings().at(window_index).image_type;
}

void SimHUD::setSubwindowCameraType(int window_index, ImageType type)
{
getSubWindowSettings().at(window_index).image_type = type;
}

bool SimHUD::getSubwindowVisible(int window_index)
{
return getSubWindowSettings().at(window_index).visible;
}

void SimHUD::setSubwindowVisible(int window_index, bool is_visible)
{
getSubWindowSettings().at(window_index).visible = is_visible;
}

void SimHUD::initializeSettings()
{
std::string settingsText;
Expand Down
4 changes: 0 additions & 4 deletions Unity/AirLibWrapper/AirsimWrapper/Source/SimHUD/SimHUD.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ class SimHUD
public:
SimHUD(std::string sime_mode_name, int port_number);
SimModeBase* GetSimMode();
ImageType getSubwindowCameraType(int window_index);
void setSubwindowCameraType(int window_index, ImageType type);
bool getSubwindowVisible(int window_index);
void setSubwindowVisible(int window_index, bool is_visible);
virtual void BeginPlay();
virtual void EndPlay();
virtual void Tick(float DeltaSeconds);
Expand Down
53 changes: 11 additions & 42 deletions Unreal/Plugins/AirSim/Source/SimHUD/SimHUD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,41 +88,7 @@ void ASimHUD::inputEventToggleHelp()

void ASimHUD::inputEventToggleTrace()
{
simmode_->getVehicleSimApi()->toggleTrace();
}

ASimHUD::ImageType ASimHUD::getSubwindowCameraType(int window_index)
{
//TODO: index check
return getSubWindowSettings().at(window_index).image_type;
}

void ASimHUD::setSubwindowCameraType(int window_index, ImageType type)
{
getSubWindowSettings().at(window_index).image_type = type;
updateWidgetSubwindowVisibility();
}

APIPCamera* ASimHUD::getSubwindowCamera(int window_index)
{
return subwindow_cameras_[window_index]; //TODO: index check
}

void ASimHUD::setSubwindowCamera(int window_index, APIPCamera* camera)
{
subwindow_cameras_[window_index] = camera; //TODO: index check
updateWidgetSubwindowVisibility();
}

bool ASimHUD::getSubwindowVisible(int window_index)
{
return getSubWindowSettings().at(window_index).visible;
}

void ASimHUD::setSubwindowVisible(int window_index, bool is_visible)
{
getSubWindowSettings().at(window_index).visible = is_visible;
updateWidgetSubwindowVisibility();
simmode_->toggleTraceAll();
}

void ASimHUD::updateWidgetSubwindowVisibility()
Expand All @@ -135,7 +101,7 @@ void ASimHUD::updateWidgetSubwindowVisibility()

if (camera != nullptr) {
camera->setCameraTypeEnabled(camera_type, is_visible);
//sub-window captures dont count as a request, set bCaptureEveryFrame and bCaptureOnMovement to display so we can show correctly the subwindow
//sub-window captures don't count as a request, set bCaptureEveryFrame and bCaptureOnMovement to display so we can show correctly the subwindow
camera->setCameraTypeUpdate(camera_type, false);
}

Expand All @@ -150,22 +116,25 @@ bool ASimHUD::isWidgetSubwindowVisible(int window_index)
return widget_->getSubwindowVisibility(window_index) != 0;
}

void ASimHUD::inputEventToggleSubwindow0()
void ASimHUD::toggleSubwindowVisibility(int window_index)
{
getSubWindowSettings().at(0).visible = !getSubWindowSettings().at(0).visible;
getSubWindowSettings().at(window_index).visible = !getSubWindowSettings().at(window_index).visible;
updateWidgetSubwindowVisibility();
}

void ASimHUD::inputEventToggleSubwindow0()
{
toggleSubwindowVisibility(0);
}

void ASimHUD::inputEventToggleSubwindow1()
{
getSubWindowSettings().at(1).visible = !getSubWindowSettings().at(1).visible;
updateWidgetSubwindowVisibility();
toggleSubwindowVisibility(1);
}

void ASimHUD::inputEventToggleSubwindow2()
{
getSubWindowSettings().at(2).visible = !getSubWindowSettings().at(2).visible;
updateWidgetSubwindowVisibility();
toggleSubwindowVisibility(2);
}

void ASimHUD::inputEventToggleAll()
Expand Down
8 changes: 1 addition & 7 deletions Unreal/Plugins/AirSim/Source/SimHUD/SimHUD.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@ class AIRSIM_API ASimHUD : public AHUD
void inputEventToggleSubwindow2();
void inputEventToggleAll();

ImageType getSubwindowCameraType(int window_index);
void setSubwindowCameraType(int window_index, ImageType type);
APIPCamera* getSubwindowCamera(int window_index);
void setSubwindowCamera(int window_index, APIPCamera* camera);
bool getSubwindowVisible(int window_index);
void setSubwindowVisible(int window_index, bool is_visible);

ASimHUD();
virtual void BeginPlay() override;
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
Expand All @@ -51,6 +44,7 @@ class AIRSIM_API ASimHUD : public AHUD
void toggleRecordHandler();
void updateWidgetSubwindowVisibility();
bool isWidgetSubwindowVisible(int window_index);
void toggleSubwindowVisibility(int window_index);

private:
void initializeSubWindows();
Expand Down
8 changes: 8 additions & 0 deletions Unreal/Plugins/AirSim/Source/SimMode/SimModeBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,14 @@ bool ASimModeBase::isRecording() const
return FRecordingThread::isRecording();
}

void ASimModeBase::toggleTraceAll()
{
for (auto sim_api : getApiProvider()->getVehicleSimApis()) {
auto* pawn_sim_api = static_cast<PawnSimApi*>(sim_api);
pawn_sim_api->toggleTrace();
}
}

const APIPCamera* ASimModeBase::getCamera(const msr::airlib::CameraDetails& camera_details) const
{
return camera_details.external ? getExternalCamera(camera_details.camera_name)
Expand Down
2 changes: 2 additions & 0 deletions Unreal/Plugins/AirSim/Source/SimMode/SimModeBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ class AIRSIM_API ASimModeBase : public AActor
virtual void stopRecording();
virtual bool isRecording() const;

virtual void toggleTraceAll();

void startApiServer();
void stopApiServer();
bool isApiServerStarted();
Expand Down

0 comments on commit 0becf91

Please sign in to comment.