4.17 fix (update OscDemo files)

This commit is contained in:
monsieurgustav
2017-10-04 15:22:43 +02:00
parent 3c8a3d0127
commit 2ac73a0e48
18 changed files with 150 additions and 75 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"FileVersion": 3, "FileVersion": 3,
"EngineAssociation": "4.11", "EngineAssociation": "4.17",
"Category": "", "Category": "",
"Description": "", "Description": "",
"Modules": [ "Modules": [
+1 -2
View File
@@ -6,10 +6,9 @@
"VersionName" : "1.0", "VersionName" : "1.0",
"CreatedBy" : "Guillaume Buisson", "CreatedBy" : "Guillaume Buisson",
"CreatedByURL" : "http://guillaume.io", "CreatedByURL" : "http://guillaume.io",
"EngineVersion" : "4.4.0",
"Description" : "", "Description" : "",
"Category" : "OSC", "Category" : "OSC",
"EnabledByDefault" : false, "EnabledByDefault" : true,
"Modules" : "Modules" :
[ [
@@ -2,8 +2,8 @@ namespace UnrealBuildTool.Rules
{ {
public class OSC : ModuleRules public class OSC : ModuleRules
{ {
public OSC(TargetInfo Target) public OSC(ReadOnlyTargetRules Target) : base(Target)
{ {
PublicDependencyModuleNames.AddRange( PublicDependencyModuleNames.AddRange(
new string[] new string[]
{ {
@@ -38,7 +38,7 @@ namespace UnrealBuildTool.Rules
} }
); );
if (Target.Type.HasValue && TargetRules.IsEditorType(Target.Type.Value)) if (Target.Type == TargetRules.TargetType.Editor)
{ {
Definitions.Add("OSC_EDITOR_BUILD=1"); Definitions.Add("OSC_EDITOR_BUILD=1");
@@ -8,24 +8,20 @@ struct FOscDataElemStruct
{ {
GENERATED_USTRUCT_BODY() GENERATED_USTRUCT_BODY()
UPROPERTY()
int32 Type;
UPROPERTY()
int64 Data;
FOscDataElemStruct() : Type(0), Data(0)
{ }
enum enum
{ {
FLOAT = 0, FLOAT = 0,
INT = 1, INT = 1,
BOOL = 2, BOOL = 2,
STRING = 3, STRING = 3,
BLOB = 4,
}; };
//------------------------------------------------------------------------- public:
FOscDataElemStruct() : Type(0), Data(0)
{
}
void SetFloat(double value) void SetFloat(double value)
{ {
@@ -112,6 +108,27 @@ struct FOscDataElemStruct
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
void SetBlob(TArray<uint8> value)
{
Data = 0;
Type = BLOB;
Blob = MakeShared<TArray<uint8>>(std::move(value));
}
const TArray<uint8> & AsBlobValue() const
{
check(IsBlob());
static const TArray<uint8> empty;
return Blob.IsValid() ? *Blob : empty;
}
bool IsBlob() const
{
return Type == BLOB;
}
//-------------------------------------------------------------------------
/// Cast the value to T. /// Cast the value to T.
template <class T> template <class T>
T GetValue() const T GetValue() const
@@ -150,6 +167,14 @@ struct FOscDataElemStruct
return Cast<T, isString>::eval(value); return Cast<T, isString>::eval(value);
} }
} }
else if(IsBlob())
{
const bool isBlob = std::is_same<T, TArray<uint8>>::value;
if(isBlob)
{
return Cast<T, isBlob>::eval(AsBlobValue());
}
}
return T(); return T();
} }
@@ -163,6 +188,13 @@ private:
return T(); return T();
} }
}; };
private:
int32 Type;
int64 Data;
TSharedPtr<TArray<uint8>> Blob;
}; };
@@ -44,6 +44,11 @@ void UOscFunctionLibrary::PopString(const TArray<FOscDataElemStruct> & input, TA
PopValueImpl(input, output, Value); PopValueImpl(input, output, Value);
} }
void UOscFunctionLibrary::PopBlob(const TArray<FOscDataElemStruct> & input, TArray<FOscDataElemStruct> & output, TArray<uint8> & Value)
{
PopValueImpl(input, output, Value);
}
void UOscFunctionLibrary::PushBool(const TArray<FOscDataElemStruct> & input, bool Value, TArray<FOscDataElemStruct> & output) void UOscFunctionLibrary::PushBool(const TArray<FOscDataElemStruct> & input, bool Value, TArray<FOscDataElemStruct> & output)
{ {
@@ -84,6 +89,14 @@ void UOscFunctionLibrary::PushString(const TArray<FOscDataElemStruct> & input, F
output.Add(elem); output.Add(elem);
} }
void UOscFunctionLibrary::PushBlob(const TArray<FOscDataElemStruct> & input, const TArray<uint8> & Value, TArray<FOscDataElemStruct> & output)
{
output = input;
FOscDataElemStruct elem;
elem.SetBlob(Value);
output.Add(elem);
}
bool UOscFunctionLibrary::AsBool(const FOscDataElemStruct & input) bool UOscFunctionLibrary::AsBool(const FOscDataElemStruct & input)
{ {
@@ -105,6 +118,11 @@ FName UOscFunctionLibrary::AsString(const FOscDataElemStruct & input)
return input.GetValue<FName>(); return input.GetValue<FName>();
} }
TArray<uint8> UOscFunctionLibrary::AsBlob(const FOscDataElemStruct & input)
{
return input.GetValue<TArray<uint8>>();
}
FOscDataElemStruct UOscFunctionLibrary::FromBool(bool input) FOscDataElemStruct UOscFunctionLibrary::FromBool(bool input)
{ {
@@ -134,6 +152,13 @@ FOscDataElemStruct UOscFunctionLibrary::FromString(FName input)
return result; return result;
} }
FOscDataElemStruct UOscFunctionLibrary::FromBlob(const TArray<uint8> & input)
{
FOscDataElemStruct result;
result.SetBlob(input);
return result;
}
namespace namespace
{ {
@@ -188,6 +213,11 @@ namespace
{ {
output << elem.AsStringValue().GetPlainANSIString(); output << elem.AsStringValue().GetPlainANSIString();
} }
else if(elem.IsBlob())
{
const TArray<uint8> & value = elem.AsBlobValue();
output << osc::Blob(value.GetData(), value.Num());
}
if(output.State() != osc::SUCCESS) if(output.State() != osc::SUCCESS)
{ {
@@ -28,6 +28,10 @@ public:
UFUNCTION(BlueprintPure, Category=OSC) UFUNCTION(BlueprintPure, Category=OSC)
static void PopString(const TArray<FOscDataElemStruct> & input, TArray<FOscDataElemStruct> & output, FName & Value); static void PopString(const TArray<FOscDataElemStruct> & input, TArray<FOscDataElemStruct> & output, FName & Value);
/// Get the next value from an OSC message as a blob.
UFUNCTION(BlueprintPure, Category=OSC)
static void PopBlob(const TArray<FOscDataElemStruct> & input, TArray<FOscDataElemStruct> & output, TArray<uint8> & Value);
/// Add a boolean value to an OSC message. /// Add a boolean value to an OSC message.
UFUNCTION(BlueprintPure, Category=OSC, meta=(AutoCreateRefTerm = "input")) UFUNCTION(BlueprintPure, Category=OSC, meta=(AutoCreateRefTerm = "input"))
@@ -45,6 +49,10 @@ public:
UFUNCTION(BlueprintPure, Category=OSC, meta=(AutoCreateRefTerm = "input")) UFUNCTION(BlueprintPure, Category=OSC, meta=(AutoCreateRefTerm = "input"))
static void PushString(const TArray<FOscDataElemStruct> & input, FName Value, TArray<FOscDataElemStruct> & output); static void PushString(const TArray<FOscDataElemStruct> & input, FName Value, TArray<FOscDataElemStruct> & output);
/// Add a blob to an OSC message.
UFUNCTION(BlueprintPure, Category=OSC, meta=(AutoCreateRefTerm = "input"))
static void PushBlob(const TArray<FOscDataElemStruct> & input, const TArray<uint8> & Value, TArray<FOscDataElemStruct> & output);
/// Interpret an OSC argument as a boolean /// Interpret an OSC argument as a boolean
UFUNCTION(BlueprintPure, Category=OSC) UFUNCTION(BlueprintPure, Category=OSC)
@@ -62,6 +70,10 @@ public:
UFUNCTION(BlueprintPure, Category=OSC) UFUNCTION(BlueprintPure, Category=OSC)
static FName AsString(const FOscDataElemStruct & input); static FName AsString(const FOscDataElemStruct & input);
/// Interpret an OSC argument as a blob.
UFUNCTION(BlueprintPure, Category=OSC)
static TArray<uint8> AsBlob(const FOscDataElemStruct & input);
/// Create an OSC argument from a boolean /// Create an OSC argument from a boolean
UFUNCTION(BlueprintPure, Category=OSC) UFUNCTION(BlueprintPure, Category=OSC)
@@ -79,6 +91,10 @@ public:
UFUNCTION(BlueprintPure, Category=OSC) UFUNCTION(BlueprintPure, Category=OSC)
static FOscDataElemStruct FromString(FName input); static FOscDataElemStruct FromString(FName input);
/// Create an OSC argument from a blob.
UFUNCTION(BlueprintPure, Category=OSC)
static FOscDataElemStruct FromBlob(const TArray<uint8> & input);
/** /**
* @brief Send an OSC message. * @brief Send an OSC message.
@@ -148,13 +148,6 @@ static void FromUInt64( char *p, uint64 x )
} }
// round up to the next highest multiple of 4. unless x is already a multiple of 4
static inline std::size_t RoundUp4( std::size_t x )
{
return (x + 3) & ~((std::size_t)0x03);
}
OutboundPacketStream::OutboundPacketStream( char *buffer, std::size_t capacity ) OutboundPacketStream::OutboundPacketStream( char *buffer, std::size_t capacity )
: data_( buffer ) : data_( buffer )
, end_( data_ + capacity ) , end_( data_ + capacity )
@@ -86,13 +86,6 @@ static inline const char* FindStr4End( const char *p, const char *end )
} }
// round up to the next highest multiple of 4. unless x is already a multiple of 4
static inline uint32 RoundUp4( uint32 x )
{
return (x + 3) & ~((uint32)0x03);
}
static inline int32 ToInt32( const char *p ) static inline int32 ToInt32( const char *p )
{ {
#ifdef OSC_HOST_LITTLE_ENDIAN #ifdef OSC_HOST_LITTLE_ENDIAN
@@ -110,6 +110,13 @@ inline bool IsMultipleOf4( osc_bundle_element_size_t x )
} }
// round up to the next highest multiple of 4. unless x is already a multiple of 4
static inline std::size_t RoundUp4( std::size_t x )
{
return (x + 3) & ~((std::size_t)0x03);
}
enum TypeTagValues { enum TypeTagValues {
TRUE_TYPE_TAG = 'T', TRUE_TYPE_TAG = 'T',
FALSE_TYPE_TAG = 'F', FALSE_TYPE_TAG = 'F',
@@ -15,7 +15,7 @@ class FOscModule : public IModuleInterface
public: public:
virtual void StartupModule( ) override virtual void StartupModule( ) override
{ {
if(!FModuleManager::Get().LoadModule(TEXT("Networking")).IsValid()) if(!FModuleManager::Get().LoadModule(TEXT("Networking")))
{ {
UE_LOG(LogOSC, Error, TEXT("Required module Networking failed to load")); UE_LOG(LogOSC, Error, TEXT("Required module Networking failed to load"));
return; return;
@@ -105,7 +105,7 @@ public:
uint32_t receivePort; uint32_t receivePort;
if(UOscSettings::Parse(settings->ReceiveFrom, &receiveAddress, &receivePort)) if(UOscSettings::Parse(settings->ReceiveFrom, &receiveAddress, &receivePort))
{ {
_dispatcher->Listen(receiveAddress, receivePort); _dispatcher->Listen(receiveAddress, receivePort, settings->MulticastLoopback);
} }
else else
{ {
@@ -6,6 +6,7 @@
UOscSettings::UOscSettings() UOscSettings::UOscSettings()
: ReceiveFrom("8000"), : ReceiveFrom("8000"),
MulticastLoopback(true),
_sendSocket(FUdpSocketBuilder(TEXT("OscSender")).Build()) _sendSocket(FUdpSocketBuilder(TEXT("OscSender")).Build())
{ {
SendTargets.Add(TEXT("127.0.0.1:8000")); SendTargets.Add(TEXT("127.0.0.1:8000"));
@@ -160,7 +161,7 @@ void UOscSettings::ClearKeyInputs(UOscDispatcher & dispatcher)
{ {
// Unregister here, not in the OscReceiverInputKey destructor // Unregister here, not in the OscReceiverInputKey destructor
// because it would crash at the application exit. // because it would crash at the application exit.
dispatcher.UnregisterReceiver(&receiver); dispatcher.UnregisterReceiver(receiver.get());
} }
_keyReceivers.Reset(0); _keyReceivers.Reset(0);
} }
@@ -170,7 +171,8 @@ void UOscSettings::UpdateKeyInputs(UOscDispatcher & dispatcher)
ClearKeyInputs(dispatcher); ClearKeyInputs(dispatcher);
for(const auto & address : Inputs) for(const auto & address : Inputs)
{ {
_keyReceivers.Emplace(address); auto receiver = std::make_unique<OscReceiverInputKey>(address);
dispatcher.RegisterReceiver(&_keyReceivers.Last()); dispatcher.RegisterReceiver(receiver.get());
_keyReceivers.Add(std::move(receiver));
} }
} }
@@ -8,7 +8,7 @@
class UOscDispatcher; class UOscDispatcher;
UCLASS(config=Engine) UCLASS(Config=Engine, DefaultConfig)
class UOscSettings : public UObject class UOscSettings : public UObject
{ {
GENERATED_BODY() GENERATED_BODY()
@@ -44,6 +44,9 @@ public:
UPROPERTY(Config, EditAnywhere, Category=Input) UPROPERTY(Config, EditAnywhere, Category=Input)
TArray<FString> Inputs; TArray<FString> Inputs;
UPROPERTY(Config, EditAnywhere, Category=Network)
bool MulticastLoopback;
public: public:
void InitSendTargets(); void InitSendTargets();
@@ -70,5 +73,5 @@ private:
TSharedRef<FSocket> _sendSocket; TSharedRef<FSocket> _sendSocket;
TArray<TSharedRef<FInternetAddr>> _sendAddresses; TArray<TSharedRef<FInternetAddr>> _sendAddresses;
TMap<FString, int32> _sendAddressesIndex; TMap<FString, int32> _sendAddressesIndex;
TArray<OscReceiverInputKey> _keyReceivers; TArray<std::unique_ptr<OscReceiverInputKey>> _keyReceivers;
}; };
@@ -25,7 +25,7 @@ UOscDispatcher * UOscDispatcher::Get()
return UOscDispatcher::StaticClass()->GetDefaultObject<UOscDispatcher>(); return UOscDispatcher::StaticClass()->GetDefaultObject<UOscDispatcher>();
} }
void UOscDispatcher::Listen(FIPv4Address address, uint32_t port) void UOscDispatcher::Listen(FIPv4Address address, uint32_t port, bool multicastLoopback)
{ {
if(_listening != std::make_pair(address, port)) if(_listening != std::make_pair(address, port))
{ {
@@ -36,6 +36,10 @@ void UOscDispatcher::Listen(FIPv4Address address, uint32_t port)
if(address.IsMulticastAddress()) if(address.IsMulticastAddress())
{ {
builder.JoinedToGroup(address); builder.JoinedToGroup(address);
if(multicastLoopback)
{
builder.WithMulticastLoopback();
}
} }
else else
{ {
@@ -131,6 +135,25 @@ static void SendMessage(TCircularQueue<std::tuple<FName, TArray<FOscDataElemStru
{ {
elem.SetString(FName(it->AsStringUnchecked())); elem.SetString(FName(it->AsStringUnchecked()));
} }
else if(it->IsBlob())
{
const void* buffer;
osc::osc_bundle_element_size_t size;
osc::Errors error = osc::SUCCESS;
it->AsBlobUnchecked(buffer, size, error);
TArray<uint8> blob;
if(size && !error)
{
blob.SetNumUninitialized(size);
FMemory::Memcpy(blob.GetData(), buffer, size);
}
else if(error)
{
UE_LOG(LogOSC, Warning, TEXT("OSC Received Message Error: %s"), osc::errorString(error));
}
elem.SetBlob(std::move(blob));
}
data.Add(elem); data.Add(elem);
} }
@@ -16,7 +16,7 @@ class UOscDispatcher : public UObject
friend class FOscModule; friend class FOscModule;
void Listen(FIPv4Address address, uint32_t port); void Listen(FIPv4Address address, uint32_t port, bool multicastLoopback);
void Stop(); void Stop();
public: public:
@@ -6,6 +6,7 @@
/// Base class to receive OSC messages. /// Base class to receive OSC messages.
struct IOscReceiverInterface struct IOscReceiverInterface
{ {
virtual ~IOscReceiverInterface() {}
virtual const FString & GetAddressFilter() const = 0; virtual const FString & GetAddressFilter() const = 0;
virtual void SendEvent(const FName & Address, const TArray<FOscDataElemStruct> & Data, const FString & SenderIp) = 0; virtual void SendEvent(const FName & Address, const TArray<FOscDataElemStruct> & Data, const FString & SenderIp) = 0;
}; };
+2 -14
View File
@@ -5,21 +5,9 @@ using System.Collections.Generic;
public class OscDemoTarget : TargetRules public class OscDemoTarget : TargetRules
{ {
public OscDemoTarget(TargetInfo Target) public OscDemoTarget(TargetInfo Target) : base(Target)
{ {
Type = TargetType.Game; Type = TargetType.Game;
} ExtraModuleNames.AddRange( new string[] { "OscDemo" } );
//
// TargetRules interface.
//
public override void SetupBinaries(
TargetInfo Target,
ref List<UEBuildBinaryConfiguration> OutBuildBinaryConfigurations,
ref List<string> OutExtraModuleNames
)
{
OutExtraModuleNames.AddRange( new string[] { "OscDemo" } );
} }
} }
@@ -4,8 +4,8 @@ using UnrealBuildTool;
public class OscDemo : ModuleRules public class OscDemo : ModuleRules
{ {
public OscDemo(TargetInfo Target) public OscDemo(ReadOnlyTargetRules Target) : base(Target)
{ {
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore" }); PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore" });
PrivateDependencyModuleNames.AddRange(new string[] { }); PrivateDependencyModuleNames.AddRange(new string[] { });
@@ -5,21 +5,9 @@ using System.Collections.Generic;
public class OscDemoEditorTarget : TargetRules public class OscDemoEditorTarget : TargetRules
{ {
public OscDemoEditorTarget(TargetInfo Target) public OscDemoEditorTarget(TargetInfo Target) : base(Target)
{ {
Type = TargetType.Editor; Type = TargetType.Editor;
} ExtraModuleNames.AddRange(new string[] { "OscDemo" });
}
//
// TargetRules interface.
//
public override void SetupBinaries(
TargetInfo Target,
ref List<UEBuildBinaryConfiguration> OutBuildBinaryConfigurations,
ref List<string> OutExtraModuleNames
)
{
OutExtraModuleNames.AddRange( new string[] { "OscDemo" } );
}
} }