Skip to content
Snippets Groups Projects
Commit a2976462 authored by Sebastian Pape's avatar Sebastian Pape
Browse files

Rewriting Dasher Sync

parent a6342d9e
No related branches found
No related tags found
1 merge request!2Backporting many features from the study on top of the Dasher3D-Core
...@@ -4,16 +4,14 @@ ...@@ -4,16 +4,14 @@
#include "Brushes/SlateColorBrush.h" #include "Brushes/SlateColorBrush.h"
#include "Rendering/DrawElements.h" #include "Rendering/DrawElements.h"
#include "DasherInterface.h" #include "DasherInterface.h"
#include "IDisplayCluster.h" #include "IDisplayCluster.h"
#include "Cluster/DisplayClusterClusterEvent.h" #include "Cluster/DisplayClusterClusterEvent.h"
#include "Cluster/IDisplayClusterClusterManager.h" #include "Cluster/IDisplayClusterClusterManager.h"
#include "Utility/RWTHVRUtilities.h"
#include "Components/SlateWrapperTypes.h" #include "Components/SlateWrapperTypes.h"
#include "Framework/Application/SlateApplication.h" #include "Framework/Application/SlateApplication.h"
#include "Serialization/BufferArchive.h"
#include "Serialization/BufferWriter.h"
#include "Utility/RWTHVRUtilities.h"
BEGIN_SLATE_FUNCTION_BUILD_OPTIMIZATION BEGIN_SLATE_FUNCTION_BUILD_OPTIMIZATION
...@@ -48,6 +46,18 @@ FReply SDasherWidget::HandleMouseMoveEvent(const FGeometry& Geometry, const FPoi ...@@ -48,6 +46,18 @@ FReply SDasherWidget::HandleMouseMoveEvent(const FGeometry& Geometry, const FPoi
if (CurrentlyUsingVectorInput) return FReply::Unhandled(); if (CurrentlyUsingVectorInput) return FReply::Unhandled();
//The mouse event only contains the Screen Space Position //The mouse event only contains the Screen Space Position
CursorPosition = Geometry.AbsoluteToLocal(MouseEvent.GetScreenSpacePosition()); CursorPosition = Geometry.AbsoluteToLocal(MouseEvent.GetScreenSpacePosition());
if(URWTHVRUtilities::IsRoomMountedMode())
{
FDisplayClusterClusterEventJson ClusterEvent;
ClusterEvent.Category = "Dasher";
ClusterEvent.Type = "Input";
ClusterEvent.Name = "MouseMove";
ClusterEvent.Parameters.Add("X", FString::SanitizeFloat(CursorPosition.X));
ClusterEvent.Parameters.Add("Y", FString::SanitizeFloat(CursorPosition.Y));
IDisplayCluster::Get().GetClusterMgr()->EmitClusterEventJson(ClusterEvent, false);
return FReply::Handled().ReleaseMouseLock();
}
} }
return FReply::Handled(); return FReply::Handled();
} }
...@@ -56,6 +66,16 @@ FReply SDasherWidget::HandleMouseDownEvent(const FGeometry& Geometry, const FPoi ...@@ -56,6 +66,16 @@ FReply SDasherWidget::HandleMouseDownEvent(const FGeometry& Geometry, const FPoi
{ {
if (!InputPaused) if (!InputPaused)
{ {
if(URWTHVRUtilities::IsRoomMountedMode())
{
FDisplayClusterClusterEventJson ClusterEvent;
ClusterEvent.Category = "Dasher";
ClusterEvent.Type = "Input";
ClusterEvent.Name = "MouseDown";
IDisplayCluster::Get().GetClusterMgr()->EmitClusterEventJson(ClusterEvent, false);
return FReply::Handled().ReleaseMouseLock();
}
if (CurrentlyUsingVectorInput) if (CurrentlyUsingVectorInput)
{ {
CurrentlyUsingVectorInput = false; CurrentlyUsingVectorInput = false;
...@@ -69,6 +89,16 @@ FReply SDasherWidget::HandleMouseDownEvent(const FGeometry& Geometry, const FPoi ...@@ -69,6 +89,16 @@ FReply SDasherWidget::HandleMouseDownEvent(const FGeometry& Geometry, const FPoi
FReply SDasherWidget::HandleMouseUpEvent(const FGeometry& Geometry, const FPointerEvent& MouseEvent) FReply SDasherWidget::HandleMouseUpEvent(const FGeometry& Geometry, const FPointerEvent& MouseEvent)
{ {
if(URWTHVRUtilities::IsRoomMountedMode())
{
FDisplayClusterClusterEventJson ClusterEvent;
ClusterEvent.Category = "Dasher";
ClusterEvent.Type = "Input";
ClusterEvent.Name = "MouseUp";
IDisplayCluster::Get().GetClusterMgr()->EmitClusterEventJson(ClusterEvent, false);
return FReply::Handled().ReleaseMouseLock();
}
if (CurrentlyUsingVectorInput) if (CurrentlyUsingVectorInput)
{ {
CurrentlyUsingVectorInput = false; CurrentlyUsingVectorInput = false;
...@@ -82,8 +112,19 @@ FReply SDasherWidget::HandleMouseUpEvent(const FGeometry& Geometry, const FPoint ...@@ -82,8 +112,19 @@ FReply SDasherWidget::HandleMouseUpEvent(const FGeometry& Geometry, const FPoint
FReply SDasherWidget::HandleMouseDoubleClickEvent(const FGeometry& Geometry, const FPointerEvent& MouseEvent) FReply SDasherWidget::HandleMouseDoubleClickEvent(const FGeometry& Geometry, const FPointerEvent& MouseEvent)
{ {
if (!InputPaused) if (!InputPaused)
{ {
if(URWTHVRUtilities::IsRoomMountedMode())
{
FDisplayClusterClusterEventJson ClusterEvent;
ClusterEvent.Category = "Dasher";
ClusterEvent.Type = "Input";
ClusterEvent.Name = "MouseDown";
IDisplayCluster::Get().GetClusterMgr()->EmitClusterEventJson(ClusterEvent, false);
return FReply::Handled().ReleaseMouseLock();
}
if (CurrentlyUsingVectorInput) if (CurrentlyUsingVectorInput)
{ {
CurrentlyUsingVectorInput = false; CurrentlyUsingVectorInput = false;
...@@ -111,9 +152,36 @@ bool SDasherWidget::GetScreenCoords(screenint& iX, screenint& iY, Dasher::CDashe ...@@ -111,9 +152,36 @@ bool SDasherWidget::GetScreenCoords(screenint& iX, screenint& iY, Dasher::CDashe
return true; return true;
} }
void SDasherWidget::HandleClusterEvent(const FDisplayClusterClusterEventJson& Event)
{
if(Event.Category != "Dasher") return;
if(Event.Type == "Input")
{
if(Event.Name == "MouseUp")
{
DasherMainInterface->KeyUp(FDateTime::Now().GetSecond() + FDateTime::Now().GetMillisecond(), Dasher::Keys::Primary_Input);
MouseUpListeners.ExecuteIfBound();
} else
if(Event.Name == "MouseDown")
{
DasherMainInterface->KeyDown(FDateTime::Now().GetSecond() + FDateTime::Now().GetMillisecond(), Dasher::Keys::Primary_Input);
MouseDownListeners.ExecuteIfBound();
} else
if(Event.Name == "MouseMove")
{
CursorPosition.X = FCString::Atod(*Event.Parameters["X"]);
CursorPosition.Y = FCString::Atod(*Event.Parameters["Y"]);
}
} else
if(Event.Type == "Tick")
{
double currentTime = FCString::Atod(*Event.Parameters["Time"]);
DasherMainInterface->Tick(static_cast<unsigned long>(currentTime * 1000.0));
}
}
void SDasherWidget::InputVector(const FVector2D InputVector) void SDasherWidget::InputVector(const FVector2D InputVector)
{ {
if (!URWTHVRUtilities::IsPrimaryNode()) return;
if (!InputPaused) { if (!InputPaused) {
if (!CurrentlyUsingVectorInput) return; if (!CurrentlyUsingVectorInput) return;
CursorPosition = DasherMainInterface->ConvertDasher2Screen(Dasher::CDasherModel::ORIGIN_X, Dasher::CDasherModel::ORIGIN_Y) CursorPosition = DasherMainInterface->ConvertDasher2Screen(Dasher::CDasherModel::ORIGIN_X, Dasher::CDasherModel::ORIGIN_Y)
...@@ -123,7 +191,6 @@ void SDasherWidget::InputVector(const FVector2D InputVector) ...@@ -123,7 +191,6 @@ void SDasherWidget::InputVector(const FVector2D InputVector)
void SDasherWidget::InputButton(bool Pressed) void SDasherWidget::InputButton(bool Pressed)
{ {
if (!URWTHVRUtilities::IsPrimaryNode()) return;
if (!InputPaused) { if (!InputPaused) {
CurrentlyUsingVectorInput = true; CurrentlyUsingVectorInput = true;
if (Pressed) if (Pressed)
...@@ -136,42 +203,6 @@ void SDasherWidget::InputButton(bool Pressed) ...@@ -136,42 +203,6 @@ void SDasherWidget::InputButton(bool Pressed)
} }
} }
void SDasherWidget::HandleClusterEvent(const FDisplayClusterClusterEventBinary& Event)
{
if(!URWTHVRUtilities::IsPrimaryNode()) UE_LOG(LogTemp, Log, TEXT("Non Primary Receive"));
FMemoryReader r(Event.EventData);
BackBuffer->Empty();
r << NDisplayBuffer;
GeometryType t;
bool readError = false;
while(!r.AtEnd() && !readError)
{
r << t;
switch (t)
{
case GeometryType::Rectangle:
BackBuffer->Add(FFilledRect::Deserialize(r));
break;
case GeometryType::Writing:
BackBuffer->Add(FWriting::Deserialize(r));
break;
case GeometryType::PolyLine:
BackBuffer->Add(FPolyLine::Deserialize(r));
break;
default:
readError = true;
break;
}
}
std::swap(FrontBuffer, BackBuffer);
BackBuffer->Empty();
}
//The construction of the Dasher Widget, Dasher parameters are set here, a function to set them outside is not provided, but can be easily implemented //The construction of the Dasher Widget, Dasher parameters are set here, a function to set them outside is not provided, but can be easily implemented
void SDasherWidget::Construct(const FArguments& InArgs) void SDasherWidget::Construct(const FArguments& InArgs)
{ {
...@@ -202,13 +233,13 @@ void SDasherWidget::Construct(const FArguments& InArgs) ...@@ -202,13 +233,13 @@ void SDasherWidget::Construct(const FArguments& InArgs)
if (ClusterManager && !ClusterEvent.IsBound()) if (ClusterManager && !ClusterEvent.IsBound())
{ {
ClusterEvent = ClusterEvent =
FOnClusterEventBinaryListener::CreateSP(this, &SDasherWidget::HandleClusterEvent); FOnClusterEventJsonListener::CreateSP(this, &SDasherWidget::HandleClusterEvent);
ClusterManager->AddClusterEventBinaryListener(ClusterEvent); ClusterManager->AddClusterEventJsonListener(ClusterEvent);
} }
//Set up the Event Handlers for Mouse Movement etc.
if (URWTHVRUtilities::IsPrimaryNode()) if (URWTHVRUtilities::IsPrimaryNode())
{ {
//Set up the Event Handlers for Mouse Movement etc.
SetOnMouseMove(FPointerEventHandler::CreateLambda([this](const FGeometry& Geometry, const FPointerEvent& MouseEvent) {return HandleMouseMoveEvent(Geometry, MouseEvent); })); SetOnMouseMove(FPointerEventHandler::CreateLambda([this](const FGeometry& Geometry, const FPointerEvent& MouseEvent) {return HandleMouseMoveEvent(Geometry, MouseEvent); }));
SetOnMouseButtonDown(FPointerEventHandler::CreateLambda([this](const FGeometry& Geometry, const FPointerEvent& MouseEvent) {return HandleMouseDownEvent(Geometry, MouseEvent); })); SetOnMouseButtonDown(FPointerEventHandler::CreateLambda([this](const FGeometry& Geometry, const FPointerEvent& MouseEvent) {return HandleMouseDownEvent(Geometry, MouseEvent); }));
SetOnMouseButtonUp(FPointerEventHandler::CreateLambda([this](const FGeometry& Geometry, const FPointerEvent& MouseEvent) {return HandleMouseUpEvent(Geometry, MouseEvent); })); SetOnMouseButtonUp(FPointerEventHandler::CreateLambda([this](const FGeometry& Geometry, const FPointerEvent& MouseEvent) {return HandleMouseUpEvent(Geometry, MouseEvent); }));
...@@ -269,12 +300,22 @@ int32 SDasherWidget::OnPaint(const FPaintArgs& Args, const FGeometry& AllottedGe ...@@ -269,12 +300,22 @@ int32 SDasherWidget::OnPaint(const FPaintArgs& Args, const FGeometry& AllottedGe
//The tick function, we tick dasher in it and update the screen size for dasher //The tick function, we tick dasher in it and update the screen size for dasher
void SDasherWidget::Tick(const FGeometry& AllotedGeometry, const double InCurrentTime, const float InDeltaTime) { void SDasherWidget::Tick(const FGeometry& AllotedGeometry, const double InCurrentTime, const float InDeltaTime) {
//don't tick in the editor
if (!IsEditor && !InputPaused && URWTHVRUtilities::IsPrimaryNode()) {
SCompoundWidget::Tick(AllotedGeometry, InCurrentTime, InDeltaTime); SCompoundWidget::Tick(AllotedGeometry, InCurrentTime, InDeltaTime);
DasherMainInterface->Tick(static_cast<unsigned long>(InCurrentTime * 1000.0)); //we need to provide ticks in milliseconds //don't tick in the editor
if (!IsEditor && !InputPaused && !URWTHVRUtilities::IsPrimaryNode()) return;
if(!URWTHVRUtilities::IsRoomMountedMode()){
DasherMainInterface->Tick(static_cast<unsigned long>(InCurrentTime * 1000.0)); //we need to provide ticks in milliseconds
}
else
{
FDisplayClusterClusterEventJson ClusterEvent;
ClusterEvent.Category = "Dasher";
ClusterEvent.Type = "Tick";
ClusterEvent.Parameters.Add("Time", FString::SanitizeFloat(InCurrentTime));
IDisplayCluster::Get().GetClusterMgr()->EmitClusterEventJson(ClusterEvent, false);
}
//This probably doesn't have to be done every tick, but it does not seem to have a huge hit on performance //This probably doesn't have to be done every tick, but it does not seem to have a huge hit on performance
const FGeometry Geometry = GetTickSpaceGeometry(); const FGeometry Geometry = GetTickSpaceGeometry();
...@@ -287,7 +328,6 @@ void SDasherWidget::Tick(const FGeometry& AllotedGeometry, const double InCurren ...@@ -287,7 +328,6 @@ void SDasherWidget::Tick(const FGeometry& AllotedGeometry, const double InCurren
if (Width && Height) DasherMainInterface->ScreenResized(this); if (Width && Height) DasherMainInterface->ScreenResized(this);
} }
} }
}
std::pair<SDasherWidget::screenint, SDasherWidget::screenint> SDasherWidget::TextSize(CDasherScreen::Label* Label, unsigned Size) std::pair<SDasherWidget::screenint, SDasherWidget::screenint> SDasherWidget::TextSize(CDasherScreen::Label* Label, unsigned Size)
{ {
...@@ -298,25 +338,6 @@ std::pair<SDasherWidget::screenint, SDasherWidget::screenint> SDasherWidget::Tex ...@@ -298,25 +338,6 @@ std::pair<SDasherWidget::screenint, SDasherWidget::screenint> SDasherWidget::Tex
//Double Buffers are rotated here. //Double Buffers are rotated here.
void SDasherWidget::Display() { void SDasherWidget::Display() {
// if (URWTHVRUtilities::IsRoomMountedMode())
// {
// auto start = std::chrono::high_resolution_clock::now();
// FDisplayClusterClusterEventBinary BinaryClusterEvent;
// BinaryClusterEvent.EventData.Reserve(100000); // 100kb of data
// FMemoryWriter m(BinaryClusterEvent.EventData);
// m << NDisplayBuffer;
// for(auto& e : *BackBuffer)
// {
// e->Serialize(m);
// }
// IDisplayCluster::Get().GetClusterMgr()->EmitClusterEventBinary(BinaryClusterEvent, false);
// }
// else
// {
std::swap(FrontBuffer, BackBuffer); std::swap(FrontBuffer, BackBuffer);
BackBuffer->Empty(); BackBuffer->Empty();
...@@ -332,7 +353,6 @@ void SDasherWidget::Display() { ...@@ -332,7 +353,6 @@ void SDasherWidget::Display() {
CharacterEnteredFlag = false; CharacterEnteredFlag = false;
CharacterDeletedFlag = false; CharacterDeletedFlag = false;
// }
} }
//Functions for Drawing //Functions for Drawing
...@@ -388,13 +408,12 @@ void SDasherWidget::Polygon(CDasherScreen::point* points, int number, const Dash ...@@ -388,13 +408,12 @@ void SDasherWidget::Polygon(CDasherScreen::point* points, int number, const Dash
//We pass through the contents of the dasher buffer //We pass through the contents of the dasher buffer
FString SDasherWidget::GetBuffer() const FString SDasherWidget::GetBuffer() const
{ {
return (URWTHVRUtilities::IsPrimaryNode()) ? DasherMainInterface->GetBuffer() : NDisplayBuffer; return DasherMainInterface->GetBuffer();
} }
void SDasherWidget::ResetBuffer() void SDasherWidget::ResetBuffer()
{ {
DasherMainInterface->ResetBuffer(); DasherMainInterface->ResetBuffer();
NDisplayBuffer = "";
} }
void SDasherWidget::StartTraining(FString PathToTextFile) void SDasherWidget::StartTraining(FString PathToTextFile)
......
...@@ -5,11 +5,9 @@ ...@@ -5,11 +5,9 @@
#include <utility> #include <utility>
#include "DasherInterface.h" #include "DasherInterface.h"
#include "Cluster/DisplayClusterClusterEvent.h"
#include "Math/Vector2D.h" #include "Math/Vector2D.h"
#include "Fonts/FontMeasure.h" #include "Fonts/FontMeasure.h"
#include "Widgets/DeclarativeSyntaxSupport.h" #include "Widgets/DeclarativeSyntaxSupport.h"
#include "Cluster/IDisplayClusterClusterManager.h" #include "Cluster/IDisplayClusterClusterManager.h"
//using namespace Dasher; //using namespace Dasher;
...@@ -36,24 +34,8 @@ struct FFilledRect : DasherDrawGeometry { ...@@ -36,24 +34,8 @@ struct FFilledRect : DasherDrawGeometry {
FVector2D top; FVector2D top;
FVector2D bottom; FVector2D bottom;
FLinearColor color; FLinearColor color;
void Serialize(FMemoryWriter& ar)
{
ar << Type;
ar << top;
ar << bottom;
ar << color;
}
static TUniquePtr<DasherDrawGeometry> Deserialize(FMemoryReader& ar)
{
TUniquePtr<FFilledRect> g = MakeUnique<FFilledRect>();
ar << g->top;
ar << g->bottom;
ar << g->color;
return g;
}
FFilledRect(FVector2D Top, FVector2D Bottom, FLinearColor Color) : DasherDrawGeometry(GeometryType::Rectangle), top(Top), bottom(Bottom), color(Color) {} FFilledRect(FVector2D Top, FVector2D Bottom, FLinearColor Color) : DasherDrawGeometry(GeometryType::Rectangle), top(Top), bottom(Bottom), color(Color) {}
FFilledRect() : DasherDrawGeometry(GeometryType::Rectangle) {}
}; };
struct FWriting : DasherDrawGeometry{ struct FWriting : DasherDrawGeometry{
...@@ -62,26 +44,7 @@ struct FWriting : DasherDrawGeometry{ ...@@ -62,26 +44,7 @@ struct FWriting : DasherDrawGeometry{
int size; int size;
FLinearColor color; FLinearColor color;
void Serialize(FMemoryWriter& ar)
{
ar << Type;
ar << pos;
ar << size;
ar << color;
ar << label;
}
static TUniquePtr<DasherDrawGeometry> Deserialize(FMemoryReader& ar)
{
TUniquePtr<FWriting> g = MakeUnique<FWriting>();
ar << g->pos;
ar << g->size;
ar << g->color;
ar << g->label;
return g;
}
FWriting(FString Label, FVector2D Pos, int Size, FLinearColor Color) : DasherDrawGeometry(GeometryType::Writing), label(Label), pos(Pos), size(Size), color(Color) {} FWriting(FString Label, FVector2D Pos, int Size, FLinearColor Color) : DasherDrawGeometry(GeometryType::Writing), label(Label), pos(Pos), size(Size), color(Color) {}
FWriting() : DasherDrawGeometry(GeometryType::Writing) {}
}; };
struct FPolyLine : DasherDrawGeometry{ struct FPolyLine : DasherDrawGeometry{
...@@ -90,26 +53,7 @@ struct FPolyLine : DasherDrawGeometry{ ...@@ -90,26 +53,7 @@ struct FPolyLine : DasherDrawGeometry{
bool AntiAliasing; bool AntiAliasing;
FLinearColor color; FLinearColor color;
void Serialize(FMemoryWriter& ar)
{
ar << Type;
ar << points;
ar << linewidth;
ar << AntiAliasing;
ar << color;
}
static TUniquePtr<DasherDrawGeometry> Deserialize(FMemoryReader& ar)
{
TUniquePtr<FPolyLine> g = MakeUnique<FPolyLine>();
ar << g->points;
ar << g->linewidth;
ar << g->AntiAliasing;
ar << g->color;
return g;
}
FPolyLine(TArray<FVector2D> Points, float LineWidth, FLinearColor Color, bool AntiAliasing): DasherDrawGeometry(GeometryType::PolyLine), points(Points), linewidth(LineWidth), AntiAliasing(AntiAliasing), color(Color) {} FPolyLine(TArray<FVector2D> Points, float LineWidth, FLinearColor Color, bool AntiAliasing): DasherDrawGeometry(GeometryType::PolyLine), points(Points), linewidth(LineWidth), AntiAliasing(AntiAliasing), color(Color) {}
FPolyLine(): DasherDrawGeometry(GeometryType::PolyLine) {}
}; };
DECLARE_DELEGATE(FDasherMouseUpDelegate); DECLARE_DELEGATE(FDasherMouseUpDelegate);
...@@ -158,8 +102,6 @@ public: ...@@ -158,8 +102,6 @@ public:
virtual void Display() override; virtual void Display() override;
virtual void SendMarker(int imarker) override {}
virtual bool IsPointVisible(screenint x, screenint y) override { return true; } virtual bool IsPointVisible(screenint x, screenint y) override { return true; }
//Pass-me-down returning Buffer //Pass-me-down returning Buffer
...@@ -184,9 +126,10 @@ public: ...@@ -184,9 +126,10 @@ public:
virtual bool GetScreenCoords(screenint& iX, screenint& iY, Dasher::CDasherView* pView) override; virtual bool GetScreenCoords(screenint& iX, screenint& iY, Dasher::CDasherView* pView) override;
void HandleClusterEvent(const FDisplayClusterClusterEventJson& Event);
void InputVector(FVector2D InputVector); void InputVector(FVector2D InputVector);
void InputButton(bool Pressed); void InputButton(bool Pressed);
void HandleClusterEvent(const FDisplayClusterClusterEventBinary& Event);
FVector2D GetCursorPosition(); FVector2D GetCursorPosition();
//Allows to Pause Input //Allows to Pause Input
...@@ -224,9 +167,8 @@ private: ...@@ -224,9 +167,8 @@ private:
//set up the font measure service to ... measure fonts. //set up the font measure service to ... measure fonts.
TSharedPtr<FSlateFontMeasure> FontMeasureService; TSharedPtr<FSlateFontMeasure> FontMeasureService;
private: //CAVE Sync
FString NDisplayBuffer = ""; FOnClusterEventJsonListener ClusterEvent;
FOnClusterEventBinaryListener ClusterEvent;
protected: protected:
// stores color information // stores color information
......
Subproject commit 015b8c82fab747de4ff98de27ac177fcac6ddbfc Subproject commit f6211ff1ad2e6aaf3a0ecf7ecb58aec610893b52
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment