Skip to content

Commit

Permalink
Fix build warnings for 4.18, add a build script to test compatibility.
Browse files Browse the repository at this point in the history
  • Loading branch information
qiuwch committed Nov 22, 2017
1 parent ff6f2c0 commit a956105
Show file tree
Hide file tree
Showing 9 changed files with 165 additions and 57 deletions.
4 changes: 2 additions & 2 deletions Source/UnrealCV/Private/Commands/PluginHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ FExecStatus FPluginCommandHandler::GetUnrealCVStatus(const TArray<FString>& Args
{
FString Msg;
FUE4CVServer& Server = FUE4CVServer::Get(); // TODO: Can not use a copy constructor, need to disable copy constructor

if (Server.NetworkManager->IsListening())
{
Msg += "Is Listening\n";
Expand Down Expand Up @@ -109,6 +109,6 @@ FExecStatus FPluginCommandHandler::GetVersion(const TArray<FString>& Args)

FExecStatus FPluginCommandHandler::GetSceneName(const TArray<FString>& Args)
{
FString SceneName = FApp::GetGameName();
FString SceneName = GetProjectName();
return FExecStatus::OK(SceneName);
}
2 changes: 1 addition & 1 deletion Source/UnrealCV/Private/GTCaptureComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ TArray<uint8> UGTCaptureComponent::CapturePng(FString Mode)

UTextureRenderTarget2D* RenderTarget = CaptureComponent->TextureTarget;
static IImageWrapperModule& ImageWrapperModule = FModuleManager::LoadModuleChecked<IImageWrapperModule>(FName("ImageWrapper"));
static IImageWrapperPtr ImageWrapper = ImageWrapperModule.CreateImageWrapper(EImageFormat::PNG);
static TSharedPtr<IImageWrapper> ImageWrapper = ImageWrapperModule.CreateImageWrapper(EImageFormat::PNG);
int32 Width = RenderTarget->SizeX, Height = RenderTarget->SizeY;
TArray<FColor> Image;
FTextureRenderTargetResource* RenderTargetResource;
Expand Down
2 changes: 1 addition & 1 deletion Source/UnrealCV/Private/ScreenCapture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ bool CaptureWithSync(UGameViewportClient *ViewportClient, const FString& Capture
InViewport->ReadFloat16Pixels(FloatBitmap);

IImageWrapperModule& ImageWrapperModule = FModuleManager::LoadModuleChecked<IImageWrapperModule>(FName("ImageWrapper"));
IImageWrapperPtr ImageWrapper = ImageWrapperModule.CreateImageWrapper(EImageFormat::EXR);
TSharedPtr<IImageWrapper> ImageWrapper = ImageWrapperModule.CreateImageWrapper(EImageFormat::EXR);

ImageWrapper->SetRaw(FloatBitmap.GetData(), FloatBitmap.GetAllocatedSize(), Size.X, Size.Y, ERGBFormat::RGBA, 16);
const TArray<uint8>& PngData = ImageWrapper->GetCompressed();
Expand Down
4 changes: 2 additions & 2 deletions Source/UnrealCV/Private/Serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ TArray<uint8> SerializationUtils::Image2Png(const TArray<FColor>& Image, int Wid
return TArray<uint8>();
}
static IImageWrapperModule& ImageWrapperModule = FModuleManager::LoadModuleChecked<IImageWrapperModule>(FName("ImageWrapper"));
static IImageWrapperPtr ImageWrapper = ImageWrapperModule.CreateImageWrapper(EImageFormat::PNG);
static TSharedPtr<IImageWrapper> ImageWrapper = ImageWrapperModule.CreateImageWrapper(EImageFormat::PNG);
ImageWrapper->SetRaw(Image.GetData(), Image.GetAllocatedSize(), Width, Height, ERGBFormat::BGRA, 8);
const TArray<uint8>& ImgData = ImageWrapper->GetCompressed();
return ImgData;
Expand All @@ -84,7 +84,7 @@ TArray<uint8> SerializationUtils::Image2Exr(const TArray<FFloat16Color>& FloatIm
return TArray<uint8>();
}
static IImageWrapperModule& ImageWrapperModule = FModuleManager::LoadModuleChecked<IImageWrapperModule>(FName("ImageWrapper"));
static IImageWrapperPtr ImageWrapper = ImageWrapperModule.CreateImageWrapper(EImageFormat::EXR);
static TSharedPtr<IImageWrapper> ImageWrapper = ImageWrapperModule.CreateImageWrapper(EImageFormat::EXR);
ImageWrapper->SetRaw(FloatImage.GetData(), FloatImage.GetAllocatedSize(), Width, Height, ERGBFormat::RGBA, 16);
const TArray<uint8>& ExrData = ImageWrapper->GetCompressed();
return ExrData;
Expand Down
6 changes: 3 additions & 3 deletions Source/UnrealCV/Private/TcpServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ bool FSocketMessageHeader::WrapAndSendPayload(const TArray<uint8>& Payload, FSoc
// GetData returns a uint8 pointer
Socket->Send(Ar.GetData() + TotalAmountSent, Ar.Num() - TotalAmountSent, AmountSent);
NumTrial--;

if (AmountSent == -1)
{
continue;
Expand All @@ -35,7 +35,7 @@ bool FSocketMessageHeader::WrapAndSendPayload(const TArray<uint8>& Payload, FSoc
UE_LOG(LogUnrealCV, Error, TEXT("Unable to send. Expect to send %d, sent %d"), Ar.Num(), TotalAmountSent);
return false;
}

UE_LOG(LogUnrealCV, Verbose, TEXT("Sending bytes %d/%d, sent %d"), TotalAmountSent, Ar.Num(), AmountSent);
AmountToSend -= AmountSent;
TotalAmountSent += AmountSent;
Expand Down Expand Up @@ -223,7 +223,7 @@ bool UNetworkManager::StartMessageService(FSocket* ClientSocket, const FIPv4Endp

UE_LOG(LogUnrealCV, Warning, TEXT("New client connected from %s"), *ClientEndpoint.ToString());
// ClientSocket->SetNonBlocking(false); // When this in blocking state, I can not use this socket to send message back
FString Confirm = FString::Printf(TEXT("connected to %s"), FApp::GetGameName());
FString Confirm = FString::Printf(TEXT("connected to %s"), *GetProjectName());
bool IsSent = this->SendMessage(Confirm); // Send a hello message
if (!IsSent)
{
Expand Down
13 changes: 13 additions & 0 deletions Source/UnrealCV/Public/UnrealCVPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,20 @@
*/
// Precompiled header file for UnrealCV
#include "Engine.h"
#include "Version.h"

DECLARE_STATS_GROUP(TEXT("UnrealCV"), STATGROUP_UnrealCV, STATCAT_Advanced);

DECLARE_LOG_CATEGORY_EXTERN(LogUnrealCV, Log, All);

inline FString GetProjectName()
{
#if ENGINE_MINOR_VERSION >= 18 // Assume major version is 4
FString SceneName = FApp::GetProjectName();
#else
FString SceneName = FApp::GetGameName();
// This is marked as deprecated in 4.18
// https://github.com/EpicGames/UnrealEngine/blob/release/Engine/Source/Runtime/Core/Public/Misc/App.h:L91
#endif
return SceneName;
}
141 changes: 94 additions & 47 deletions Source/UnrealCV/UnrealCV.Build.cs
Original file line number Diff line number Diff line change
@@ -1,69 +1,116 @@
// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
using System.IO;
using System.Collections.Generic;

// An engine version independent configuration class
public class UnrealcvBuildConfig
{
public List<string> PrivateIncludePaths = new List<string>();
public List<string> PublicIncludePaths = new List<string>();
public List<string> PublicDependencyModuleNames = new List<string>();
public List<string> EditorPrivateDependencyModuleNames = new List<string>();
public List<string> DynamicallyLoadedModuleNames = new List<string>();

public UnrealcvBuildConfig(string EnginePath)
{
PublicIncludePaths.AddRange(
new string[]
{
EnginePath + "Source/Runtime/Launch/Resources",
// To get Unreal Engine minor version
}
);

PrivateIncludePaths.AddRange(
new string[] {
"UnrealCV/Private/Commands",
"UnrealCV/Private/libs", // For 3rd-party libs
}
);

PublicDependencyModuleNames.AddRange(new string[] {
"Core",
"CoreUObject",
"Engine",
"InputCore",
"RenderCore",
"Networking",
"Sockets",
"Slate",
"ImageWrapper",
"CinematicCamera",
"Projects", // Support IPluginManager
});

EditorPrivateDependencyModuleNames.AddRange(
new string[]
{
"UnrealEd", // To support GetGameWorld
// This is only available for Editor build
}
);

DynamicallyLoadedModuleNames.AddRange(
new string[]
{
"Renderer"
}
);
}
}

#if WITH_FORWARDED_MODULE_RULES_CTOR
namespace UnrealBuildTool.Rules
{
public class UnrealCV: ModuleRules
{
#if WITH_FORWARDED_MODULE_RULES_CTOR
// ReadOnlyTargetRules for version > 4.15
public UnrealCV(ReadOnlyTargetRules Target) : base(Target)
// 4.16 or better
{
bEnforceIWYU = false;
#else
public UnrealCV(TargetInfo Target) //4.15 or lower
{
#endif
// This trick is from https://answers.unrealengine.com/questions/258689/how-to-include-private-header-files-of-other-modul.html
string EnginePath = Path.GetFullPath(BuildConfiguration.RelativeEnginePath);

PublicIncludePaths.AddRange(
new string[]
{
EnginePath + "Source/Runtime/Launch/Resources",
// To get Unreal Engine minor version
}
);

PrivateIncludePaths.AddRange(
new string[] {
"UnrealCV/Private/Commands",
"UnrealCV/Private/libs", // For 3rd-party libs
}
);
// This trick is from https://answers.unrealengine.com/questions/258689/how-to-include-private-header-files-of-other-modul.html
// string EnginePath = Path.GetFullPath(BuildConfigurationTarget.RelativeEnginePath);
string EnginePath = Path.GetFullPath(Target.RelativeEnginePath);
UnrealcvBuildConfig BuildConfig = new UnrealcvBuildConfig(EnginePath);

PublicDependencyModuleNames.AddRange(new string[] {
"Core",
"CoreUObject",
"Engine",
"InputCore",
"RenderCore",
"Networking",
"Sockets",
"Slate",
"ImageWrapper",
"CinematicCamera",
"Projects", // Support IPluginManager
});
PublicIncludePaths = BuildConfig.PublicIncludePaths;
PrivateIncludePaths = BuildConfig.PrivateIncludePaths;
PublicDependencyModuleNames = BuildConfig.PublicDependencyModuleNames;
DynamicallyLoadedModuleNames = BuildConfig.DynamicallyLoadedModuleNames;

// PrivateDependency only available in Private folder
// Reference: https://answers.unrealengine.com/questions/23384/what-is-the-difference-between-publicdependencymod.html
if (UEBuildConfiguration.bBuildEditor == true)
// if (UEBuildConfiguration.bBuildEditor == true)
if (Target.bBuildEditor == true)
{
PrivateDependencyModuleNames.AddRange(
new string[]
{
"UnrealEd", // To support GetGameWorld
}
);
PrivateDependencyModuleNames = BuildConfig.EditorPrivateDependencyModuleNames;
}
}
}
}

#else //4.15 or lower, for backward compatibility
namespace UnrealBuildTool.Rules
{
public class UnrealCV: ModuleRules
{
public UnrealCV(TargetInfo Target)
{
string EnginePath = Path.GetFullPath(BuildConfiguration.RelativeEnginePath);
UnrealcvBuildConfig BuildConfig = new UnrealcvBuildConfig(EnginePath);

DynamicallyLoadedModuleNames.AddRange(
new string[]
{
"Renderer"
}
);
PublicIncludePaths = BuildConfig.PublicIncludePaths;
PrivateIncludePaths = BuildConfig.PrivateIncludePaths;
PublicDependencyModuleNames = BuildConfig.PublicDependencyModuleNames;
DynamicallyLoadedModuleNames = BuildConfig.DynamicallyLoadedModuleNames;

if (UEBuildConfiguration.bBuildEditor == true)
{
PrivateDependencyModuleNames = BuildConfig.EditorPrivateDependencyModuleNames;
}
}
}
}
#endif
7 changes: 6 additions & 1 deletion build.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ def main():
'--UE4',
help='Specify the engine path. If left empty, default installation locations will be used'
)
parser.add_argument(
'--overwrite',
type=bool,
help='Whether to overwrite the compiled binary'
)

args = parser.parse_args()
need_install = args.install
Expand All @@ -45,7 +50,7 @@ def main():
output_folder = 'Plugins/UnrealCV'
abs_output_folder = os.path.abspath(output_folder)

ue4.build_plugin(abs_descriptor_file, abs_output_folder)
ue4.build_plugin(abs_descriptor_file, abs_output_folder, args.overwrite)

# Install the plugin if requested
if need_install:
Expand Down
43 changes: 43 additions & 0 deletions test/ue4_version_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Build UnrealCV against different UE4 version to check compatibility
import subprocess, os, sys

def format_cmd(UE4, output_folder):
cmd = [
'python',
'build.py',
'--UE4',
UE4,
'--output',
output_folder,
]
return cmd

UE414 = [r'C:\Program Files\Epic Games\UE_4.14', r'C:/temp/unrealcv_built/414', 'log/UE414.log']
UE416 = [r'C:\Program Files\Epic Games\UE_4.16', r'C:/temp/unrealcv_built/416', 'log/UE416.log']
UE418 = [r'C:\Program Files\Epic Games\UE_4.18', r'C:/temp/unrealcv_built/418', 'log/UE418.log']
# Send the output to C:/temp to avoid cluttering current directory, which might cause failure to the build.

ue_versions = [UE414, UE416, UE418]

if not os.path.isdir('log'):
os.mkdir('log')

for ue4 in ue_versions:
print('-' * 80)
print('Run configuration', ue4)
log_filename = ue4[2]
if os.path.isfile(log_filename):
print('Skip because log exists')
continue
cmd = format_cmd(ue4[0], ue4[1])

logfile = open(log_filename, 'wb')
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
for line in proc.stdout:
sys.stdout.buffer.write(line)
sys.stdout.flush()
# see, https://stackoverflow.com/questions/908331/how-to-write-binary-data-in-stdout-in-python-3
logfile.write(line)
proc.wait()
# with open(log_filename, 'w') as f:
# subprocess.call(cmd, stdout = f, stderr = f)

0 comments on commit a956105

Please sign in to comment.