This commit is contained in:
monsieurgustav
2015-05-28 20:48:40 +02:00
parent 47d2a303e9
commit 0275de3fec
15 changed files with 87 additions and 62 deletions
@@ -92,14 +92,9 @@ struct FOscDataElemStruct
void SetString(FName value) void SetString(FName value)
{ {
#if OSC_ENGINE_VERSION < 40500
static_assert(sizeof(value) <= sizeof(Data), "Too short to hold the string value.");
Data = *reinterpret_cast<const int64*>(&value);
#else
static_assert(sizeof(FMinimalName) <= sizeof(Data), "Too short to hold the string value."); static_assert(sizeof(FMinimalName) <= sizeof(Data), "Too short to hold the string value.");
const auto mininal = NameToMinimalName(value); const auto mininal = NameToMinimalName(value);
Data = *reinterpret_cast<const int64*>(&mininal); Data = *reinterpret_cast<const int64*>(&mininal);
#endif
Type = STRING; Type = STRING;
check(value == AsStringValue()); check(value == AsStringValue());
} }
@@ -107,11 +102,7 @@ struct FOscDataElemStruct
FName AsStringValue() const FName AsStringValue() const
{ {
check(IsString()); check(IsString());
#if OSC_ENGINE_VERSION < 40500
return *reinterpret_cast<const FName *>(&Data);
#else
return MinimalNameToName(*reinterpret_cast<const FMinimalName *>(&Data)); return MinimalNameToName(*reinterpret_cast<const FMinimalName *>(&Data));
#endif
} }
bool IsString() const bool IsString() const
@@ -4,11 +4,6 @@
#include "oscpack/osc/OscOutboundPacketStream.h" #include "oscpack/osc/OscOutboundPacketStream.h"
UOscFunctionLibrary::UOscFunctionLibrary(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{
}
template <class T> template <class T>
static inline static inline
void PopValueImpl(const TArray<FOscDataElemStruct> & input, TArray<FOscDataElemStruct> & output, T & Value) void PopValueImpl(const TArray<FOscDataElemStruct> & input, TArray<FOscDataElemStruct> & output, T & Value)
@@ -7,7 +7,9 @@
UCLASS() UCLASS()
class UOscFunctionLibrary : public UBlueprintFunctionLibrary class UOscFunctionLibrary : public UBlueprintFunctionLibrary
{ {
GENERATED_UCLASS_BODY() GENERATED_BODY()
public:
/// Get the next value from an OSC message as a boolean. /// Get the next value from an OSC message as a boolean.
UFUNCTION(BlueprintPure, Category=OSC) UFUNCTION(BlueprintPure, Category=OSC)
+1 -1
View File
@@ -2,7 +2,7 @@
// Target engine version. Used to enable compatibility code. // Target engine version. Used to enable compatibility code.
#define OSC_ENGINE_VERSION 40700 #define OSC_ENGINE_VERSION 40800
#ifndef OSC_EDITOR_BUILD #ifndef OSC_EDITOR_BUILD
#error OSC_EDITOR_BUILD must be set by the OSC.Build.cs #error OSC_EDITOR_BUILD must be set by the OSC.Build.cs
-16
View File
@@ -32,24 +32,9 @@ public:
HandleSettingsSaved(); HandleSettingsSaved();
// register settings // register settings
#if OSC_ENGINE_VERSION < 40600
auto settingsModule = ISettingsModule::Get();
#else
auto settingsModule = FModuleManager::GetModulePtr<ISettingsModule>("Settings"); auto settingsModule = FModuleManager::GetModulePtr<ISettingsModule>("Settings");
#endif
if(settingsModule) if(settingsModule)
{ {
#if OSC_ENGINE_VERSION < 40600
FSettingsSectionDelegates settingsDelegates;
settingsDelegates.ModifiedDelegate = FOnSettingsSectionModified::CreateRaw(this, &FOscModule::HandleSettingsSaved);
auto settings = GetMutableDefault<UOscSettings>();
settingsModule->RegisterSettings("Project", "Plugins", "OSC",
LOCTEXT("OscSettingsName", "OSC"),
LOCTEXT("OscSettingsDescription", "Configure the OSC plug-in."),
settings,
settingsDelegates);
#else
auto settingsSection = settingsModule->RegisterSettings("Project", "Plugins", "OSC", auto settingsSection = settingsModule->RegisterSettings("Project", "Plugins", "OSC",
LOCTEXT("OscSettingsName", "OSC"), LOCTEXT("OscSettingsName", "OSC"),
LOCTEXT("OscSettingsDescription", "Configure the OSC plug-in."), LOCTEXT("OscSettingsDescription", "Configure the OSC plug-in."),
@@ -60,7 +45,6 @@ public:
{ {
settingsSection->OnModified().BindRaw(this, &FOscModule::HandleSettingsSaved); settingsSection->OnModified().BindRaw(this, &FOscModule::HandleSettingsSaved);
} }
#endif
} }
else else
{ {
-5
View File
@@ -2,14 +2,9 @@
#include "Osc.h" #include "Osc.h"
#if OSC_ENGINE_VERSION < 40600
#include "Core.h"
#include "Settings.h"
#else
#include "Engine.h" #include "Engine.h"
#include "ISettingsModule.h" #include "ISettingsModule.h"
#include "ISettingsSection.h" #include "ISettingsSection.h"
#endif
#include "ModuleManager.h" #include "ModuleManager.h"
#include "Sockets.h" #include "Sockets.h"
+8 -3
View File
@@ -4,14 +4,19 @@
#include "OscDispatcher.h" #include "OscDispatcher.h"
UOscSettings::UOscSettings( const class FPostConstructInitializeProperties& PCIP ) UOscSettings::UOscSettings()
: Super(PCIP), : ReceiveFrom("8000"),
ReceiveFrom("8000"),
_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"));
} }
UOscSettings::UOscSettings(FVTableHelper & helper)
: _sendSocket(FUdpSocketBuilder(TEXT("OscSender")).Build())
{
// Does not need to be a valid object.
}
void UOscSettings::UpdateSendAddresses() void UOscSettings::UpdateSendAddresses()
{ {
FString addressStr, portStr; FString addressStr, portStr;
+7 -1
View File
@@ -11,10 +11,16 @@ class UOscDispatcher;
UCLASS(config=Engine) UCLASS(config=Engine)
class UOscSettings : public UObject class UOscSettings : public UObject
{ {
GENERATED_UCLASS_BODY() GENERATED_BODY()
public: public:
/// Default constructor
UOscSettings();
/// Hot reload constructor
UOscSettings(FVTableHelper & helper);
/** /**
* Specify the [address:]port to listen to. * Specify the [address:]port to listen to.
* *
@@ -5,15 +5,20 @@
#include "oscpack/osc/OscReceivedElements.h" #include "oscpack/osc/OscReceivedElements.h"
UOscDispatcher::UOscDispatcher(const class FPostConstructInitializeProperties& PCIP) UOscDispatcher::UOscDispatcher()
: Super(PCIP), : _listening(FIPv4Address(0), 0),
_listening(FIPv4Address(0), 0),
_socket(nullptr), _socket(nullptr),
_socketReceiver(nullptr), _socketReceiver(nullptr),
_pendingMessages(1024) // arbitrary max message count per frame _pendingMessages(1024) // arbitrary max message count per frame
{ {
} }
UOscDispatcher::UOscDispatcher(FVTableHelper & helper)
: _pendingMessages(0)
{
// Does not need to be a valid object.
}
UOscDispatcher * UOscDispatcher::Get() UOscDispatcher * UOscDispatcher::Get()
{ {
return UOscDispatcher::StaticClass()->GetDefaultObject<UOscDispatcher>(); return UOscDispatcher::StaticClass()->GetDefaultObject<UOscDispatcher>();
@@ -173,11 +178,7 @@ void UOscDispatcher::Callback(const FArrayReaderPtr& data, const FIPv4Endpoint&)
{ {
FSimpleDelegateGraphTask::CreateAndDispatchWhenReady( FSimpleDelegateGraphTask::CreateAndDispatchWhenReady(
FSimpleDelegateGraphTask::FDelegate::CreateUObject(this, &UOscDispatcher::CallbackMainThread), FSimpleDelegateGraphTask::FDelegate::CreateUObject(this, &UOscDispatcher::CallbackMainThread),
#if OSC_ENGINE_VERSION < 40500
TEXT("OscDispatcherProcessMessages"),
#else
TStatId(), TStatId(),
#endif
nullptr, nullptr,
ENamedThreads::GameThread); ENamedThreads::GameThread);
} }
@@ -12,14 +12,19 @@ class FUdpSocketReceiver;
UCLASS() UCLASS()
class UOscDispatcher : public UObject class UOscDispatcher : public UObject
{ {
GENERATED_UCLASS_BODY() GENERATED_BODY()
friend class OscModule; friend class FOscModule;
void Listen(FIPv4Address address, uint32_t port); void Listen(FIPv4Address address, uint32_t port);
void Stop(); void Stop();
public: public:
/// Default constructor
UOscDispatcher();
/// Hot reload constructor
UOscDispatcher(FVTableHelper & helper);
/// Get the unique instance /// Get the unique instance
/// ///
@@ -3,9 +3,8 @@
#include "OscDispatcher.h" #include "OscDispatcher.h"
AOscReceiverActor::AOscReceiverActor(const class FPostConstructInitializeProperties& PCIP) AOscReceiverActor::AOscReceiverActor()
: Super(PCIP), : _listener(this)
_listener(this)
{ {
auto instance = UOscDispatcher::Get(); auto instance = UOscDispatcher::Get();
if (instance && !HasAnyFlags(RF_ClassDefaultObject)) if (instance && !HasAnyFlags(RF_ClassDefaultObject))
@@ -14,6 +13,12 @@ AOscReceiverActor::AOscReceiverActor(const class FPostConstructInitializePropert
} }
} }
AOscReceiverActor::AOscReceiverActor(FVTableHelper & helper)
: _listener(this)
{
// Does not need to be a valid object.
}
void AOscReceiverActor::BeginDestroy() void AOscReceiverActor::BeginDestroy()
{ {
auto instance = UOscDispatcher::Get(); auto instance = UOscDispatcher::Get();
@@ -9,7 +9,9 @@
UCLASS(ClassGroup=OSC) UCLASS(ClassGroup=OSC)
class AOscReceiverActor : public AActor class AOscReceiverActor : public AActor
{ {
GENERATED_UCLASS_BODY() GENERATED_BODY()
public:
UPROPERTY(EditAnywhere, Category=OSC) UPROPERTY(EditAnywhere, Category=OSC)
FString AddressFilter; FString AddressFilter;
@@ -18,6 +20,12 @@ class AOscReceiverActor : public AActor
void OnOscReceived(const FName & Address, const TArray<FOscDataElemStruct> & Data); void OnOscReceived(const FName & Address, const TArray<FOscDataElemStruct> & Data);
public: public:
AOscReceiverActor();
/// Hot reload constructor
AOscReceiverActor(FVTableHelper & helper);
const FString & GetAddressFilter() const const FString & GetAddressFilter() const
{ {
return AddressFilter; return AddressFilter;
@@ -3,13 +3,18 @@
#include "OscDispatcher.h" #include "OscDispatcher.h"
UOscReceiverComponent::UOscReceiverComponent(const class FPostConstructInitializeProperties& PCIP) UOscReceiverComponent::UOscReceiverComponent()
: Super(PCIP), : _listener(this)
_listener(this)
{ {
} }
UOscReceiverComponent::UOscReceiverComponent(FVTableHelper & helper)
: _listener(this)
{
// Does not need to be a valid object.
}
void UOscReceiverComponent::OnRegister() void UOscReceiverComponent::OnRegister()
{ {
Super::OnRegister(); Super::OnRegister();
@@ -13,7 +13,9 @@ DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FComponentOscReceivedSignature, con
UCLASS(ClassGroup=OSC, meta = (BlueprintSpawnableComponent)) UCLASS(ClassGroup=OSC, meta = (BlueprintSpawnableComponent))
class UOscReceiverComponent : public UActorComponent class UOscReceiverComponent : public UActorComponent
{ {
GENERATED_UCLASS_BODY() GENERATED_BODY()
public:
UPROPERTY(EditAnywhere, Category=OSC) UPROPERTY(EditAnywhere, Category=OSC)
FString AddressFilter; FString AddressFilter;
@@ -22,6 +24,12 @@ class UOscReceiverComponent : public UActorComponent
FComponentOscReceivedSignature OnOscReceived; FComponentOscReceivedSignature OnOscReceived;
public: public:
UOscReceiverComponent();
/// Hot reload constructor
UOscReceiverComponent(FVTableHelper & helper);
const FString & GetAddressFilter() const const FString & GetAddressFilter() const
{ {
return AddressFilter; return AddressFilter;
+19 -4
View File
@@ -7,9 +7,16 @@ OSC plugin for Unreal Engine 4 Blueprints
Integration Integration
=========== ===========
Put the "OSC" folder in a "Plugins" folder in the project root. Install Visual Studio 2013 on Windows (Community edition works) or XCode on MaxOSX.
e.g. "/MyProject/Plugins/OSC" Create a "C++" project, or convert a "Blueprint" project to "C++" **********************
Create a "Plugins" directory in the project root (near the "Content" directory) and put the "OSC" folder of the plugin in it.
(e.g. "/MyProject/Plugins/OSC")
Run the "*.uproject" file: the plugin is compiled automatically.
Alternatively, right-clic the "*.uproject" to generate Visual Studio or XCode project files.
Usage Usage
@@ -35,8 +42,16 @@ Use the PushFloat/Int/Bool/String functions, or standard array functions, to bui
Use the SendOsc function to send the OSC message Use the SendOsc function to send the OSC message
- Inputs:
List the messages that should be UE4 inputs (like a game controller). A new input is created for each message.
Bind OSC inputs to UE4 action in the usual "Input" project settings.
Engine version Engine version
===== =====
Tested on UE 4.4, UE 4.5 (Windows, MacOSX)
Set the OSC_ENGINE_VERSION value (in Source/OSC/Private/Osc.h) to compile for a specific engine version. Get the right branch for your engine version: "default" for the latest version, "before4.8" for 4.4, ..., 4.7, etc.
Optionally, set the OSC_ENGINE_VERSION value (in Source/OSC/Private/Osc.h) to compile for a specific engine version.