Skip to content

Commit

Permalink
fix several compile errors due to IWYU mode in UE 4.18
Browse files Browse the repository at this point in the history
  • Loading branch information
sytelus committed Apr 29, 2018
1 parent a085125 commit 7bddd58
Show file tree
Hide file tree
Showing 20 changed files with 268 additions and 254 deletions.
205 changes: 23 additions & 182 deletions Unreal/Plugins/AirSim/Source/AirBlueprintLib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@
#include "GameFramework/WorldSettings.h"
#include "Components/SceneCaptureComponent2D.h"
#include "Components/SkinnedMeshComponent.h"
#include "Kismet/GameplayStatics.h"
#include "GameFramework/RotatingMovementComponent.h"
#include <exception>
#include "common/common_utils/Utils.hpp"
#include "Components/StaticMeshComponent.h"
#include "EngineUtils.h"
#include "Runtime/Landscape/Classes/LandscapeComponent.h"
#include "Runtime/Engine/Classes/Engine/StaticMesh.h"
#include "UObjectIterator.h"
#include "Camera/CameraComponent.h"
//#include "Runtime/Foliage/Public/FoliageType.h"
#include "Kismet/KismetStringLibrary.h"
#include "MessageDialog.h"
Expand All @@ -23,6 +20,8 @@
#include "IImageWrapper.h"
#include "ObjectThumbnail.h"
#include "Engine/Engine.h"
#include <exception>
#include "common/common_utils/Utils.hpp"

