4#include "Kismet/GameplayStatics.h"
5#include "GameFramework/PlayerState.h"
6#include "Net/UnrealNetwork.h"
25 template <
typename DataType>
26 static bool RLEEncodeLine(TArray<DataType>* LineToEncode, TArray<uint8>* EncodedLine);
28 template <
typename DataType>
29 static bool RLEEncodeBuffer(DataType* BufferToEncode, uint32 EncodeLength, TArray<uint8>* EncodedLine);
31 template <
typename DataType>
32 static void RLEDecodeLine(TArray<uint8>* LineToDecode, TArray<DataType>* DecodedLine,
bool bCompressed);
34 template <
typename DataType>
35 static void RLEDecodeLine(
const uint8* LineToDecode, uint32 Num, TArray<DataType>* DecodedLine,
bool bCompressed);
39 template <
typename DataType>
40 static inline void RLEWriteRunFlag(uint32 Count, uint8** loc, TArray<DataType>& Data,
bool bCompressed);
44 : Super(ObjectInitializer)
47 PrimaryComponentTick.bCanEverTick =
true;
48 PrimaryComponentTick.bStartWithTickEnabled =
true;
68bool UVRRenderTargetManager::SendDrawOperations_Validate(
const TArray<FRenderManagerOperation>& RenderOperationStoreList)
73void UVRRenderTargetManager::SendDrawOperations_Implementation(
const TArray<FRenderManagerOperation>& RenderOperationStoreList)
75 if (GetNetMode() == ENetMode::NM_Client)
88 NewOperation.
Color = Color;
89 NewOperation.
P1 = Point1;
90 NewOperation.
P2 = Point2;
91 NewOperation.
Thickness = (uint32)Thickness;
93 if (GetNetMode() < ENetMode::NM_Client)
107 if (!TextureToDisplay)
112 NewOperation.
P1 = Position;
113 NewOperation.
Texture = TextureToDisplay;
115 if (GetNetMode() < ENetMode::NM_Client)
134 NewOperation.
Color = Tris[0].V0_Color.ToFColor(
true);
136 NewOperation.
Tris.AddUninitialized(Tris.Num());
139 for (FCanvasUVTri Tri : Tris)
141 RenderTri.
P1 = Tri.V0_Pos;
142 RenderTri.
P2 = Tri.V1_Pos;
143 RenderTri.
P3 = Tri.V2_Pos;
144 NewOperation.
Tris[Counter++] = RenderTri;
149 if (GetNetMode() < ENetMode::NM_Client)
171 FCanvasLineItem LineItem;
172 LineItem.Origin = FVector(Operation.
P1.X, Operation.
P1.Y, 0.f);
173 LineItem.EndPos = FVector(Operation.
P2.X, Operation.
P2.Y, 0.f);
174 LineItem.LineThickness = (float)Operation.
Thickness;
175 LineItem.SetColor(Operation.
Color.ReinterpretAsLinear());
176 Canvas->DrawItem(LineItem);
183 FCanvasTileItem TileItem(Operation.
P1, Operation.
Texture->Resource, FVector2D(Operation.
Texture->GetSizeX(), Operation.
Texture->GetSizeY()), FVector2D(0, 0), FVector2D(1.f, 1.f),
ClearColor);
184 TileItem.BlendMode = FCanvas::BlendToSimpleElementBlend(EBlendMode::BLEND_Translucent);
185 Canvas->DrawItem(TileItem);
192 FCanvasTriangleItem TriangleItem(FVector2D::ZeroVector, FVector2D::ZeroVector, FVector2D::ZeroVector, NULL);
193 TriangleItem.MaterialRenderProxy = Operation.
Material->GetRenderProxy();
195 FCanvasUVTri triStore;
196 triStore.V0_Color = Operation.
Color;
197 triStore.V1_Color = Operation.
Color;
198 triStore.V2_Color = Operation.
Color;
200 TriangleItem.TriangleList.Reset(Operation.
Tris.Num());
201 TriangleItem.TriangleList.AddUninitialized(Operation.
Tris.Num());
205 triStore.V0_Pos = Tri.P1;
206 triStore.V1_Pos = Tri.P2;
207 triStore.V2_Pos = Tri.P3;
208 TriangleItem.TriangleList[Counter++] = triStore;
211 Canvas->DrawItem(TriangleItem);
222 GetWorld()->GetTimerManager().ClearTimer(
DrawHandle);
226 if (GetNetMode() < ENetMode::NM_Client)
259 if (GetNetMode() == ENetMode::NM_DedicatedServer)
265 UWorld* World = GetWorld();
267 if (!World || !World->bBegunPlay)
271 FTextureRenderTargetResource* RenderTargetResource =
RenderTarget->GameThread_GetRenderTargetResource();
273 if (!RenderTargetResource)
280 UCanvas* CanvasToUse = World->GetCanvasForDrawMaterialToRenderTarget();
283 FCanvas RenderCanvas(
284 RenderTargetResource,
287 World->FeatureLevel);
291 CanvasToUse->Update();
303 RenderCanvas.Flush_GameThread();
306 CanvasToUse->Canvas = NULL;
312 : Super(ObjectInitializer)
314 bOnlyRelevantToOwner =
true;
315 bNetUseOwnerRelevancy =
true;
317 PrimaryActorTick.bCanEverTick =
false;
318 SetReplicateMovement(
false);
344bool ARenderTargetReplicationProxy::SendLocalDrawOperations_Validate(
const TArray<FRenderManagerOperation>& LocalRenderOperationStoreList)
349void ARenderTargetReplicationProxy::SendLocalDrawOperations_Implementation(
const TArray<FRenderManagerOperation>& LocalRenderOperationStoreList)
353 OwningManager->RenderOperationStore.Append(LocalRenderOperationStoreList);
358 for (
int i = (
OwningManager->RenderOperationStore.Num() - LocalRenderOperationStoreList.Num()); i <
OwningManager->RenderOperationStore.Num(); i++)
379void ARenderTargetReplicationProxy::InitTextureSend_Implementation(int32 Width, int32 Height, int32 TotalDataCount, int32 BlobCount, EPixelFormat PixelFormat,
bool bIsZipped)
401bool ARenderTargetReplicationProxy::Ack_InitTextureSend_Validate(int32 TotalDataCount)
406void ARenderTargetReplicationProxy::Ack_InitTextureSend_Implementation(int32 TotalDataCount)
432 if (this->IsPendingKill() || !this->GetOwner() || this->GetOwner()->IsPendingKill())
449 TArray<uint8> BlobStore;
453 BlobStore.AddUninitialized(BlobLen);
458 FMemory::Memcpy(BlobStore.GetData(), MemLoc, BlobLen);
474void ARenderTargetReplicationProxy::GetLifetimeReplicatedProps(TArray< class FLifetimeProperty >& OutLifetimeProps)
const
476 Super::GetLifetimeReplicatedProps(OutLifetimeProps);
483void ARenderTargetReplicationProxy::ReceiveTextureBlob_Implementation(
const TArray<uint8>& TextureBlob, int32 LocationInData, int32 BlobNumber)
488 MemLoc += LocationInData;
489 FMemory::Memcpy(MemLoc, TextureBlob.GetData(), TextureBlob.Num());
517bool ARenderTargetReplicationProxy::Ack_ReceiveTextureBlob_Validate(int32 BlobCount)
522void ARenderTargetReplicationProxy::Ack_ReceiveTextureBlob_Implementation(int32 BlobCount)
531 AActor* myOwner = GetOwner();
544 if (!myOwner->IsNetRelevantFor(
NetRelevancyLog[i].PC.Get(), pawn, pawn->GetActorLocation()))
555 bool bHadDirtyActors =
false;
557 for (FConstPlayerControllerIterator PCIt = GetWorld()->GetPlayerControllerIterator(); PCIt; ++PCIt)
561 if (PC->IsLocalController())
564 if (!PC->HasClientLoadedCurrentWorld())
567 if (
APawn* pawn = PC->GetPawn())
570 if (myOwner->IsNetRelevantFor(PC, pawn, pawn->GetActorLocation()))
574 return Other.PC == PC;
581 FTransform NewTransform = this->GetOwner()->GetActorTransform();
589 UGameplayStatics::FinishSpawningActor(RenderProxy, NewTransform);
594 RenderProxy->AttachToActor(this->GetOwner(), FAttachmentTransformRules::SnapToTargetIncludingScale);
597 ClientRepData.
PC = PC;
601 bHadDirtyActors =
true;
612 bHadDirtyActors =
true;
638 uint8 PixelFormat8 = 0;
640 TArray<FColor> FinalColorData;
649 ColorVal.R = CompColor << 3;
650 ColorVal.G = CompColor >> 5 << 2;
651 ColorVal.B = CompColor >> 11 << 3;
653 FinalColorData[Counter++] = ColorVal;
657 UTexture2D* RenderBase = UTexture2D::CreateTransient(Width, Height, PF_R8G8B8A8);
660 uint8* MipData = (uint8*)RenderBase->PlatformData->Mips[0].BulkData.Lock(LOCK_READ_WRITE);
661 FMemory::Memcpy(MipData, (
void*)FinalColorData.GetData(), FinalColorData.Num() *
sizeof(FColor));
662 RenderBase->PlatformData->Mips[0].BulkData.Unlock();
665 RenderBase->PlatformData->SetNumSlices(1);
666 RenderBase->NeverStream =
true;
667 RenderBase->SRGB =
true;
670 RenderBase->UpdateResource();
698 UWorld* World = GetWorld();
701 FTextureRenderTargetResource* RenderTargetResource =
RenderTarget->GameThread_GetRenderTargetResource();
704 UCanvas* CanvasToUse = World->GetCanvasForDrawMaterialToRenderTarget();
707 FCanvas RenderCanvas(
708 RenderTargetResource,
711 World->FeatureLevel);
715 CanvasToUse->Update();
719 FTexture* RenderTextureResource = (RenderBase) ? RenderBase->Resource : GWhiteTexture;
720 FCanvasTileItem TileItem(FVector2D(0, 0), RenderTextureResource, FVector2D(
RenderTarget->SizeX,
RenderTarget->SizeY), FVector2D(0, 0), FVector2D(1.f, 1.f), FLinearColor::White);
721 TileItem.BlendMode = FCanvas::BlendToSimpleElementBlend(EBlendMode::BLEND_Opaque);
722 CanvasToUse->DrawItem(TileItem);
726 RenderCanvas.Flush_GameThread();
729 CanvasToUse->Canvas = NULL;
732 RenderBase->ReleaseResource();
733 RenderBase->MarkPendingKill();
752 FTextureRenderTargetResource* renderTargetResource =
RenderTarget->GameThread_GetRenderTargetResource();
754 if (!renderTargetResource)
757 renderData->
Size2D = renderTargetResource->GetSizeXY();
760 struct FReadSurfaceContext {
761 FRenderTarget* SrcRenderTarget;
762 TArray<FColor>* OutData;
764 FReadSurfaceDataFlags Flags;
768 FReadSurfaceContext readSurfaceContext =
770 renderTargetResource,
772 FIntRect(0,0,renderTargetResource->GetSizeXY().X, renderTargetResource->GetSizeXY().Y),
773 FReadSurfaceDataFlags(RCM_UNorm, CubeFace_MAX)
776 ENQUEUE_RENDER_COMMAND(SceneDrawCompletion)(
777 [readSurfaceContext](FRHICommandListImmediate& RHICmdList) {
778 RHICmdList.ReadSurfaceData(
779 readSurfaceContext.SrcRenderTarget->GetRenderTargetTexture(),
780 readSurfaceContext.Rect,
781 *readSurfaceContext.OutData,
782 readSurfaceContext.Flags
792 this->SetComponentTickEnabled(
true);
797 Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
802 SetComponentTickEnabled(
false);
816 uint32 SizeOfData = nextRenderData->
ColorData.Num();
825 for (FColor col : nextRenderData->
ColorData)
827 ColorVal = (col.R >> 3) << 11 | (col.G >> 2) << 5 | (col.B >> 3);
831 FIntPoint Size2D = nextRenderData->
Size2D;
845 delete nextRenderData;
873 if (GetNetMode() < ENetMode::NM_Client)
879 Super::EndPlay(EndPlayReason);
892 if (GetNetMode() < ENetMode::NM_Client)
896 GetWorld()->GetTimerManager().ClearTimer(
DrawHandle);
906 RepData.PC =
nullptr;
908 if (RepData.ReplicationProxy.IsValid() && !RepData.ReplicationProxy->IsPendingKill())
910 RepData.ReplicationProxy->Destroy();
913 RepData.ReplicationProxy.Reset();
920 if (this->GetNetMode() == ENetMode::NM_DedicatedServer)
925 UWorld* World = GetWorld();
958 FBoxSphereBounds LocalBounds = PrimToBoxCheck->CalcLocalBounds();
959 FVector Center = LocalBounds.Origin;
960 FVector Extent = LocalBounds.BoxExtent;
963 FTransform LocalTrans = PrimToBoxCheck->GetComponentTransform() * WorldTransformOfPlane.Inverse();
965 FVector BoxMin = Center - Extent;
966 FVector BoxMax = Center + Extent;
968 TArray<FVector> PointList;
969 PointList.AddUninitialized(8);
971 PointList[0] = LocalTrans.TransformPosition(BoxMin);
972 PointList[1] = LocalTrans.TransformPosition(BoxMax);
973 PointList[2] = LocalTrans.TransformPosition(FVector(BoxMin.X, BoxMin.Y, BoxMax.Z));
974 PointList[3] = LocalTrans.TransformPosition(FVector(BoxMin.X, BoxMax.Y, BoxMin.Z));
975 PointList[4] = LocalTrans.TransformPosition(FVector(BoxMax.X, BoxMin.Y, BoxMin.Z));
976 PointList[5] = LocalTrans.TransformPosition(FVector(BoxMin.X, BoxMax.Y, BoxMax.Z));
977 PointList[6] = LocalTrans.TransformPosition(FVector(BoxMax.X, BoxMin.Y, BoxMax.Z));
978 PointList[7] = LocalTrans.TransformPosition(FVector(BoxMax.X, BoxMax.Y, BoxMin.Z));
997 TArray<FVector2D> IntersectionPoints;
999 FVector Intersection;
1002 FVector2D HalfPlane = PlaneSize / 2.f;
1006 int CenterCount = 0;
1007 for (
int i = 0; i < 24; i += 2)
1010 if (UKismetMathLibrary::LinePlaneIntersection(PointList[EdgeList[i]], PointList[EdgeList[i + 1]], LocalProjectionPlane, Time, Intersection))
1013 PlanePoint = Intersection;
1017 NewPt.X = ((PlanePoint.X + HalfPlane.X) / PlaneSize.X) *
RenderTarget->SizeX;
1018 NewPt.Y = ((PlanePoint.Y + HalfPlane.Y) / PlaneSize.Y) *
RenderTarget->SizeY;
1026 IntersectionPoints.Add(NewPt);
1032 if (IntersectionPoints.Num() <= 2)
1038 PtCenter /= CenterCount;
1041 struct FPointSortCompare
1044 FVector2D CenterPoint;
1045 FPointSortCompare(
const FVector2D& InCenterPoint)
1046 : CenterPoint(InCenterPoint)
1051 FORCEINLINE
bool operator()(
const FVector2D& A,
const FVector2D& B)
const
1053 if (A.Y - CenterPoint.X >= 0 && B.X - CenterPoint.X < 0)
1055 if (A.X - CenterPoint.X < 0 && B.X - CenterPoint.X >= 0)
1057 if (A.X - CenterPoint.X == 0 && B.X - CenterPoint.X == 0) {
1058 if (A.Y - CenterPoint.Y >= 0 || B.Y - CenterPoint.Y >= 0)
1064 int det = (A.X - CenterPoint.X) * (B.Y - CenterPoint.Y) - (B.X - CenterPoint.X) * (A.Y - CenterPoint.Y);
1072 int d1 = (A.X - CenterPoint.X) * (A.X - CenterPoint.X) + (A.Y - CenterPoint.Y) * (A.Y - CenterPoint.Y);
1073 int d2 = (B.X - CenterPoint.X) * (B.X - CenterPoint.X) + (B.Y - CenterPoint.Y) * (B.Y - CenterPoint.Y);
1078 IntersectionPoints.Sort(FPointSortCompare(PtCenter));
1081 Tri.V0_Color = UVColor;
1082 Tri.V1_Color = UVColor;
1083 Tri.V2_Color = UVColor;
1085 OutTris.Reserve(IntersectionPoints.Num() - 2);
1088 for (
int i = 1; i < IntersectionPoints.Num() - 1; i++)
1090 Tri.V0_Pos = IntersectionPoints[0];
1091 Tri.V1_Pos = IntersectionPoints[i];
1092 Tri.V2_Pos = IntersectionPoints[i + 1];
1104 TArray<uint8> TmpPacked;
1123if (TmpPacked.Num() > 512)
1125 FArchiveSaveCompressedProxy Compressor(
PackedData, NAME_Zlib, COMPRESS_BiasSpeed);
1126 Compressor << TmpPacked;
1165 TArray<uint8> RLEEncodedData;
1166 FArchiveLoadCompressedProxy DataArchive(
PackedData, NAME_Zlib);
1167 DataArchive << RLEEncodedData;
1168 RLE_Funcs::RLEDecodeLine<uint16>(&RLEEncodedData, &
UnpackedData,
true);
1187 Ar.SerializeIntPacked(
Width);
1188 Ar.SerializeIntPacked(
Height);
1202template <
typename DataType>
1205 if (!LineToDecode || !DecodedLine)
1208 RLEDecodeLine(LineToDecode->GetData(), LineToDecode->Num(), DecodedLine, bCompressed);
1212template <
typename DataType>
1213void RLE_Funcs::RLEDecodeLine(
const uint8* LineToDecode, uint32 Num, TArray<DataType>* DecodedLine,
bool bCompressed)
1217 DecodedLine->Empty(Num /
sizeof(DataType));
1218 DecodedLine->AddUninitialized(Num /
sizeof(DataType));
1219 FMemory::Memcpy(DecodedLine->GetData(), LineToDecode, Num);
1223 const uint8* StartLoc = LineToDecode;
1224 const uint8* EndLoc = StartLoc + Num;
1225 uint8 incr =
sizeof(DataType);
1227 DataType ValToWrite = *((DataType*)LineToDecode);
1229 DecodedLine->Empty();
1237 for (
const uint8* loc = StartLoc; loc < EndLoc;)
1239 RLE_FLAG = *loc >> 4;
1243 case RLE_Flags::RLE_CompressedByte:
1245 Length8 = (*loc & ~0xF0) + 1;
1247 ValToWrite = *((DataType*)loc);
1250 origLoc = DecodedLine->AddUninitialized(Length8);
1252 for (uint32 i = origLoc; i < origLoc + Length8; i++)
1254 (*DecodedLine)[i] = ValToWrite;
1258 case RLE_Flags::RLE_CompressedShort:
1260 Length16 = (((uint16)(*loc & ~0xF0)) << 8 | (*(loc + 1))) + 1;
1262 ValToWrite = *((DataType*)loc);
1265 origLoc = DecodedLine->AddUninitialized(Length16);
1267 for (uint32 i = origLoc; i < origLoc + Length16; i++)
1269 (*DecodedLine)[i] = ValToWrite;
1273 case RLE_Flags::RLE_Compressed24:
1275 Length32 = (((uint32)(*loc & ~0xF0)) << 16 | ((uint32)(*(loc + 1))) << 8 | (uint32)(*(loc + 2))) + 1;
1277 ValToWrite = *((DataType*)loc);
1280 origLoc = DecodedLine->AddUninitialized(Length32);
1282 for (uint32 i = origLoc; i < origLoc + Length32; i++)
1284 (*DecodedLine)[i] = ValToWrite;
1289 case RLE_Flags::RLE_NotCompressedByte:
1291 Length8 = (*loc & ~0xF0) + 1;
1294 origLoc = DecodedLine->AddUninitialized(Length8);
1296 for (uint32 i = origLoc; i < origLoc + Length8; i++)
1298 (*DecodedLine)[i] = *((DataType*)loc);
1303 case RLE_Flags::RLE_NotCompressedShort:
1305 Length16 = (((uint16)(*loc & ~0xF0)) << 8 | (*(loc + 1))) + 1;
1308 origLoc = DecodedLine->AddUninitialized(Length16);
1310 for (uint32 i = origLoc; i < origLoc + Length16; i++)
1312 (*DecodedLine)[i] = *((DataType*)loc);
1317 case RLE_Flags::RLE_NotCompressed24:
1319 Length32 = (((uint32)(*loc & ~0xF0)) << 16 | ((uint32)(*(loc + 1))) << 8 | ((uint32)(*(loc + 2)))) + 1;
1322 origLoc = DecodedLine->AddUninitialized(Length32);
1324 for (uint32 i = origLoc; i < origLoc + Length32; i++)
1326 (*DecodedLine)[i] = *((DataType*)loc);
1332 case RLE_Flags::RLE_ContinueRunByte:
1334 Length8 = (*loc & ~0xF0) + 1;
1337 origLoc = DecodedLine->AddUninitialized(Length8);
1339 for (uint32 i = origLoc; i < origLoc + Length8; i++)
1341 (*DecodedLine)[i] = ValToWrite;
1345 case RLE_Flags::RLE_ContinueRunShort:
1347 Length16 = (((uint16)(*loc & ~0xF0)) << 8 | (*(loc + 1))) + 1;
1350 origLoc = DecodedLine->AddUninitialized(Length16);
1352 for (uint32 i = origLoc; i < origLoc + Length16; i++)
1354 (*DecodedLine)[i] = ValToWrite;
1358 case RLE_Flags::RLE_ContinueRun24:
1360 Length32 = (((uint32)(*loc & ~0xF0)) << 16 | ((uint32)(*(loc + 1))) << 8 | (*(loc + 2))) + 1;
1363 origLoc = DecodedLine->AddUninitialized(Length32);
1365 for (uint32 i = origLoc; i < origLoc + Length32; i++)
1367 (*DecodedLine)[i] = ValToWrite;
1376template <
typename DataType>
1379 return RLEEncodeBuffer<DataType>(LineToEncode->GetData(), LineToEncode->Num(), EncodedLine);
1386 **loc = (((uint8)RLE_Flags::RLE_ContinueRunByte << 4) | ((uint8)count - 1));
1389 else if (count <= 4096)
1391 uint16 val = ((((uint16)RLE_Flags::RLE_ContinueRunShort) << 12) | ((uint16)count - 1));
1399 uint32 val = ((((uint32)RLE_Flags::RLE_ContinueRun24) << 20) | ((uint32)count - 1));
1400 **loc = (uint8)(val >> 16);
1402 **loc = (uint8)(val >> 8);
1409template <
typename DataType>
1417 val = ((((uint8)RLE_Flags::RLE_CompressedByte) << 4) | ((uint8)count - 1));
1419 val = ((((uint8)RLE_Flags::RLE_NotCompressedByte) << 4) | ((uint8)count - 1));
1424 else if (count <= 4096)
1428 val = ((((uint16)RLE_Flags::RLE_CompressedShort) << 12) | ((uint16)count - 1));
1430 val = ((((uint16)RLE_Flags::RLE_NotCompressedShort) << 12) | ((uint16)count - 1));
1432 **loc = (uint8)(val >> 8);
1441 val = ((((uint32)RLE_Flags::RLE_Compressed24) << 20) | ((uint32)count - 1));
1443 val = ((((uint32)RLE_Flags::RLE_NotCompressed24) << 20) | ((uint32)count - 1));
1445 **loc = (uint8)(val >> 16);
1447 **loc = (uint8)(val >> 8);
1449 **loc = (uint8)(val);
1453 FMemory::Memcpy(*loc, Data.GetData(), Data.Num() *
sizeof(DataType));
1454 *loc += Data.Num() *
sizeof(DataType);
1458template <
typename DataType>
1461 uint32 OrigNum = EncodeLength;
1462 uint8 incr =
sizeof(DataType);
1463 uint32 MAX_COUNT = 1048576;
1465 EncodedLine->Empty((OrigNum *
sizeof(DataType)) + (OrigNum * (
sizeof(short))));
1468 EncodedLine->AddUninitialized((OrigNum *
sizeof(DataType)) + ((OrigNum / MAX_COUNT * 3)));
1470 DataType*
First = BufferToEncode;
1472 uint32 RunCount = 0;
1474 uint8* loc = EncodedLine->GetData();
1477 bool bInRun =
false;
1478 bool bWroteStart =
false;
1479 bool bContinueRun =
false;
1481 TArray<DataType> TempBuffer;
1482 TempBuffer.Reserve(256);
1483 uint32 TempCount = 0;
1488 for (uint32 i = 0; i < OrigNum - 1; i++,
First++)
1492 if (bWroteStart && !bInRun)
1495 bWroteStart =
false;
1498 if (bInRun && TempCount < MAX_COUNT)
1502 if (TempCount == MAX_COUNT)
1512 bContinueRun =
true;
1519 bWroteStart =
false;
1520 bContinueRun =
false;
1522 TempBuffer.Add(Last);
1543 bContinueRun =
false;
1547 if (bWroteStart && TempCount < MAX_COUNT)
1550 TempBuffer.Add(Last);
1552 else if (bWroteStart && TempCount == MAX_COUNT)
1557 TempBuffer.Add(Last);
1562 TempBuffer.Add(Last);
1576 if (TempCount <= MAX_COUNT)
1578 if (TempCount == MAX_COUNT)
1582 bContinueRun =
true;
1601 if (bWroteStart && TempCount <= MAX_COUNT)
1603 if (TempCount == MAX_COUNT)
1611 TempBuffer.Add(Last);
1617 uint32 Wrote = loc - EncodedLine->GetData();
1618 EncodedLine->RemoveAt(Wrote, EncodedLine->Num() - Wrote,
true);
1625 if (Wrote > OrigNum * incr)
1627 EncodedLine->Empty(OrigNum * incr);
1628 EncodedLine->AddUninitialized(OrigNum * incr);
1629 FMemory::Memcpy(EncodedLine->GetData(), BufferToEncode, OrigNum * incr);
1636template<
int32 ScaleFactor,
int32 MaxBitsPerComponent>
1639 check(Ar.IsSaving());
1642 Value *= ScaleFactor;
1645 if (Value.ContainsNaN())
1647 logOrEnsureNanError(TEXT(
"WritePackedVector2D: Value contains NaN, clearing for safety."));
1648 FVector2D Dummy(0, 0);
1649 WritePackedVector2D<ScaleFactor, MaxBitsPerComponent>(Dummy, Ar);
1653 float MinV = -1073741824.0f;
1654 float MaxV = 1073741760.0f;
1657 const FVector2D ClampedValue = FVector2D(FMath::Clamp(Value.X, MinV, MaxV), FMath::Clamp(Value.Y, MinV, MaxV));
1658 bool bClamp = ClampedValue != Value;
1661 int32 IntX = FMath::RoundToInt(ClampedValue.X);
1662 int32 IntY = FMath::RoundToInt(ClampedValue.Y);
1664 uint32 Bits = FMath::Clamp<uint32>(FMath::CeilLogTwo(1 + FMath::Max(FMath::Abs(IntX), FMath::Abs(IntY))), 1, MaxBitsPerComponent) - 1;
1667 Ar.SerializeInt(Bits, MaxBitsPerComponent);
1669 int32 Bias = 1 << (Bits + 1);
1670 uint32
Max = 1 << (Bits + 2);
1671 uint32 DX = IntX + Bias;
1672 uint32 DY = IntY + Bias;
1674 if (DX >=
Max) { bClamp =
true; DX =
static_cast<int32
>(DX) > 0 ?
Max - 1 : 0; }
1675 if (DY >=
Max) { bClamp =
true; DY =
static_cast<int32
>(DY) > 0 ?
Max - 1 : 0; }
1677 Ar.SerializeInt(DX,
Max);
1678 Ar.SerializeInt(DY,
Max);
1683template<u
int32 ScaleFactor,
int32 MaxBitsPerComponent>
1689 Ar.SerializeInt(Bits, MaxBitsPerComponent);
1691 int32 Bias = 1 << (Bits + 1);
1692 uint32
Max = 1 << (Bits + 2);
1696 Ar.SerializeInt(DX,
Max);
1697 Ar.SerializeInt(DY,
Max);
1700 float fact = (float)ScaleFactor;
1702 Value.X = (float)(
static_cast<int32
>(DX) - Bias) / fact;
1703 Value.Y = (float)(
static_cast<int32
>(DY) - Bias) / fact;
1713 Ar.SerializeIntPacked(
OwnerID);
1725 bOutSuccess &= WritePackedVector2D<1, 20>(
P1, Ar);
1726 bOutSuccess &= WritePackedVector2D<1, 20>(
P2, Ar);
1730 ReadPackedVector2D<1, 20>(
P1, Ar);
1731 ReadPackedVector2D<1, 20>(
P2, Ar);
1740 bOutSuccess &= WritePackedVector2D<1, 20>(
P1, Ar);
1744 ReadPackedVector2D<1, 20>(
P1, Ar);
1752 uint32 ArrayCt =
Tris.Num();
1753 Ar.SerializeIntPacked(ArrayCt);
1757 Tris.Reset(ArrayCt);
1758 Tris.AddUninitialized(ArrayCt);
1761 for (uint32 i = 0; i < ArrayCt; ++i)
1763 ReadPackedVector2D<1, 20>(TriTemp.
P1, Ar);
1764 ReadPackedVector2D<1, 20>(TriTemp.
P2, Ar);
1765 ReadPackedVector2D<1, 20>(TriTemp.
P3, Ar);
1771 for (uint32 i = 0; i < ArrayCt; ++i)
1773 WritePackedVector2D<1, 20>(
Tris[i].
P1, Ar);
1774 WritePackedVector2D<1, 20>(
Tris[i].
P2, Ar);
1775 WritePackedVector2D<1, 20>(
Tris[i].P3, Ar);
bool WritePackedVector2D(FVector2D Value, FArchive &Ar)
bool ReadPackedVector2D(FVector2D &Value, FArchive &Ar)
UCLASS(ClassGroup = (VRExpansionPlugin))
FTimerHandle SendTimer_Handle
int32 MaxBytesPerSecondRate
UPROPERTY()
void InitTextureSend(int32 Width, int32 Height, int32 TotalDataCount, int32 BlobCount, EPixelFormat PixelFormat, bool bIsZipped)
UFUNCTION(Reliable, Client)
int32 BlobNum
UPROPERTY(Transient)
FBPVRReplicatedTextureStore TextureStore
UPROPERTY(Transient)
int32 TextureBlobSize
UPROPERTY()
TWeakObjectPtr< UVRRenderTargetManager > OwningManager
UPROPERTY(Replicated, ReplicatedUsing = OnRep_Manager)
void ReceiveTextureBlob(const TArray< uint8 > &TextureBlob, int32 LocationInData, int32 BlobCount)
UFUNCTION(Reliable, Client)
void OnRep_Manager()
UFUNCTION()
void SendNextDataBlob()
UFUNCTION()
void Ack_InitTextureSend(int32 TotalDataCount)
UFUNCTION(Reliable, Server, WithValidation)
uint32 OwnersID
UPROPERTY(Replicated)
ARenderTargetReplicationProxy(const FObjectInitializer &ObjectInitializer=FObjectInitializer::Get())
void Ack_ReceiveTextureBlob(int32 BlobCount)
UFUNCTION(Reliable, Server, WithValidation)
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override
float DrawRate
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "RenderTargetManager")
bool bIsLoadingTextureBuffer
UPROPERTY(Transient)
UCanvasRenderTarget2D * RenderTarget
UPROPERTY(BlueprintReadOnly, VisibleAnywhere, Category = "RenderTargetManager")
TArray< FRenderManagerOperation > LocalRenderOperationStore
bool GenerateTrisFromBoxPlaneIntersection(UPrimitiveComponent *PrimToBoxCheck, FTransform WorldTransformOfPlane, const FPlane &LocalProjectionPlane, FVector2D PlaneSize, FColor UVColor, TArray< FCanvasUVTri > &OutTris)
UFUNCTION(BlueprintCallable, Category = "VRRenderTargetManager|UtilityFunctions")
int32 TextureBlobSize
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "RenderTargetManager")
virtual void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction) override
void AddTextureDrawOperation(FVector2D Position, UTexture2D *TextureToDisplay)
UFUNCTION(BlueprintCallable, Category = "VRRenderTargetManager|DrawingFunctions")
void AddMaterialTrianglesDrawOperation(TArray< FCanvasUVTri > Tris, UMaterial *Material)
UFUNCTION(BlueprintCallable, Category = "VRRenderTargetManager|DrawingFunctions")
bool bIsStoringImage
UPROPERTY(Transient)
int32 MaxBytesPerSecondRate
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "RenderTargetManager")
FBPVRReplicatedTextureStore RenderTargetStore
UPROPERTY(Transient)
FTimerHandle DrawHandle
UPROPERTY()
TArray< FClientRepData > NetRelevancyLog
UPROPERTY(Transient)
TWeakObjectPtr< ARenderTargetReplicationProxy > LocalProxy
UPROPERTY(Transient)
FColor ClearColor
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "RenderTargetManager")
int32 RenderTargetHeight
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "RenderTargetManager")
UVRRenderTargetManager(const FObjectInitializer &ObjectInitializer)
TArray< FRenderManagerOperation > RenderOperationStore
bool bInitiallyReplicateTexture
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "RenderTargetManager")
void DrawOperation(UCanvas *Canvas, const FRenderManagerOperation &Operation)
float PollRelevancyTime
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "RenderTargetManager")
void SendDrawOperations(const TArray< FRenderManagerOperation > &RenderOperationStoreList)
UFUNCTION(Reliable, NetMultiCast, WithValidation)
TQueue< FRenderDataStore * > RenderDataQueue
void UpdateRelevancyMap()
void DrawPoll()
UFUNCTION()
bool DeCompressRenderTarget2D()
FTimerHandle NetRelevancyTimer_Handle
virtual void BeginPlay() override
int32 RenderTargetWidth
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "RenderTargetManager")
void AddLineDrawOperation(FVector2D Point1, FVector2D Point2, FColor Color, int32 Thickness)
UFUNCTION(BlueprintCallable, Category = "VRRenderTargetManager|DrawingFunctions")
static void RLEWriteContinueFlag(uint32 Count, uint8 **loc)
static void RLEWriteRunFlag(uint32 Count, uint8 **loc, TArray< DataType > &Data, bool bCompressed)
static void RLEDecodeLine(TArray< uint8 > *LineToDecode, TArray< DataType > *DecodedLine, bool bCompressed)
static bool RLEEncodeLine(TArray< DataType > *LineToEncode, TArray< uint8 > *EncodedLine)
static bool RLEEncodeBuffer(DataType *BufferToEncode, uint32 EncodeLength, TArray< uint8 > *EncodedLine)
USTRUCT(BlueprintType, Category = "VRExpansionLibrary")
TArray< uint16 > UnpackedData
UPROPERTY(Transient)
TArray< uint8 > PackedData
UPROPERTY(Transient)
bool bIsZipped
UPROPERTY(Transient)
bool NetSerialize(FArchive &Ar, class UPackageMap *Map, bool &bOutSuccess)
uint32 Width
UPROPERTY(Transient)
bool bIsRelevant
UPROPERTY()
TWeakObjectPtr< APlayerController > PC
UPROPERTY()
TWeakObjectPtr< ARenderTargetReplicationProxy > ReplicationProxy
UPROPERTY()
FRenderCommandFence RenderFence
TArray< FColor > ColorData
ERenderManagerOperationType OperationType
UPROPERTY()
TSoftObjectPtr< UTexture2D > Texture
UPROPERTY()
TSoftObjectPtr< UMaterial > Material
UPROPERTY()
uint32 Thickness
UPROPERTY()
uint32 OwnerID
UPROPERTY()
bool NetSerialize(FArchive &Ar, class UPackageMap *Map, bool &bOutSuccess)
TArray< FRenderManagerTri > Tris
UPROPERTY()