mirror of
https://github.com/storytold/UE4-OSC.git
synced 2026-10-17 00:25:12 +00:00
in editor, listen port only during play/simulate
This commit is contained in:
@@ -39,6 +39,17 @@ namespace UnrealBuildTool.Rules
|
|||||||
);
|
);
|
||||||
|
|
||||||
bEnableExceptions = true;
|
bEnableExceptions = true;
|
||||||
|
|
||||||
|
if (Target.Type.HasValue && TargetRules.IsEditorType(Target.Type.Value))
|
||||||
|
{
|
||||||
|
Definitions.Add("OSC_EDITOR_BUILD=1");
|
||||||
|
|
||||||
|
PrivateDependencyModuleNames.Add("UnrealEd");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Definitions.Add("OSC_EDITOR_BUILD=0");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,10 @@
|
|||||||
// Target engine version. Used to enable compatibility code.
|
// Target engine version. Used to enable compatibility code.
|
||||||
#define OSC_ENGINE_VERSION 40600
|
#define OSC_ENGINE_VERSION 40600
|
||||||
|
|
||||||
|
#ifndef OSC_EDITOR_BUILD
|
||||||
|
#error OSC_EDITOR_BUILD must be set by the OSC.Build.cs
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* Public Dependencies
|
/* Public Dependencies
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
#include "OscPrivatePCH.h"
|
#include "OscPrivatePCH.h"
|
||||||
#include "OscDispatcher.h"
|
#include "OscDispatcher.h"
|
||||||
|
|
||||||
|
#if OSC_EDITOR_BUILD
|
||||||
|
#include "Editor.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#define LOCTEXT_NAMESPACE "FOscModule"
|
#define LOCTEXT_NAMESPACE "FOscModule"
|
||||||
|
|
||||||
@@ -16,6 +20,12 @@ public:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if OSC_EDITOR_BUILD
|
||||||
|
_isPlayingInEditor = false;
|
||||||
|
FEditorDelegates::BeginPIE.AddRaw(this, &FOscModule::OnBeginPIE);
|
||||||
|
FEditorDelegates::EndPIE.AddRaw(this, &FOscModule::OnEndPIE);
|
||||||
|
#endif
|
||||||
|
|
||||||
_dispatcher = UOscDispatcher::Get();
|
_dispatcher = UOscDispatcher::Get();
|
||||||
|
|
||||||
HandleSettingsSaved();
|
HandleSettingsSaved();
|
||||||
@@ -53,7 +63,9 @@ public:
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
#if OSC_EDITOR_BUILD
|
||||||
UE_LOG(LogOSC, Warning, TEXT("Settings changed registration failed"));
|
UE_LOG(LogOSC, Warning, TEXT("Settings changed registration failed"));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
UE_LOG(LogOSC, Display, TEXT("Startup succeed"));
|
UE_LOG(LogOSC, Display, TEXT("Startup succeed"));
|
||||||
}
|
}
|
||||||
@@ -84,17 +96,15 @@ public:
|
|||||||
auto settings = GetMutableDefault<UOscSettings>();
|
auto settings = GetMutableDefault<UOscSettings>();
|
||||||
|
|
||||||
// receive settings
|
// receive settings
|
||||||
FIPv4Address receiveAddress(0);
|
#if OSC_EDITOR_BUILD
|
||||||
uint32_t receivePort;
|
if(_isPlayingInEditor)
|
||||||
if(UOscSettings::Parse(settings->ReceiveFrom, &receiveAddress, &receivePort))
|
|
||||||
{
|
{
|
||||||
_dispatcher->Listen(receiveAddress, receivePort);
|
Listen(settings);
|
||||||
}
|
}
|
||||||
else
|
#else
|
||||||
{
|
Listen(settings);
|
||||||
UE_LOG(LogOSC, Warning, TEXT("Fail to parse receive address: %s"), *settings->ReceiveFrom);
|
#endif
|
||||||
}
|
|
||||||
|
|
||||||
// send settings
|
// send settings
|
||||||
settings->UpdateSendAddresses();
|
settings->UpdateSendAddresses();
|
||||||
|
|
||||||
@@ -104,6 +114,40 @@ public:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Listen(UOscSettings * settings)
|
||||||
|
{
|
||||||
|
FIPv4Address receiveAddress(0);
|
||||||
|
uint32_t receivePort;
|
||||||
|
if(UOscSettings::Parse(settings->ReceiveFrom, &receiveAddress, &receivePort))
|
||||||
|
{
|
||||||
|
_dispatcher->Listen(receiveAddress, receivePort);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UE_LOG(LogOSC, Error, TEXT("Fail to parse receive address: %s"), *settings->ReceiveFrom);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
#if OSC_EDITOR_BUILD
|
||||||
|
void OnBeginPIE(bool isSimulating)
|
||||||
|
{
|
||||||
|
_isPlayingInEditor = true;
|
||||||
|
|
||||||
|
check(_dispatcher.IsValid())
|
||||||
|
auto settings = GetMutableDefault<UOscSettings>();
|
||||||
|
Listen(settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnEndPIE(bool isSimulating)
|
||||||
|
{
|
||||||
|
_isPlayingInEditor = false;
|
||||||
|
_dispatcher->Stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool _isPlayingInEditor;
|
||||||
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
TWeakObjectPtr<UOscDispatcher> _dispatcher;
|
TWeakObjectPtr<UOscDispatcher> _dispatcher;
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ void UOscSettings::UpdateSendAddresses()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
UE_LOG(LogOSC, Warning, TEXT("Fail to parse or invalid send address: %s"), *SendTargets[i]);
|
UE_LOG(LogOSC, Error, TEXT("Fail to parse or invalid send address: %s"), *SendTargets[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -69,7 +69,7 @@ void UOscSettings::Send(const uint8 *buffer, int32 length, int32 targetIndex)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
UE_LOG(LogOSC, Warning, TEXT("Cannot send OSC: invalid targetIndex %d"), targetIndex);
|
UE_LOG(LogOSC, Error, TEXT("Cannot send OSC: invalid targetIndex %d"), targetIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user