mirror of
https://github.com/storytold/UE4-OSC.git
synced 2026-10-09 00:09:43 +00:00
4.17 fix (update OscDemo files)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"FileVersion": 3,
|
||||
"EngineAssociation": "4.11",
|
||||
"EngineAssociation": "4.17",
|
||||
"Category": "",
|
||||
"Description": "",
|
||||
"Modules": [
|
||||
|
||||
@@ -6,10 +6,9 @@
|
||||
"VersionName" : "1.0",
|
||||
"CreatedBy" : "Guillaume Buisson",
|
||||
"CreatedByURL" : "http://guillaume.io",
|
||||
"EngineVersion" : "4.4.0",
|
||||
"Description" : "",
|
||||
"Category" : "OSC",
|
||||
"EnabledByDefault" : false,
|
||||
"EnabledByDefault" : true,
|
||||
|
||||
"Modules" :
|
||||
[
|
||||
|
||||
@@ -2,8 +2,8 @@ namespace UnrealBuildTool.Rules
|
||||
{
|
||||
public class OSC : ModuleRules
|
||||
{
|
||||
public OSC(TargetInfo Target)
|
||||
{
|
||||
public OSC(ReadOnlyTargetRules Target) : base(Target)
|
||||
{
|
||||
PublicDependencyModuleNames.AddRange(
|
||||
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");
|
||||
|
||||
|
||||
@@ -8,24 +8,20 @@ struct FOscDataElemStruct
|
||||
{
|
||||
GENERATED_USTRUCT_BODY()
|
||||
|
||||
UPROPERTY()
|
||||
int32 Type;
|
||||
|
||||
UPROPERTY()
|
||||
int64 Data;
|
||||
|
||||
FOscDataElemStruct() : Type(0), Data(0)
|
||||
{ }
|
||||
|
||||
enum
|
||||
{
|
||||
FLOAT = 0,
|
||||
INT = 1,
|
||||
BOOL = 2,
|
||||
FLOAT = 0,
|
||||
INT = 1,
|
||||
BOOL = 2,
|
||||
STRING = 3,
|
||||
BLOB = 4,
|
||||
};
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
public:
|
||||
|
||||
FOscDataElemStruct() : Type(0), Data(0)
|
||||
{
|
||||
}
|
||||
|
||||
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.
|
||||
template <class T>
|
||||
T GetValue() const
|
||||
@@ -150,6 +167,14 @@ struct FOscDataElemStruct
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -163,6 +188,13 @@ private:
|
||||
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);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
@@ -84,6 +89,14 @@ void UOscFunctionLibrary::PushString(const TArray<FOscDataElemStruct> & input, F
|
||||
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)
|
||||
{
|
||||
@@ -105,6 +118,11 @@ FName UOscFunctionLibrary::AsString(const FOscDataElemStruct & input)
|
||||
return input.GetValue<FName>();
|
||||
}
|
||||
|
||||
TArray<uint8> UOscFunctionLibrary::AsBlob(const FOscDataElemStruct & input)
|
||||
{
|
||||
return input.GetValue<TArray<uint8>>();
|
||||
}
|
||||
|
||||
|
||||
FOscDataElemStruct UOscFunctionLibrary::FromBool(bool input)
|
||||
{
|
||||
@@ -134,6 +152,13 @@ FOscDataElemStruct UOscFunctionLibrary::FromString(FName input)
|
||||
return result;
|
||||
}
|
||||
|
||||
FOscDataElemStruct UOscFunctionLibrary::FromBlob(const TArray<uint8> & input)
|
||||
{
|
||||
FOscDataElemStruct result;
|
||||
result.SetBlob(input);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
@@ -188,6 +213,11 @@ namespace
|
||||
{
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -28,6 +28,10 @@ public:
|
||||
UFUNCTION(BlueprintPure, Category=OSC)
|
||||
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.
|
||||
UFUNCTION(BlueprintPure, Category=OSC, meta=(AutoCreateRefTerm = "input"))
|
||||
@@ -45,6 +49,10 @@ public:
|
||||
UFUNCTION(BlueprintPure, Category=OSC, meta=(AutoCreateRefTerm = "input"))
|
||||
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
|
||||
UFUNCTION(BlueprintPure, Category=OSC)
|
||||
@@ -62,6 +70,10 @@ public:
|
||||
UFUNCTION(BlueprintPure, Category=OSC)
|
||||
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
|
||||
UFUNCTION(BlueprintPure, Category=OSC)
|
||||
@@ -79,6 +91,10 @@ public:
|
||||
UFUNCTION(BlueprintPure, Category=OSC)
|
||||
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.
|
||||
|
||||
-7
@@ -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 )
|
||||
: data_( buffer )
|
||||
, end_( data_ + capacity )
|
||||
|
||||
-7
@@ -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 )
|
||||
{
|
||||
#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 {
|
||||
TRUE_TYPE_TAG = 'T',
|
||||
FALSE_TYPE_TAG = 'F',
|
||||
|
||||
@@ -15,7 +15,7 @@ class FOscModule : public IModuleInterface
|
||||
public:
|
||||
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"));
|
||||
return;
|
||||
@@ -105,7 +105,7 @@ public:
|
||||
uint32_t receivePort;
|
||||
if(UOscSettings::Parse(settings->ReceiveFrom, &receiveAddress, &receivePort))
|
||||
{
|
||||
_dispatcher->Listen(receiveAddress, receivePort);
|
||||
_dispatcher->Listen(receiveAddress, receivePort, settings->MulticastLoopback);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
UOscSettings::UOscSettings()
|
||||
: ReceiveFrom("8000"),
|
||||
MulticastLoopback(true),
|
||||
_sendSocket(FUdpSocketBuilder(TEXT("OscSender")).Build())
|
||||
{
|
||||
SendTargets.Add(TEXT("127.0.0.1:8000"));
|
||||
@@ -160,7 +161,7 @@ void UOscSettings::ClearKeyInputs(UOscDispatcher & dispatcher)
|
||||
{
|
||||
// Unregister here, not in the OscReceiverInputKey destructor
|
||||
// because it would crash at the application exit.
|
||||
dispatcher.UnregisterReceiver(&receiver);
|
||||
dispatcher.UnregisterReceiver(receiver.get());
|
||||
}
|
||||
_keyReceivers.Reset(0);
|
||||
}
|
||||
@@ -170,7 +171,8 @@ void UOscSettings::UpdateKeyInputs(UOscDispatcher & dispatcher)
|
||||
ClearKeyInputs(dispatcher);
|
||||
for(const auto & address : Inputs)
|
||||
{
|
||||
_keyReceivers.Emplace(address);
|
||||
dispatcher.RegisterReceiver(&_keyReceivers.Last());
|
||||
auto receiver = std::make_unique<OscReceiverInputKey>(address);
|
||||
dispatcher.RegisterReceiver(receiver.get());
|
||||
_keyReceivers.Add(std::move(receiver));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
class UOscDispatcher;
|
||||
|
||||
|
||||
UCLASS(config=Engine)
|
||||
UCLASS(Config=Engine, DefaultConfig)
|
||||
class UOscSettings : public UObject
|
||||
{
|
||||
GENERATED_BODY()
|
||||
@@ -44,6 +44,9 @@ public:
|
||||
UPROPERTY(Config, EditAnywhere, Category=Input)
|
||||
TArray<FString> Inputs;
|
||||
|
||||
UPROPERTY(Config, EditAnywhere, Category=Network)
|
||||
bool MulticastLoopback;
|
||||
|
||||
public:
|
||||
void InitSendTargets();
|
||||
|
||||
@@ -70,5 +73,5 @@ private:
|
||||
TSharedRef<FSocket> _sendSocket;
|
||||
TArray<TSharedRef<FInternetAddr>> _sendAddresses;
|
||||
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>();
|
||||
}
|
||||
|
||||
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))
|
||||
{
|
||||
@@ -36,6 +36,10 @@ void UOscDispatcher::Listen(FIPv4Address address, uint32_t port)
|
||||
if(address.IsMulticastAddress())
|
||||
{
|
||||
builder.JoinedToGroup(address);
|
||||
if(multicastLoopback)
|
||||
{
|
||||
builder.WithMulticastLoopback();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -131,6 +135,25 @@ static void SendMessage(TCircularQueue<std::tuple<FName, TArray<FOscDataElemStru
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ class UOscDispatcher : public UObject
|
||||
|
||||
friend class FOscModule;
|
||||
|
||||
void Listen(FIPv4Address address, uint32_t port);
|
||||
void Listen(FIPv4Address address, uint32_t port, bool multicastLoopback);
|
||||
void Stop();
|
||||
|
||||
public:
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
/// Base class to receive OSC messages.
|
||||
struct IOscReceiverInterface
|
||||
{
|
||||
virtual ~IOscReceiverInterface() {}
|
||||
virtual const FString & GetAddressFilter() const = 0;
|
||||
virtual void SendEvent(const FName & Address, const TArray<FOscDataElemStruct> & Data, const FString & SenderIp) = 0;
|
||||
};
|
||||
|
||||
@@ -5,21 +5,9 @@ using System.Collections.Generic;
|
||||
|
||||
public class OscDemoTarget : TargetRules
|
||||
{
|
||||
public OscDemoTarget(TargetInfo Target)
|
||||
public OscDemoTarget(TargetInfo Target) : base(Target)
|
||||
{
|
||||
Type = TargetType.Game;
|
||||
}
|
||||
|
||||
//
|
||||
// TargetRules interface.
|
||||
//
|
||||
|
||||
public override void SetupBinaries(
|
||||
TargetInfo Target,
|
||||
ref List<UEBuildBinaryConfiguration> OutBuildBinaryConfigurations,
|
||||
ref List<string> OutExtraModuleNames
|
||||
)
|
||||
{
|
||||
OutExtraModuleNames.AddRange( new string[] { "OscDemo" } );
|
||||
ExtraModuleNames.AddRange( new string[] { "OscDemo" } );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@ using UnrealBuildTool;
|
||||
|
||||
public class OscDemo : ModuleRules
|
||||
{
|
||||
public OscDemo(TargetInfo Target)
|
||||
{
|
||||
public OscDemo(ReadOnlyTargetRules Target) : base(Target)
|
||||
{
|
||||
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore" });
|
||||
|
||||
PrivateDependencyModuleNames.AddRange(new string[] { });
|
||||
|
||||
@@ -5,21 +5,9 @@ using System.Collections.Generic;
|
||||
|
||||
public class OscDemoEditorTarget : TargetRules
|
||||
{
|
||||
public OscDemoEditorTarget(TargetInfo Target)
|
||||
{
|
||||
public OscDemoEditorTarget(TargetInfo Target) : base(Target)
|
||||
{
|
||||
Type = TargetType.Editor;
|
||||
}
|
||||
|
||||
//
|
||||
// TargetRules interface.
|
||||
//
|
||||
|
||||
public override void SetupBinaries(
|
||||
TargetInfo Target,
|
||||
ref List<UEBuildBinaryConfiguration> OutBuildBinaryConfigurations,
|
||||
ref List<string> OutExtraModuleNames
|
||||
)
|
||||
{
|
||||
OutExtraModuleNames.AddRange( new string[] { "OscDemo" } );
|
||||
}
|
||||
ExtraModuleNames.AddRange(new string[] { "OscDemo" });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user