/*
//TODO: change naming conventions to same as other files?
Expand Down Expand Up @@ -140,7 +139,7 @@ void UAirBlueprintLib::enableViewportRendering(AActor* context, bool enable)
void UAirBlueprintLib::OnBeginPlay()
{
flush_on_draw_count_ = 0;
image_wrapper_module_ = & FModuleManager::LoadModuleChecked<IImageWrapperModule>(FName("ImageWrapper"));
image_wrapper_module_ = &FModuleManager::LoadModuleChecked<IImageWrapperModule>(FName("ImageWrapper"));
}

void UAirBlueprintLib::OnEndPlay()
Expand Down Expand Up @@ -171,19 +170,19 @@ void UAirBlueprintLib::LogMessage(const FString &prefix, const FString &suffix,

FColor color;
switch (level) {
case LogDebugLevel::Informational:
color = FColor(147, 231, 237);
case LogDebugLevel::Informational:
color = FColor(147, 231, 237);
//UE_LOG(LogAirSim, Log, TEXT("%s%s"), *prefix, *suffix);
break;
case LogDebugLevel::Success:
color = FColor(156, 237, 147);
case LogDebugLevel::Success:
color = FColor(156, 237, 147);
//UE_LOG(LogAirSim, Log, TEXT("%s%s"), *prefix, *suffix);
break;
case LogDebugLevel::Failure:
case LogDebugLevel::Failure:
color = FColor(237, 147, 168);
//UE_LOG(LogAirSim, Error, TEXT("%s%s"), *prefix, *suffix);
break;
case LogDebugLevel::Unimportant:
case LogDebugLevel::Unimportant:
color = FColor(237, 228, 147);
//UE_LOG(LogAirSim, Verbose, TEXT("%s%s"), *prefix, *suffix);
break;
Expand Down Expand Up @@ -234,23 +233,7 @@ template UChildActorComponent* UAirBlueprintLib::GetActorComponent(AActor*, FStr
template USceneCaptureComponent2D* UAirBlueprintLib::GetActorComponent(AActor*, FString);
template UStaticMeshComponent* UAirBlueprintLib::GetActorComponent(AActor*, FString);
template URotatingMovementComponent* UAirBlueprintLib::GetActorComponent(AActor*, FString);

template<typename T>
T* UAirBlueprintLib::FindActor(const UObject* context, FString name)
{
TArray<AActor*> foundActors;
FindAllActor<T>(context, foundActors);
FName name_n = FName(*name);

for (AActor* actor : foundActors) {
if (actor->ActorHasTag(name_n) || actor->GetName().Compare(name) == 0) {
return static_cast<T*>(actor);
}
}

//UAirBlueprintLib::LogMessage(name + TEXT(" Actor not found!"), TEXT(""), LogDebugLevel::Failure);
return nullptr;
}
template UCameraComponent* UAirBlueprintLib::GetActorComponent(AActor*, FString);

bool UAirBlueprintLib::IsInGameThread()
{
Expand All @@ -268,119 +251,26 @@ void UAirBlueprintLib::RunCommandOnGameThread(TFunction<void()> InFunction, bool
}
}


template<typename T>
void UAirBlueprintLib::FindAllActor(const UObject* context, TArray<AActor*>& foundActors)
{
UGameplayStatics::GetAllActorsOfClass(context == nullptr ? GEngine : context, T::StaticClass(), foundActors);
}

template<typename T>
void UAirBlueprintLib::InitializeObjectStencilID(T* mesh, bool ignore_existing)
{
std::string mesh_name = common_utils::Utils::toLower(GetMeshName(mesh));
if (mesh_name == "" || common_utils::Utils::startsWith(mesh_name, "default_")) {
//common_utils::Utils::DebugBreak();
return;
}
FString name(mesh_name.c_str());
int hash = 5;
for (int idx = 0; idx < name.Len(); ++idx) {
auto char_num = UKismetStringLibrary::GetCharacterAsNumber(name, idx);
if (char_num < 97)
continue; //numerics and other punctuations
hash += char_num;
}
if (ignore_existing || mesh->CustomDepthStencilValue == 0) { //if value is already set then don't bother
SetObjectStencilID(mesh, hash % 256);
}
}

template<typename T>
void UAirBlueprintLib::SetObjectStencilID(T* mesh, int object_id)
{
if (object_id < 0)
{
mesh->SetRenderCustomDepth(false);
}
else
{
mesh->SetCustomDepthStencilValue(object_id);
mesh->SetRenderCustomDepth(true);
}
//mesh->SetVisibility(false);
//mesh->SetVisibility(true);
}

void UAirBlueprintLib::SetObjectStencilID(ALandscapeProxy* mesh, int object_id)
{
if (object_id < 0)
{
mesh->bRenderCustomDepth = false;
}
else
{
mesh->CustomDepthStencilValue = object_id;
mesh->bRenderCustomDepth = true;
}

// Explicitly set the custom depth state on the components so the
// render state is marked dirty and the update actually takes effect
// immediately.
for (ULandscapeComponent* comp : mesh->LandscapeComponents)
{
if (object_id < 0)
{
comp->SetRenderCustomDepth(false);
}
else
{
comp->SetCustomDepthStencilValue(object_id);
comp->SetRenderCustomDepth(true);
}
}
}

template<class T>
std::string UAirBlueprintLib::GetMeshName(T* mesh)
template<>
std::string UAirBlueprintLib::GetMeshName<USkinnedMeshComponent>(USkinnedMeshComponent* mesh)
{
switch(mesh_naming_method_)
switch (mesh_naming_method_)
{
case msr::airlib::AirSimSettings::SegmentationSettings::MeshNamingMethodType::OwnerName:
if (mesh->GetOwner())
return std::string(TCHAR_TO_UTF8(*(mesh->GetOwner()->GetName())));
else
return ""; // std::string(TCHAR_TO_UTF8(*(UKismetSystemLibrary::GetDisplayName(mesh))));
case msr::airlib::AirSimSettings::SegmentationSettings::MeshNamingMethodType::StaticMeshName:
if (mesh->GetStaticMesh())
return std::string(TCHAR_TO_UTF8(*(mesh->GetStaticMesh()->GetName())));
if (mesh->SkeletalMesh)
return std::string(TCHAR_TO_UTF8(*(mesh->SkeletalMesh->GetName())));
else
return "";
default:
return "";
}
}

template<>
std::string UAirBlueprintLib::GetMeshName<USkinnedMeshComponent>(USkinnedMeshComponent* mesh)
{
switch(mesh_naming_method_)
{
case msr::airlib::AirSimSettings::SegmentationSettings::MeshNamingMethodType::OwnerName:
if (mesh->GetOwner())
return std::string(TCHAR_TO_UTF8(*(mesh->GetOwner()->GetName())));
else
return ""; // std::string(TCHAR_TO_UTF8(*(UKismetSystemLibrary::GetDisplayName(mesh))));
case msr::airlib::AirSimSettings::SegmentationSettings::MeshNamingMethodType::StaticMeshName:
if (mesh->SkeletalMesh)
return std::string(TCHAR_TO_UTF8(*(mesh->SkeletalMesh->GetName())));
else
return "";
default:
return "";
}
}


std::string UAirBlueprintLib::GetMeshName(ALandscapeProxy* mesh)
{
Expand All @@ -407,20 +297,6 @@ void UAirBlueprintLib::InitializeMeshStencilIDs(bool ignore_existing)
}
}

template<typename T>
void UAirBlueprintLib::SetObjectStencilIDIfMatch(T* mesh, int object_id, const std::string& mesh_name, bool is_name_regex,
const std::regex& name_regex, int& changes)
{
std::string comp_mesh_name = GetMeshName(mesh);
if (comp_mesh_name == "")
return;
bool is_match = (!is_name_regex && (comp_mesh_name == mesh_name))
|| (is_name_regex && std::regex_match(comp_mesh_name, name_regex));
if (is_match) {
++changes;
SetObjectStencilID(mesh, object_id);
}
}
bool UAirBlueprintLib::SetMeshStencilID(const std::string& mesh_name, int object_id,
bool is_name_regex)
{
Expand Down Expand Up @@ -461,7 +337,7 @@ int UAirBlueprintLib::GetMeshStencilID(const std::string& mesh_name)
return -1;
}

bool UAirBlueprintLib::HasObstacle(const AActor* actor, const FVector& start, const FVector& end, const AActor* ignore_actor, ECollisionChannel collision_channel)
bool UAirBlueprintLib::HasObstacle(const AActor* actor, const FVector& start, const FVector& end, const AActor* ignore_actor, ECollisionChannel collision_channel)
{
FCollisionQueryParams trace_params;
trace_params.AddIgnoredActor(actor);
Expand All @@ -471,8 +347,8 @@ bool UAirBlueprintLib::HasObstacle(const AActor* actor, const FVector& start, co
return actor->GetWorld()->LineTraceTestByChannel(start, end, collision_channel, trace_params);
}

bool UAirBlueprintLib::GetObstacle(const AActor* actor, const FVector& start, const FVector& end,
FHitResult& hit, const AActor* ignore_actor, ECollisionChannel collision_channel)
bool UAirBlueprintLib::GetObstacle(const AActor* actor, const FVector& start, const FVector& end,
FHitResult& hit, const AActor* ignore_actor, ECollisionChannel collision_channel)
{
hit = FHitResult(ForceInit);

Expand All @@ -484,8 +360,8 @@ bool UAirBlueprintLib::GetObstacle(const AActor* actor, const FVector& start, co
return actor->GetWorld()->LineTraceSingleByChannel(hit, start, end, collision_channel, trace_params);
}

bool UAirBlueprintLib::GetLastObstaclePosition(const AActor* actor, const FVector& start, const FVector& end,
FHitResult& hit, const AActor* ignore_actor, ECollisionChannel collision_channel)
bool UAirBlueprintLib::GetLastObstaclePosition(const AActor* actor, const FVector& start, const FVector& end,
FHitResult& hit, const AActor* ignore_actor, ECollisionChannel collision_channel)
{
TArray<FHitResult> hits;

Expand Down Expand Up @@ -536,47 +412,12 @@ void UAirBlueprintLib::FollowActor(AActor* follower, const AActor* followee, con
follower->SetActorRotation(next_rot);
}

template<class UserClass>
FInputActionBinding& UAirBlueprintLib::BindActionToKey(const FName action_name, const FKey in_key, UserClass* actor,
typename FInputActionHandlerSignature::TUObjectMethodDelegate<UserClass>::FMethodPtr func, bool on_press_or_release,
bool shift_key, bool control_key, bool alt_key, bool command_key)
{
FInputActionKeyMapping action(action_name, in_key, shift_key, control_key, alt_key, command_key);

APlayerController* controller = actor->GetWorld()->GetFirstPlayerController();

controller->PlayerInput->AddActionMapping(action);
return controller->InputComponent->
BindAction(action_name, on_press_or_release ? IE_Pressed : IE_Released, actor, func);
}


template<class UserClass>
FInputAxisBinding& UAirBlueprintLib::BindAxisToKey(const FName axis_name, const FKey in_key, AActor* actor, UserClass* obj,
typename FInputAxisHandlerSignature::TUObjectMethodDelegate<UserClass>::FMethodPtr func)
{
FInputAxisKeyMapping axis(axis_name, in_key);

return UAirBlueprintLib::BindAxisToKey(axis, actor, obj, func);
}

template<class UserClass>
FInputAxisBinding& UAirBlueprintLib::BindAxisToKey(const FInputAxisKeyMapping& axis, AActor* actor, UserClass* obj,
typename FInputAxisHandlerSignature::TUObjectMethodDelegate<UserClass>::FMethodPtr func)
{
APlayerController* controller = actor->GetWorld()->GetFirstPlayerController();

controller->PlayerInput->AddAxisMapping(axis);
return controller->InputComponent->
BindAxis(axis.AxisName, obj, func);
}


int UAirBlueprintLib::RemoveAxisBinding(const FInputAxisKeyMapping& axis, FInputAxisBinding* axis_binding, AActor* actor)
{
if (axis_binding != nullptr && actor != nullptr) {
APlayerController* controller = actor->GetWorld()->GetFirstPlayerController();

//remove mapping
int found_mapping_index = -1, cur_mapping_index = -1;
for (const auto& axis_arr : controller->PlayerInput->AxisMappings) {
Expand All @@ -600,7 +441,7 @@ int UAirBlueprintLib::RemoveAxisBinding(const FInputAxisKeyMapping& axis, FInput
}
if (found_binding_index >= 0)
controller->InputComponent->AxisBindings.RemoveAt(found_binding_index);

return found_binding_index;
}
else return -1;
Expand Down
Loading

0 comments on commit 7bddd58

Please sign in to comment.