Files
UnrealEngineUWP/Engine/Source/Editor/UnrealEd/Public/RayTracingDebugVisualizationMenuCommands.h
henrik karlsson b11d35f80e [UnrealEd]
* Reverted the changes in 25904929 related to subclasses to TCommands<>.

This code relies on undefined behavior of how things are inlined. base class is a template with a static variable. One instance of that static variable exists in each dll/exe. To call TCommands<>::Get() would return the instance in the same dll.
But, because the subclass has dllexport on the type and not the members it will generate a Get function that is not inlined. The callsite when calling Get will actually then use the instantiated Get() function and not the inlined one.

So for

class API X : public TCommands<X> {}

it will (for now) work to call

X::Get() and get the same instantiated singletone.

Calling

TCommands<X>::Get() will definitely not work and return the singleton instantiated in the same dll/exe

#rb none

[CL 25909947 by henrik karlsson in ue5-main branch]
2023-06-09 23:42:49 -04:00

55 lines
1.5 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "Containers/Map.h"
#include "UObject/NameTypes.h"
#include "Templates/SharedPointer.h"
#include "Framework/Commands/UICommandInfo.h"
#include "Framework/MultiBox/MultiBoxBuilder.h"
#include "Framework/Commands/Commands.h"
class FEditorViewportClient;
class UNREALED_API FRayTracingDebugVisualizationMenuCommands : public TCommands<FRayTracingDebugVisualizationMenuCommands>
{
public:
struct FRayTracingDebugVisualizationRecord
{
uint32 Index;
FName Name;
TSharedPtr<FUICommandInfo> Command;
FRayTracingDebugVisualizationRecord()
: Index(0),
Name(),
Command()
{
}
};
FRayTracingDebugVisualizationMenuCommands();
static void BuildVisualisationSubMenu(FMenuBuilder& Menu);
virtual void RegisterCommands() override;
void BindCommands(FUICommandList& CommandList, const TSharedPtr<FEditorViewportClient>& Client) const;
static bool DebugModeShouldBeTonemapped(const FName& RayTracingDebugModeName);
private:
void BuildCommandMap();
void CreateRayTracingDebugVisualizationCommands();
void AddRayTracingDebugVisualizationCommandsToMenu(FMenuBuilder& menu) const;
static void ChangeRayTracingDebugVisualizationMode(TWeakPtr<FEditorViewportClient> WeakClient, FName InName);
static bool IsRayTracingDebugVisualizationModeSelected(TWeakPtr<FEditorViewportClient> WeakClient, FName InName);
TArray<FRayTracingDebugVisualizationRecord> RayTracingDebugVisualizationCommands;
static TArray<FText> RayTracingDebugModeNames;
};