Skip to content

Commit

Permalink
settings to hide debug messages, record button, initial view mode
Browse files Browse the repository at this point in the history
  • Loading branch information
sytelus committed Jun 21, 2017
1 parent cf0e2b2 commit ee11a23
Show file tree
Hide file tree
Showing 13 changed files with 66 additions and 14 deletions.
2 changes: 0 additions & 2 deletions AirSim.sln
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SimHUD", "SimHUD", "{95E2FE
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SimMode", "SimMode", "{6175579D-2920-406D-A36B-2A0A56AA7892}"
ProjectSection(SolutionItems) = preProject
Unreal\Plugins\AirSim\Source\AirSimGameMode.cpp = Unreal\Plugins\AirSim\Source\AirSimGameMode.cpp
Unreal\Plugins\AirSim\Source\AirSimGameMode.h = Unreal\Plugins\AirSim\Source\AirSimGameMode.h
Unreal\Plugins\AirSim\Source\SimMode\SimModeBase.cpp = Unreal\Plugins\AirSim\Source\SimMode\SimModeBase.cpp
Unreal\Plugins\AirSim\Source\SimMode\SimModeBase.h = Unreal\Plugins\AirSim\Source\SimMode\SimModeBase.h
Unreal\Plugins\AirSim\Source\SimMode\SimModeWorldBase.cpp = Unreal\Plugins\AirSim\Source\SimMode\SimModeWorldBase.cpp
Expand Down
Binary file not shown.
Binary file modified Unreal/Plugins/AirSim/Content/Blueprints/BP_SimHUDWidget.uasset
Binary file not shown.
6 changes: 6 additions & 0 deletions Unreal/Plugins/AirSim/Source/AirBlueprintLib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,21 @@ parameters -> camel_case

typedef common_utils::Utils Utils;

bool UAirBlueprintLib::log_messages_hidden = false;

void UAirBlueprintLib::LogMessageString(const std::string &prefix, const std::string &suffix, LogDebugLevel level, float persist_sec)
{
LogMessage(FString(prefix.c_str()), FString(suffix.c_str()), level, persist_sec);
}

void UAirBlueprintLib::LogMessage(const FString &prefix, const FString &suffix, LogDebugLevel level, float persist_sec)
{
if (log_messages_hidden)
return;

static TMap<FString, int> loggingKeys;
static int counter = 1;

int key = loggingKeys.FindOrAdd(prefix);
if (key == 0) {
key = counter++;
Expand Down
12 changes: 12 additions & 0 deletions Unreal/Plugins/AirSim/Source/AirBlueprintLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,17 @@ class UAirBlueprintLib : public UBlueprintFunctionLibrary
typename FInputAxisHandlerSignature::TUObjectMethodDelegate<UserClass>::FMethodPtr func);

static void EnableInput(AActor* actor);

static bool getLogMessagesHidden()
{
return log_messages_hidden;
}
static void setLogMessagesHidden(bool is_hidden)
{
log_messages_hidden = is_hidden;
}

private:
static bool log_messages_hidden;
};

2 changes: 2 additions & 0 deletions Unreal/Plugins/AirSim/Source/AirSimGameMode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ void AAirSimGameMode::initializeSettings()
Settings& settings = Settings::loadJSonFile("settings.json");
auto settings_filename = Settings::singleton().getFileName();
if (settings.isLoadSuccess()) {
UAirBlueprintLib::setLogMessagesHidden(! settings.getBool("LogMessagesVisible", true));

std::string msg = "Loaded settings from " + settings_filename;
UAirBlueprintLib::LogMessage(FString(msg.c_str()), TEXT(""), LogDebugLevel::Informational);
}
Expand Down
22 changes: 13 additions & 9 deletions Unreal/Plugins/AirSim/Source/CameraDirector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ ECameraDirectorMode ACameraDirector::getMode()
return mode_;
}

void ACameraDirector::initializeForBeginPlay()
void ACameraDirector::initializeForBeginPlay(ECameraDirectorMode view_mode)
{
setupInputBindings();

Expand All @@ -42,10 +42,14 @@ void ACameraDirector::initializeForBeginPlay()
initial_ground_obs_offset_ = camera_start_location_ - TargetPawn->GetActorLocation();

//set initial view mode
setMode(ECameraDirectorMode::CAMERA_DIRECTOR_MODE_FLY_WITH_ME);
this->getCamera()->setToPIPView();
ExternalCamera->setToMainView();
ext_obs_fixed_z_ = false;
switch (view_mode) {
case ECameraDirectorMode::CAMERA_DIRECTOR_MODE_FLY_WITH_ME: inputEventFlyWithView(); break;
case ECameraDirectorMode::CAMERA_DIRECTOR_MODE_FPV: inputEventFpvView(); break;
case ECameraDirectorMode::CAMERA_DIRECTOR_MODE_GROUND_OBSERVER: inputEventGroundView(); break;
case ECameraDirectorMode::CAMERA_DIRECTOR_MODE_MANUAL: inputEventManualView(); break;
default:
throw std::out_of_range("Unknown view mode specified in CameraDirector::initializeForBeginPlay");
}
}

