Yasiu Math 1
Collection of mathematic functions that help create game mechanics and procedural tools
Loading...
Searching...
No Matches
YasiuMathLogs.h
1#pragma once
2
3
4#define RunVerb Log
5#define CompVerb Log
6
7
8#include "CoreMinimal.h"
9#include "Runtime/Launch/Resources/Version.h"
10
11
12DECLARE_LOG_CATEGORY_EXTERN(YasiuMathPlugin, Log, Log);
13
14
15FString ReadObName( const class UObject* ob );
16
17FString ReadObName( const class AActor* act );
18
19FString ReadObName( const class UActorComponent* cmp );
20
21#if ENGINE_MAJOR_VERSION == 5 && ENGINE_MINOR_VERSION <= 1
22#include "Logging/LogMacros.h"
23
24template<typename T>
25FString ToFString( const T& Val )
26{
27 if constexpr ( TIsPointer<T>::Value && TIsDerivedFrom<T, UObject>::Value ) {
28 return Val ? Val->GetName() : TEXT("nullptr");
29 }
30 else if constexpr ( TIsEnum<T>::Value ) {
31 return FString::Printf(TEXT("%d "), static_cast<int>(Val)); // cast enum to int
32 }
33 else {
34 return FString::Printf(TEXT("%s "), *LexToString(Val));
35 }
36}template<typename ... Args>
37FString BuildLogMessage( const FString& Msg, Args&& ... args )
38{
39 TArray<FString> Parts = {ToFString(args) ...};
40 return Msg + TEXT(", Values: ") + FString::Join(Parts, TEXT(", "));
41}
42
43#define YASIUMATHLOG(LogVerb, LogMsg) \
44do { \
45UE_LOG(YasiuMathPlugin, LogVerb, TEXT(LogMsg)); \
46} while(0)
47
48#define YASIUMATHLOG_MULTI(LogVerb, LogMsg, ...) \
49do { \
50const FString FormattedMsg = FString::Format(TEXT("{0} {1}"), { ReadObName(this), LogMsg }); \
51const FString MessageWithValues = BuildLogMessage(FormattedMsg, __VA_ARGS__);\
52UE_LOG(YasiuMathPlugin, LogVerb, TEXT("%s"), *MessageWithValues); \
53} while(0)
54#else
55#include "Logging/StructuredLog.h"
56
57#define YASIUMATHLOG(LogVerb, LogMsg) \
58UE_LOGFMT(YasiuMathPlugin, LogVerb, "{nm}({funcName}) " LogMsg, \
59ReadObName(this), \
60__FUNCTION__)
61
62#define YASIUMATHLOG_MULTI(LogVerb, LogMsg, ...) \
63UE_LOGFMT(YasiuMathPlugin, LogVerb, "{nm}({funcName}) " LogMsg, \
64ReadObName(this), \
65__FUNCTION__ \
66, __VA_ARGS__)
67#endif