Skip to content

Commit

Permalink
Changed the dereferrenced FBPropertyStrings to const char* casts
Browse files Browse the repository at this point in the history
Changed from using kReference's to int32s as adding a row using a pointer casted to a kReference was silently converting from 8 bytes to 4 bytes meaning that later pointer comparisons failed
Added a UID system in the LiveLinkDevice to replace using pointers for row indices
Set BeforeRender to be the default update mode which should provide a smoother stream in the majority of use cases
  • Loading branch information
EpicAeryll committed Oct 4, 2018
1 parent 35bae95 commit f2d7912
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 38 deletions.
20 changes: 12 additions & 8 deletions Source/Private/MobuLiveLinkDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,8 @@ FBRegisterDevice ( MOBULIVELINK__NAME,
************************************************/
bool FMobuLiveLink::FBCreate()
{
// Set sampling rate to 60 Hz
CurrentSampleRate = FFrameRate(60, 1);
bShouldUpdateInRenderCallback = false;
// Set sampling rate to Before Render
CurrentSampleRate = SampleOptions.Last().Value;
UpdateSampleRate();

StartLiveLink();
Expand All @@ -62,7 +61,7 @@ bool FMobuLiveLink::FBCreate()
SetDirty(false);

TSharedPtr<IStreamObject> EditorCamera = MakeShared<FEditorActiveCameraStreamObject>(LiveLinkProvider);
StreamObjects.Emplace((kReference)nullptr, EditorCamera);
StreamObjects.Emplace(-1, EditorCamera);

LastEvaluationTime = FPlatformTime::Seconds();

Expand Down Expand Up @@ -228,7 +227,7 @@ void FMobuLiveLink::UpdateStream()
{
UpdateStreamObjects();
}
for (TPair<kReference, TSharedPtr<IStreamObject>>& MapPair : StreamObjects)
for (TPair<int32, TSharedPtr<IStreamObject>>& MapPair : StreamObjects)
{
const TSharedPtr<IStreamObject>& StreamObject = MapPair.Value;
StreamObject->UpdateSubjectFrame();
Expand Down Expand Up @@ -314,7 +313,7 @@ bool FMobuLiveLink::FbxStore(FBFbxObject* pFbxObject, kFbxObjectStore pStoreWhat
pFbxObject->FieldWriteI(MOBULIVELINK_NUMBER_OF_OBJECT_COLUMNS);

// NumberOfObjects * NumberOfObjectColumns * ObjectColumn
for (TPair<kReference, TSharedPtr<IStreamObject>>& MapPair : StreamObjects)
for (TPair<int32, TSharedPtr<IStreamObject>>& MapPair : StreamObjects)
{
const FString StreamObjectRootName = MapPair.Value->GetRootName();

Expand Down Expand Up @@ -368,7 +367,7 @@ bool FMobuLiveLink::FbxRetrieve(FBFbxObject* pFbxObject, kFbxObjectStore pStoreW
{
FBModel* FoundFBModel = (FBModel*)FoundModels[0];
TSharedPtr<IStreamObject> FoundStreamObject = StreamObjectManagement::FBModelToStreamObject(FoundFBModel, LiveLinkProvider);
StreamObjects.Emplace((kReference)FoundFBModel, FoundStreamObject);
StreamObjects.Emplace(GetNextUID(), FoundStreamObject);

FName SubjectName(pFbxObject->FieldReadC());
int32 StreamingMode = pFbxObject->FieldReadI();
Expand Down Expand Up @@ -450,7 +449,7 @@ void FMobuLiveLink::EventSceneChange(HISender Sender, HKEvent Event)

void FMobuLiveLink::UpdateStreamObjects()
{
for (TPair<kReference, TSharedPtr<IStreamObject>>& MapPair : StreamObjects)
for (TPair<int32, TSharedPtr<IStreamObject>>& MapPair : StreamObjects)
{
const TSharedPtr<IStreamObject>& StreamObject = MapPair.Value;
if (StreamObject->IsValid())
Expand All @@ -471,4 +470,9 @@ void FMobuLiveLink::TickCoreTicker()
double CurrentTime = FPlatformTime::Seconds();
FTicker::GetCoreTicker().Tick(CurrentTime - LastEvaluationTime);
LastEvaluationTime = CurrentTime;
}

int32 FMobuLiveLink::GetNextUID()
{
return NextUID++;
}
41 changes: 24 additions & 17 deletions Source/Private/MobuLiveLinkLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ void FMobuLiveLinkLayout::UIReset()
FBTrace("UI Reset!\n");
StreamSpread.Clear();
CreateSpreadColumns();
for (const TPair<kReference, StreamObjectPtr>& MapPair : LiveLinkDevice->StreamObjects)
for (const TPair<int32, StreamObjectPtr>& MapPair : LiveLinkDevice->StreamObjects)
{
AddSpreadRowFromStreamObject(MapPair.Value);
AddSpreadRowFromStreamObject(MapPair.Key, MapPair.Value);
}
LiveLinkDevice->SetRefreshUI(false);
}
Expand All @@ -176,28 +176,34 @@ void FMobuLiveLinkLayout::EventUIIdle(HISender Sender, HKEvent Event)
}
}

void FMobuLiveLinkLayout::AddSpreadRowFromStreamObject(StreamObjectPtr Object)
void FMobuLiveLinkLayout::AddSpreadRowFromStreamObject(int32 NewRowKey, StreamObjectPtr Object)
{
// Check whether the Object should be shown
if (!Object->ShouldShowInUI()) return;

const kReference ObjectReference = Object->GetReference();
const FString RootName = Object->GetRootName();

StreamSpread.RowAdd(FStringToChar(RootName), ObjectReference);
StreamSpread.RowAdd(FStringToChar(RootName), NewRowKey);

StreamSpread.SetCell(ObjectReference, 0, FStringToChar(Object->GetSubjectName().ToString()));
StreamSpread.SetCell(ObjectReference, 1, FStringToChar(Object->GetStreamOptions()));
StreamSpread.SetCell(ObjectReference, 1, Object->GetStreamingMode());
StreamSpread.SetCell(NewRowKey, 0, FStringToChar(Object->GetSubjectName().ToString()));
StreamSpread.SetCell(NewRowKey, 1, FStringToChar(Object->GetStreamOptions()));
StreamSpread.SetCell(NewRowKey, 1, Object->GetStreamingMode());
bool bIsActive = Object->GetActiveStatus();
StreamSpread.SetCell(ObjectReference, 2, bIsActive);
StreamSpread.SetCell(ObjectReference, 2, BoolToActiveText(bIsActive));
StreamSpread.SetCell(NewRowKey, 2, bIsActive);
StreamSpread.SetCell(NewRowKey, 2, BoolToActiveText(bIsActive));
}


bool IsModelInDeviceStream(const FMobuLiveLink* MobuDevice, const FBModel* Model)
{
return MobuDevice->StreamObjects.Contains((kReference)Model);
for (const TPair<int32, TSharedPtr<IStreamObject>>& StreamPair : MobuDevice->StreamObjects)
{
if (StreamPair.Value->GetModelPointer() == Model)
{
return true;
}
}
return false;
}

void FMobuLiveLinkLayout::EventAddToStream(HISender Sender, HKEvent Event)
Expand All @@ -224,8 +230,9 @@ void FMobuLiveLinkLayout::EventAddToStream(HISender Sender, HKEvent Event)
else if (!IsModelInDeviceStream(LiveLinkDevice, Model))
{
StreamObjectPtr StoreObject = StreamObjectManagement::FBModelToStreamObject(Model, LiveLinkDevice->LiveLinkProvider);
LiveLinkDevice->StreamObjects.Emplace((kReference)Model, StoreObject);
AddSpreadRowFromStreamObject(StoreObject);
int32 NewUID = LiveLinkDevice->GetNextUID();
LiveLinkDevice->StreamObjects.Emplace(NewUID, StoreObject);
AddSpreadRowFromStreamObject(NewUID, StoreObject);
FBTrace("Added New Object to StreamObject\n");

ParentsToIgnore.Emplace(Model);
Expand All @@ -238,19 +245,19 @@ void FMobuLiveLinkLayout::EventAddToStream(HISender Sender, HKEvent Event)
void FMobuLiveLinkLayout::EventRemoveFromStream(HISender Sender, HKEvent Event)
{
int SelectedCount = 0;
TArray<kReference> DeletionObjects;
TArray<int32> DeletionObjects;
DeletionObjects.Reserve(LiveLinkDevice->StreamObjects.Num());
for (const TPair<kReference, StreamObjectPtr>& MapPair : LiveLinkDevice->StreamObjects)
for (const TPair<int32, StreamObjectPtr>& MapPair : LiveLinkDevice->StreamObjects)
{
kReference RowKey = MapPair.Value->GetReference();
int32 RowKey = MapPair.Key;
bool bRowSelected = StreamSpread.GetRow(RowKey).RowSelected;
if (bRowSelected)
{
DeletionObjects.Emplace(RowKey);
SelectedCount++;
}
}
for (const kReference& DeletionKey : DeletionObjects)
for (int32 DeletionKey : DeletionObjects)
{
LiveLinkDevice->StreamObjects.Remove(DeletionKey);
}
Expand Down
8 changes: 4 additions & 4 deletions Source/Private/StreamObjectManagement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,31 @@ TSharedPtr<IStreamObject> StreamObjectManagement::FBModelToStreamObject(FBModel*

TSharedPtr<IStreamObject> StreamObjectManagement::StoreCamera(const FBModel* Model, TSharedPtr<ILiveLinkProvider> LiveLinkProvider)
{
FBTrace("%s is a Camera!\n", *Model->LongName);
FBTrace("%s is a Camera!\n", (const char*)Model->LongName);

TSharedPtr<IStreamObject> CameraStore = MakeShared<FCameraStreamObject>(Model, LiveLinkProvider);
return CameraStore;
}

TSharedPtr<IStreamObject> StreamObjectManagement::StoreLight(const FBModel* Model, TSharedPtr<ILiveLinkProvider> LiveLinkProvider)
{
FBTrace("%s is a Light!\n", *Model->LongName);
FBTrace("%s is a Light!\n", (const char*)Model->LongName);

TSharedPtr<IStreamObject> LightStore = MakeShared<FLightStreamObject>(Model, LiveLinkProvider);
return LightStore;
}

TSharedPtr<IStreamObject> StreamObjectManagement::StoreSkeleton(const FBModel* Model, TSharedPtr<ILiveLinkProvider> LiveLinkProvider)
{
FBTrace("%s is a Skeleton!\n", *Model->LongName);
FBTrace("%s is a Skeleton!\n", (const char*)Model->LongName);

TSharedPtr<IStreamObject> SkeletonStore = MakeShared<FSkeletonHierarchyStreamObject>(Model, LiveLinkProvider);
return SkeletonStore;
}

TSharedPtr<IStreamObject> StreamObjectManagement::StoreGeneric(const FBModel* Model, TSharedPtr<ILiveLinkProvider> LiveLinkProvider)
{
FBTrace("%s is an Unknown Type! - %s\n", *Model->LongName, *((FBModel*)Model)->ClassName());
FBTrace("%s is an Unknown Type! - %s\n", (const char*)Model->LongName, ((FBModel*)Model)->ClassName());

TSharedPtr<IStreamObject> GenericStore = MakeShared<FModelStreamObject>(Model, LiveLinkProvider);
return GenericStore;
Expand Down
2 changes: 1 addition & 1 deletion Source/Public/IStreamObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class IStreamObject

virtual void UpdateActiveStatus(bool bIsNowActive) = 0;

virtual const kReference GetReference() const = 0;
virtual const FBModel* GetModelPointer() const = 0;

virtual const FString GetRootName() const = 0;

Expand Down
6 changes: 5 additions & 1 deletion Source/Public/MobuLiveLinkDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class FMobuLiveLink : public FBDevice

public:
const FString mProviderName = TEXT("Mobu Live Link");
TMap<kReference, TSharedPtr<IStreamObject>> StreamObjects;
TMap<int32, TSharedPtr<IStreamObject>> StreamObjects;

TSharedPtr<ILiveLinkProvider> LiveLinkProvider;

Expand All @@ -77,7 +77,11 @@ class FMobuLiveLink : public FBDevice

FFrameRate CurrentSampleRate;
void UpdateSampleRate();

int32 GetNextUID();
private:
int32 NextUID = 1;

void UpdateStream(); //!< Get latest data and send to unreal

int32 GetCurrentSampleRateIndex();
Expand Down
2 changes: 1 addition & 1 deletion Source/Public/MobuLiveLinkLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class FMobuLiveLinkLayout : public FBDeviceLayout

typedef TSharedPtr<IStreamObject> StreamObjectPtr;

void AddSpreadRowFromStreamObject(StreamObjectPtr Object);
void AddSpreadRowFromStreamObject(int32 NewRowKey, StreamObjectPtr Object);

FBSystem System;
FMobuLiveLink* LiveLinkDevice;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ void FEditorActiveCameraStreamObject::UpdateActiveStatus(bool bIsNowActive)
// Active Status is not changeable on the Editor camera
};

const kReference FEditorActiveCameraStreamObject::GetReference() const
const FBModel* FEditorActiveCameraStreamObject::GetModelPointer() const
{
return (kReference)nullptr;
return nullptr;
};

const FString FEditorActiveCameraStreamObject::GetRootName() const
Expand Down
4 changes: 2 additions & 2 deletions Source/StreamObjects/Private/ModelStreamObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ void FModelStreamObject::UpdateActiveStatus(bool bIsNowActive)
Refresh();
};

const kReference FModelStreamObject::GetReference() const
const FBModel* FModelStreamObject::GetModelPointer() const
{
return (kReference)RootModel;
return RootModel;
};

const FString FModelStreamObject::GetRootName() const
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class FEditorActiveCameraStreamObject : public IStreamObject
bool GetActiveStatus() const final;
void UpdateActiveStatus(bool bIsNowActive) final;

const kReference GetReference() const final;
const FBModel* GetModelPointer() const final;

const FString GetRootName() const final;

Expand Down
2 changes: 1 addition & 1 deletion Source/StreamObjects/Public/ModelStreamObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class FModelStreamObject : public IStreamObject
virtual bool GetActiveStatus() const override;
virtual void UpdateActiveStatus(bool bIsNowActive) override;

virtual const kReference GetReference() const override;
virtual const FBModel* GetModelPointer() const override;

virtual const FString GetRootName() const override;

Expand Down

0 comments on commit f2d7912

Please sign in to comment.