void ACameraDirector::setMode(ECameraDirectorMode mode)
Expand Down Expand Up @@ -120,23 +124,23 @@ void ACameraDirector::inputEventFlyWithView()
void ACameraDirector::inputManualLeft(float val)
{
if (!FMath::IsNearlyEqual(val, 0.f)) {
camera_location_manual_ += camera_rotation_manual_.RotateVector(FVector(0,-val*10,0));
camera_location_manual_ += camera_rotation_manual_.RotateVector(FVector(0,-val*10,0));
}
}
void ACameraDirector::inputManualRight(float val)
{
if (!FMath::IsNearlyEqual(val, 0.f))
camera_location_manual_ += camera_rotation_manual_.RotateVector(FVector(0, val * 10, 0));
camera_location_manual_ += camera_rotation_manual_.RotateVector(FVector(0, val * 10, 0));
}
void ACameraDirector::inputManualForward(float val)
{
if (!FMath::IsNearlyEqual(val, 0.f))
camera_location_manual_ += camera_rotation_manual_.RotateVector(FVector(val * 10, 0, 0));
camera_location_manual_ += camera_rotation_manual_.RotateVector(FVector(val * 10, 0, 0));
}
void ACameraDirector::inputManualBackward(float val)
{
if (!FMath::IsNearlyEqual(val, 0.f))
camera_location_manual_ += camera_rotation_manual_.RotateVector(FVector(-val * 10, 0, 0));
camera_location_manual_ += camera_rotation_manual_.RotateVector(FVector(-val * 10, 0, 0));
}
void ACameraDirector::inputManualMoveUp(float val)
{
Expand Down
2 changes: 1 addition & 1 deletion Unreal/Plugins/AirSim/Source/CameraDirector.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class AIRSIM_API ACameraDirector : public AActor
UFUNCTION(BlueprintCallable, Category = "Modes")
void setMode(ECameraDirectorMode mode);

void initializeForBeginPlay();
void initializeForBeginPlay(ECameraDirectorMode view_mode = ECameraDirectorMode::CAMERA_DIRECTOR_MODE_FLY_WITH_ME);

private:
void setupInputBindings();
Expand Down
1 change: 1 addition & 0 deletions Unreal/Plugins/AirSim/Source/SimHUD/SimHUD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ void ASimHUD::BeginPlay()
widget_->setReportVisible(simmode_->EnableReport);
widget_->refreshPIPVisibility(simmode_->CameraDirector->getCamera());
widget_->setOnToggleRecordingHandler(std::bind(&ASimHUD::toggleRecordHandler, this));
widget_->setRecordButtonVisibility(simmode_->isRecordUIVisible());
}

void ASimHUD::Tick( float DeltaSeconds )
Expand Down
5 changes: 4 additions & 1 deletion Unreal/Plugins/AirSim/Source/SimHUD/SimHUDWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ class AIRSIM_API USimHUDWidget : public UUserWidget
bool setPIPSegVisibility(bool is_viisble);
UFUNCTION(BlueprintImplementableEvent, Category = "C++ Interface")
bool getPIPSegVisibility();

UFUNCTION(BlueprintImplementableEvent, Category = "C++ Interface")
bool setRecordButtonVisibility(bool is_visible);
UFUNCTION(BlueprintImplementableEvent, Category = "C++ Interface")
bool getRecordButtonVisibility();
protected:
UFUNCTION(BlueprintImplementableEvent, Category = "C++ Interface")
bool setReportContainerVisibility(bool is_visible);
Expand Down
21 changes: 21 additions & 0 deletions Unreal/Plugins/AirSim/Source/SimMode/SimModeBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ void ASimModeBase::BeginPlay()
Settings& settings = Settings::singleton();
enable_rpc = settings.getBool("RpcEnabled", true);
api_server_address = settings.getString("LocalHostIp", "127.0.0.1");
is_record_ui_visible = settings.getBool("RecordUIVisible", true);

std::string view_mode_string = settings.getString("ViewMode", "FlyWithMe");
if (view_mode_string == "FlyWithMe")
initial_view_mode = ECameraDirectorMode::CAMERA_DIRECTOR_MODE_FLY_WITH_ME;
else if (view_mode_string == "Fpv")
initial_view_mode = ECameraDirectorMode::CAMERA_DIRECTOR_MODE_FPV;
else if (view_mode_string == "Manual")
initial_view_mode = ECameraDirectorMode::CAMERA_DIRECTOR_MODE_MANUAL;
else if (view_mode_string == "GroundObserver")
initial_view_mode = ECameraDirectorMode::CAMERA_DIRECTOR_MODE_GROUND_OBSERVER;

//do not save this default in json as this will change in near future
fpv_vehicle_name = settings.getString("FpvVehicleName", "Pixhawk");
Expand Down Expand Up @@ -70,6 +81,16 @@ bool ASimModeBase::isRecording()
return is_recording;
}

bool ASimModeBase::isRecordUIVisible()
{
return is_record_ui_visible;
}

ECameraDirectorMode ASimModeBase::getInitialViewMode()
{
return initial_view_mode;
}

void ASimModeBase::startRecording()
{
if (record_file.is_open()) {
Expand Down
5 changes: 5 additions & 0 deletions Unreal/Plugins/AirSim/Source/SimMode/SimModeBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,18 @@ class AIRSIM_API ASimModeBase : public AActor
virtual void startRecording();
virtual void stopRecording();
virtual bool isRecording();
virtual bool isRecordUIVisible();
virtual ECameraDirectorMode getInitialViewMode();

FString getRecordingPath();

std::ofstream record_file;
std::string record_filename = "airsim_rec";
protected:
virtual void setupInputBindings();
bool is_recording;
bool is_record_ui_visible;
ECameraDirectorMode initial_view_mode;
int record_tick_count;
bool enable_rpc;
std::string api_server_address;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void ASimModeWorldMultiRotor::setupVehiclesAndCamera()
}

CameraDirector->TargetPawn->initializeForBeginPlay();
CameraDirector->initializeForBeginPlay();
CameraDirector->initializeForBeginPlay(getInitialViewMode());
}

void ASimModeWorldMultiRotor::Tick(float DeltaSeconds)
Expand Down

0 comments on commit ee11a23

Please sign in to comment.