Skip to content

Commit a08a68c

Browse files
authored
updated source for ue5.4.4 (#308)
1 parent 9dce510 commit a08a68c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+260
-569
lines changed

Source/RapyutaSimulationPlugins/Private/Core/RRActorCommon.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#include "Core/RRSceneDirector.h"
1616
#include "Core/RRThreadUtils.h"
1717
#include "Core/RRUObjectUtils.h"
18+
#include "RapyutaSimulationPlugins.h"
19+
1820

1921
void URRSceneInstance::ConfigureStaticClasses()
2022
{

Source/RapyutaSimulationPlugins/Private/Core/RRAssetUtils.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
// Copyright 2020-2023 Rapyuta Robotics Co., Ltd.
22
#include "Core/RRAssetUtils.h"
33

4+
// Native
5+
#include <type_traits>
6+
47
// UE
58
#include "CoreMinimal.h"
69

10+
11+
12+
// Ensure RAPYUTA_SIM_DEBUG is defined before usage
13+
#ifndef RAPYUTA_SIM_DEBUG
14+
#define RAPYUTA_SIM_DEBUG 0 // Default to 0 if undefined
15+
#endif
16+
17+
718
#if WITH_EDITOR
819
#include "BlueprintCompilationManager.h"
920
#include "PackageHelperFunctions.h"
@@ -18,7 +29,7 @@
1829
#include "Core/RRGameSingleton.h"
1930
#include "Core/RRThreadUtils.h"
2031

21-
using URRBlueprint = typename TChooseClass<WITH_EDITOR, UBlueprint, UBlueprintGeneratedClass>::Result;
32+
using URRBlueprint = typename std::conditional<WITH_EDITOR, UBlueprint, UBlueprintGeneratedClass>::type;
2233

2334
UClass* URRAssetUtils::FindBlueprintClass(const FString& InBlueprintClassName)
2435
{
@@ -58,11 +69,11 @@ UClass* URRAssetUtils::FindBlueprintClass(const FString& InBlueprintClassName)
5869
{
5970
if (auto* bp = Cast<URRBlueprint>(InAssetData.GetAsset()))
6071
{
61-
if constexpr (TIsSame<URRBlueprint, UBlueprint>::Value)
72+
if constexpr (std::is_same<URRBlueprint, UBlueprint>::value)
6273
{
6374
foundBPClass = Cast<UBlueprint>(bp)->GeneratedClass;
6475
}
65-
else if constexpr (TIsSame<URRBlueprint, UBlueprintGeneratedClass>::Value)
76+
else if constexpr (std::is_same<URRBlueprint, UBlueprintGeneratedClass>::value)
6677
{
6778
foundBPClass = Cast<UClass>(bp);
6879
}

Source/RapyutaSimulationPlugins/Private/Core/RRBaseActor.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include "Core/RRGameState.h"
99
#include "Core/RRPlayerController.h"
1010
#include "Core/RRUObjectUtils.h"
11+
#include "RapyutaSimulationPlugins.h"
12+
1113

1214
TMap<UClass*, TUniquePtr<std::once_flag>> ARRBaseActor::OnceFlagList;
1315
std::once_flag ARRBaseActor::OnceFlag;

Source/RapyutaSimulationPlugins/Private/Core/RRCamera.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#include "Core/RRMathUtils.h"
1313
#include "Core/RRMeshActor.h"
1414
#include "Core/RRUObjectUtils.h"
15+
#include "RapyutaSimulationPlugins.h"
16+
1517

1618
ARRCamera::ARRCamera()
1719
{

Source/RapyutaSimulationPlugins/Private/Core/RRCoreUtils.cpp

Lines changed: 11 additions & 173 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77
#include "HAL/PlatformProcess.h"
88
#include "IESConverter.h"
99
#include "ImageUtils.h"
10-
#include "TextureCompiler.h"
1110
#if WITH_EDITOR
1211
#include "Factories/TextureFactory.h"
13-
#include "ThumbnailRendering/ThumbnailManager.h"
1412
#endif
1513

1614
// RapyutaSimulationPlugins
@@ -26,6 +24,9 @@
2624
#include "Core/RRThreadUtils.h"
2725
#include "Core/RRTypeUtils.h"
2826
#include "Core/RRUObjectUtils.h"
27+
#include "RapyutaSimulationPlugins.h"
28+
29+
2930

3031
IImageWrapperModule* URRCoreUtils::SImageWrapperModule = nullptr;
3132
TMap<ERRFileType, TSharedPtr<IImageWrapper>> URRCoreUtils::SImageWrappers;
@@ -303,6 +304,12 @@ bool URRCoreUtils::CheckWithTimeOut(const TFunctionRef<bool()>& InCondition,
303304
//
304305
UTexture2D* URRCoreUtils::LoadImageToTexture(const FString& InFullFilePath, const FString& InTextureName, const bool bInSaveToAsset)
305306
{
307+
if (InTextureName.IsEmpty())
308+
{
309+
UE_LOG_WITH_INFO_SHORT(LogRapyutaCore, Error, TEXT("Image path [%s] - InTextureName is empty"));
310+
return nullptr;
311+
}
312+
306313
if (bInSaveToAsset)
307314
{
308315
#if WITH_EDITOR
@@ -316,7 +323,7 @@ UTexture2D* URRCoreUtils::LoadImageToTexture(const FString& InFullFilePath, cons
316323
// Save [texture] to uasset file on disk, logged here-in
317324
return URRAssetUtils::SavePackageToAsset(texturePkg, texture) ? texture : nullptr;
318325
#else
319-
UE_LOG_WITH_INFO(LogTemp, Error, TEXT("Texture saving to uasset is Editor-only feature"));
326+
UE_LOG_WITH_INFO_SHORT(LogRapyutaCore, Error, TEXT("Texture saving to uasset is Editor-only feature"));
320327
return nullptr;
321328
#endif
322329
}
@@ -333,6 +340,7 @@ UTexture2D* URRCoreUtils::LoadImageToTexture(const FString& InFullFilePath, cons
333340
texture = FImageUtils::ImportFileAsTexture2D(InFullFilePath);
334341
if (texture)
335342
{
343+
texture = FImageUtils::ImportFileAsTexture2D(InFullFilePath);
336344
texture->Rename(*InTextureName);
337345
}
338346
return texture;
@@ -487,173 +495,3 @@ bool URRCoreUtils::LoadIESProfilesFromFolder(const FString& InFolderPath,
487495

488496
return bResult;
489497
}
490-
491-
// -------------------------------------------------------------------------------------------------------------------------
492-
// GRAPHICS UTILS --
493-
//
494-
#if WITH_EDITOR
495-
bool URRCoreUtils::RenderThumbnail(UObject* InObject,
496-
uint32 InImageWidth,
497-
uint32 InImageHeight,
498-
const ThumbnailTools::EThumbnailTextureFlushMode::Type InFlushMode,
499-
FObjectThumbnail* OutThumbnail)
500-
{
501-
// Renderer must be initialized before generating thumbnails
502-
if (!ensure(FApp::CanEverRender()))
503-
{
504-
return false;
505-
}
506-
if (!ensure(GIsRHIInitialized))
507-
{
508-
return false;
509-
}
510-
511-
// Get the rendering info for this object
512-
FThumbnailRenderingInfo* renderInfo = UThumbnailManager::Get().GetRenderingInfo(InObject);
513-
if ((nullptr == renderInfo) || (nullptr == renderInfo->Renderer))
514-
{
515-
UE_LOG_WITH_INFO_SHORT(LogRapyutaCore,
516-
Error,
517-
TEXT("[ThumbnailManager] No rendering info found for class [%s]"),
518-
*InObject->GetClass()->GetName());
519-
return false;
520-
}
521-
522-
if (false == renderInfo->Renderer->CanVisualizeAsset(InObject))
523-
{
524-
UE_LOG_WITH_INFO_SHORT(LogRapyutaCore,
525-
Error,
526-
TEXT("[%s] cannot be visualized, probably due to invalid rendering resource"),
527-
*InObject->GetName());
528-
return false;
529-
}
530-
531-
// Thumbnail size
532-
if (OutThumbnail)
533-
{
534-
OutThumbnail->SetImageSize(InImageWidth, InImageHeight);
535-
}
536-
537-
// Create a static texture render target, as commonly used for all thumbnails
538-
static UTextureRenderTarget2D* sThumbnailRenderTarget = []()
539-
{
540-
// Create thumbnail render target
541-
UTextureRenderTarget2D* renderTarget = NewObject<UTextureRenderTarget2D>(GetTransientPackage());
542-
renderTarget->AddToRoot();
543-
renderTarget->ClearColor = FLinearColor::Transparent;
544-
renderTarget->TargetGamma = GEngine->GetDisplayGamma();
545-
renderTarget->RenderTargetFormat = RTF_RGBA8;
546-
return renderTarget;
547-
}();
548-
sThumbnailRenderTarget->InitAutoFormat(InImageWidth, InImageHeight);
549-
auto* renderTargetResource = sThumbnailRenderTarget->GameThread_GetRenderTargetResource();
550-
551-
// Create a canvas for the render target and clear it to black
552-
FCanvas canvas(renderTargetResource, nullptr, FGameTime::GetTimeSinceAppStart(), GMaxRHIFeatureLevel);
553-
canvas.Clear(FLinearColor::Transparent);
554-
555-
// Wait for all textures to be streamed in before rendering the thumbnail
556-
// @todo CB: This helps but doesn't 100% guarantee fully-streamed-in resources!
557-
if (ThumbnailTools::EThumbnailTextureFlushMode::AlwaysFlush == InFlushMode)
558-
{
559-
if (GShaderCompilingManager)
560-
{
561-
GShaderCompilingManager->ProcessAsyncResults(false, true);
562-
}
563-
564-
if (UTexture* texture = Cast<UTexture>(InObject))
565-
{
566-
FTextureCompilingManager::Get().FinishCompilation({texture});
567-
}
568-
569-
FlushAsyncLoading();
570-
IStreamingManager::Get().StreamAllResources(100.f);
571-
}
572-
573-
// Make sure we suppress any message dialogs that might result from constructing
574-
// or initializing any of the renderable objects.
575-
{
576-
TGuardValue<bool> Unattended(GIsRunningUnattendedScript, true);
577-
578-
// Draw thumbnail onto [canvas]
579-
renderInfo->Renderer->Draw(
580-
InObject, 0, 0, InImageWidth, InImageHeight, renderTargetResource, &canvas, false /*bAdditionalViewFamily*/);
581-
}
582-
583-
// Flush [canvas], tell rendering thread to finish drawing batched elements
584-
canvas.Flush_GameThread();
585-
{
586-
ENQUEUE_RENDER_COMMAND(UpdateThumbnailRTCommand)
587-
(
588-
[renderTargetResource](FRHICommandListImmediate& RHICmdList) {
589-
TransitionAndCopyTexture(
590-
RHICmdList, renderTargetResource->GetRenderTargetTexture(), renderTargetResource->TextureRHI, {});
591-
});
592-
593-
if (OutThumbnail)
594-
{
595-
const FIntRect thumbnailRect(0, 0, OutThumbnail->GetImageWidth(), OutThumbnail->GetImageHeight());
596-
TArray<uint8>& outThumbnailData = OutThumbnail->AccessImageData();
597-
598-
outThumbnailData.Empty();
599-
outThumbnailData.AddUninitialized(OutThumbnail->GetImageWidth() * OutThumbnail->GetImageHeight() * sizeof(FColor));
600-
601-
// Read remote texture's contents (GPU) back to system memory (CPU)
602-
renderTargetResource->ReadPixelsPtr((FColor*)outThumbnailData.GetData(), FReadSurfaceDataFlags(), thumbnailRect);
603-
}
604-
}
605-
return true;
606-
}
607-
#endif
608-
609-
bool URRCoreUtils::GenerateThumbnail(UObject* InObject, uint32 InImageWidth, uint32 InImageHeight, const FString& InSaveImagePath)
610-
{
611-
if (IsRunningCommandlet() && !IsAllowCommandletRendering())
612-
{
613-
UE_LOG_WITH_INFO_SHORT(
614-
LogRapyutaCore,
615-
Warning,
616-
TEXT("[%s] is running without [-AllowCommandletRendering], thus unable to generate [%s]'s thumbnail!"),
617-
*GetRunningCommandletClass()->GetName(),
618-
*InObject->GetName());
619-
return false;
620-
}
621-
#if WITH_EDITOR
622-
FObjectThumbnail thumbnail;
623-
// Already logged here-in
624-
if (false == URRCoreUtils::RenderThumbnail(
625-
InObject, InImageWidth, InImageHeight, ThumbnailTools::EThumbnailTextureFlushMode::AlwaysFlush, &thumbnail))
626-
{
627-
return false;
628-
}
629-
630-
// Ref: FImageUtils::ThumbnailCompressImageArray()
631-
#if RAPYUTA_SIM_DEBUG
632-
FColor* thumbnailColorData = (FColor*)thumbnail.AccessImageData().GetData();
633-
// Thumbnails are saved as RGBA but FColors are stored as BGRA. An option to swap the order upon compression may be added at
634-
// some point. At the moment, manually swapping Red and Blue
635-
for (int32 i = 0; i < InImageWidth * InImageHeight; ++i)
636-
{
637-
Swap(thumbnailColorData[i].R, thumbnailColorData[i].B);
638-
}
639-
#endif
640-
641-
// Compress thumbnail data & save to disk
642-
thumbnail.CompressImageData();
643-
if (FFileHelper::SaveArrayToFile(thumbnail.AccessCompressedImageData(), *InSaveImagePath))
644-
{
645-
UE_LOG_WITH_INFO_SHORT(
646-
LogRapyutaCore, Log, TEXT("[%s]'s thumbnail has been saved to file [%s]"), *InObject->GetName(), *InSaveImagePath);
647-
return true;
648-
}
649-
else
650-
{
651-
UE_LOG_WITH_INFO_SHORT(
652-
LogRapyutaCore, Error, TEXT("Failed saving [%s]'s thumbnail to file [%s]"), *InObject->GetName(), *InSaveImagePath);
653-
return false;
654-
}
655-
#else
656-
UE_LOG_WITH_INFO_SHORT(LogRapyutaCore, Error, TEXT("Editor-only API"));
657-
return false;
658-
#endif
659-
}

Source/RapyutaSimulationPlugins/Private/Core/RRCrowdROSController.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
// RapyutaSimulationPlugins
55
#include "Robots/RRBaseRobot.h"
66
#include "Robots/RRRobotROS2Interface.h"
7+
#include "RapyutaSimulationPlugins.h"
8+
79

810
void ARRCrowdROSController::OnPossess(APawn* InPawn)
911
{

Source/RapyutaSimulationPlugins/Private/Core/RRGameInstance.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include "Core/RRGameMode.h"
88
#include "Core/RRGameSingleton.h"
99
#include "Core/RRMathUtils.h"
10+
#include "logUtilities.h"
11+
1012

1113
FString URRGameInstance::SMapName;
1214
void URRGameInstance::PreloadContentForURL(FURL InURL)

Source/RapyutaSimulationPlugins/Private/Core/RRGameMode.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include "Core/RRGameState.h"
1515
#include "Core/RRPlayerController.h"
1616
#include "Tools/RRROS2ClockPublisher.h"
17+
#include "logUtilities.h"
18+
1719

1820
ARRGameMode::ARRGameMode()
1921
{

Source/RapyutaSimulationPlugins/Private/Core/RRGameSingleton.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
// RapyutaSim
66
#include "Core/RRPakLoader.h"
77
#include "Core/RRTypeUtils.h"
8+
#include "logUtilities.h"
9+
810

911
TMap<ERRResourceDataType, TArray<const TCHAR*>> URRGameSingleton::SASSET_OWNING_MODULE_NAMES = {
1012
// Only required for statically loaded UASSET
@@ -25,12 +27,6 @@ URRGameSingleton::URRGameSingleton()
2527
#if RAPYUTA_SIM_VERBOSE
2628
UE_LOG_WITH_INFO(LogRapyutaCore, Display, TEXT("INSTANTIATED! ======================"));
2729
#endif
28-
// Prepare an empty [ResourceMap]
29-
for (uint8 i = (static_cast<uint8>(ERRResourceDataType::NONE) + 1); i < static_cast<uint8>(ERRResourceDataType::TOTAL); ++i)
30-
{
31-
const ERRResourceDataType dataType = static_cast<ERRResourceDataType>(i);
32-
ResourceMap.Add(dataType, FRRResourceInfo(dataType));
33-
}
3430
}
3531

3632
URRGameSingleton::~URRGameSingleton()
@@ -98,6 +94,13 @@ URRGameSingleton* URRGameSingleton::Get()
9894

9995
bool URRGameSingleton::InitializeResources(bool bInRequestResourceLoading)
10096
{
97+
// Prepare an empty [ResourceMap]
98+
for (uint8 i = (static_cast<uint8>(ERRResourceDataType::NONE) + 1); i < static_cast<uint8>(ERRResourceDataType::TOTAL); ++i)
99+
{
100+
const ERRResourceDataType dataType = static_cast<ERRResourceDataType>(i);
101+
ResourceMap.Add(dataType, FRRResourceInfo(dataType));
102+
}
103+
101104
// Initialize PakLoader (only available in packaged Sim)
102105
#if WITH_EDITOR
103106
bPakLoaderInitialized = false;

Source/RapyutaSimulationPlugins/Private/Core/RRGameState.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
#include "Core/RRROS2GameMode.h"
1919
#include "Core/RRSceneDirector.h"
2020
#include "Core/RRUObjectUtils.h"
21+
#include "logUtilities.h"
22+
#include "Core/RRGameMode.h"
23+
2124

2225
ARRGameState::ARRGameState()
2326
{

0 commit comments

Comments
 (0)