in editor, listen port only during play/simulate

This commit is contained in:
monsieurgustav
2015-02-05 00:41:09 +01:00
parent bde87ae9dc
commit 9a3e5015ab
4 changed files with 70 additions and 11 deletions
+11
View File
@@ -39,6 +39,17 @@ namespace UnrealBuildTool.Rules
);
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
View File
@@ -4,6 +4,10 @@
// Target engine version. Used to enable compatibility code.
#define OSC_ENGINE_VERSION 40600
#ifndef OSC_EDITOR_BUILD
#error OSC_EDITOR_BUILD must be set by the OSC.Build.cs
#endif
/* Public Dependencies
*****************************************************************************/
+53 -9
View File
@@ -1,6 +1,10 @@
#include "OscPrivatePCH.h"
#include "OscDispatcher.h"
#if OSC_EDITOR_BUILD
#include "Editor.h"
#endif
#define LOCTEXT_NAMESPACE "FOscModule"
@@ -16,6 +20,12 @@ public:
return;
}
#if OSC_EDITOR_BUILD
_isPlayingInEditor = false;
FEditorDelegates::BeginPIE.AddRaw(this, &FOscModule::OnBeginPIE);
FEditorDelegates::EndPIE.AddRaw(this, &FOscModule::OnEndPIE);
#endif
_dispatcher = UOscDispatcher::Get();
HandleSettingsSaved();
@@ -53,7 +63,9 @@ public:
}
else
{
#if OSC_EDITOR_BUILD
UE_LOG(LogOSC, Warning, TEXT("Settings changed registration failed"));
#endif
}
UE_LOG(LogOSC, Display, TEXT("Startup succeed"));
}
@@ -84,17 +96,15 @@ public:
auto settings = GetMutableDefault<UOscSettings>();
// receive settings
FIPv4Address receiveAddress(0);
uint32_t receivePort;
if(UOscSettings::Parse(settings->ReceiveFrom, &receiveAddress, &receivePort))
#if OSC_EDITOR_BUILD
if(_isPlayingInEditor)
{
_dispatcher->Listen(receiveAddress, receivePort);
Listen(settings);
}
else
{
UE_LOG(LogOSC, Warning, TEXT("Fail to parse receive address: %s"), *settings->ReceiveFrom);
}
#else
Listen(settings);
#endif
// send settings
settings->UpdateSendAddresses();
@@ -104,6 +114,40 @@ public:
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:
TWeakObjectPtr<UOscDispatcher> _dispatcher;
+2 -2
View File
@@ -35,7 +35,7 @@ void UOscSettings::UpdateSendAddresses()
}
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
{
UE_LOG(LogOSC, Warning, TEXT("Cannot send OSC: invalid targetIndex %d"), targetIndex);
UE_LOG(LogOSC, Error, TEXT("Cannot send OSC: invalid targetIndex %d"), targetIndex);
}
}