Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
FrameNumber.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreTypes.h"
6#include "Math/NumericLimits.h"
7#include "Math/UnrealMathUtility.h"
8#include "Templates/EnableIf.h"
9#include "Templates/UnrealTypeTraits.h"
10
11class FArchive;
12template <typename NumericType> struct TNumericLimits;
13
14/**
15 * Typesafe 32-bit signed frame number. Defined in this way to prevent erroneous float->int conversions and afford type-safe operator overloading.
16 */
18{
19 constexpr FFrameNumber()
20 : Value(0)
21 {}
22
23 /**
24 * Implicit construction from a signed integer frame number, whilst disallowing any construction from other types.
25 */
26 template<typename T, typename U = typename TEnableIf<std::is_same_v<T, int32>>::Type>
27 constexpr FFrameNumber(T /*int32*/ InValue)
28 : Value(InValue)
29 {}
30
31 /**
32 * Serializes the given FrameNumber from or into the specified archive.
33 *
34 * @param Ar The archive to serialize from or into.
35 * @param FrameNumber The bound to serialize.
36 * @return The archive used for serialization.
37 */
38 friend FArchive& operator<<(FArchive& Ar, FFrameNumber& FrameNumber);
39
41
42 FFrameNumber& operator+=(FFrameNumber RHS) { Value += RHS.Value; return *this; }
43 FFrameNumber& operator-=(FFrameNumber RHS) { Value -= RHS.Value; return *this; }
44 FFrameNumber& operator%=(FFrameNumber RHS) { Value %= RHS.Value; return *this; }
45
46 FFrameNumber& operator++() { ++Value; return *this; }
47 FFrameNumber& operator--() { --Value; return *this; }
48
49 FFrameNumber operator++(int32) { FFrameNumber Ret = *this; ++Value; return Ret; }
50 FFrameNumber operator--(int32) { FFrameNumber Ret = *this; --Value; return Ret; }
51
52 friend bool operator==(FFrameNumber A, FFrameNumber B) { return A.Value == B.Value; }
53 friend bool operator!=(FFrameNumber A, FFrameNumber B) { return A.Value != B.Value; }
54
55 friend bool operator< (FFrameNumber A, FFrameNumber B) { return A.Value < B.Value; }
56 friend bool operator> (FFrameNumber A, FFrameNumber B) { return A.Value > B.Value; }
57 friend bool operator<=(FFrameNumber A, FFrameNumber B) { return A.Value <= B.Value; }
58 friend bool operator>=(FFrameNumber A, FFrameNumber B) { return A.Value >= B.Value; }
59
60 friend FFrameNumber operator+(FFrameNumber A, FFrameNumber B) { return FFrameNumber(A.Value + B.Value); }
61 friend FFrameNumber operator-(FFrameNumber A, FFrameNumber B) { return FFrameNumber(A.Value - B.Value); }
62 friend FFrameNumber operator%(FFrameNumber A, FFrameNumber B) { return FFrameNumber(A.Value % B.Value); }
63
64 friend FFrameNumber operator-(FFrameNumber A) { return FFrameNumber(-A.Value); }
65
66 friend FFrameNumber operator*(FFrameNumber A, float Scalar) { return FFrameNumber(static_cast<int32>(FMath::Clamp(FMath::FloorToDouble(double(A.Value) * Scalar), (double)TNumericLimits<int32>::Min(), (double)TNumericLimits<int32>::Max()))); }
67 friend FFrameNumber operator/(FFrameNumber A, float Scalar) { return FFrameNumber(static_cast<int32>(FMath::Clamp(FMath::FloorToDouble(double(A.Value) / Scalar), (double)TNumericLimits<int32>::Min(), (double)TNumericLimits<int32>::Max()))); }
68
69 friend inline uint32 GetTypeHash(FFrameNumber A)
70 {
71 return A.Value;
72 }
73
74 /**
75 * The value of the frame number
76 */
77 int32 Value;
78};
79
80template<>
81struct TNumericLimits<FFrameNumber>
82{
84
85 static constexpr NumericType Min()
86 {
87 return MIN_int32;
88 }
89
90 static constexpr NumericType Max()
91 {
92 return MAX_int32;
93 }
94
95 static constexpr NumericType Lowest()
96 {
97 return Min();
98 }
99};
#define MAX_int32
#define MIN_int32
friend bool operator<=(FFrameNumber A, FFrameNumber B)
Definition FrameNumber.h:57
FFrameNumber & operator%=(FFrameNumber RHS)
Definition FrameNumber.h:44
friend FFrameNumber operator-(FFrameNumber A)
Definition FrameNumber.h:64
constexpr FFrameNumber()
Definition FrameNumber.h:19
FFrameNumber operator--(int32)
Definition FrameNumber.h:50
friend FFrameNumber operator+(FFrameNumber A, FFrameNumber B)
Definition FrameNumber.h:60
FFrameNumber & operator--()
Definition FrameNumber.h:47
friend uint32 GetTypeHash(FFrameNumber A)
Definition FrameNumber.h:69
FFrameNumber & operator++()
Definition FrameNumber.h:46
friend bool operator<(FFrameNumber A, FFrameNumber B)
Definition FrameNumber.h:55
friend bool operator>(FFrameNumber A, FFrameNumber B)
Definition FrameNumber.h:56
FFrameNumber operator++(int32)
Definition FrameNumber.h:49
bool Serialize(FArchive &Ar)
constexpr FFrameNumber(T InValue)
Definition FrameNumber.h:27
friend FFrameNumber operator/(FFrameNumber A, float Scalar)
Definition FrameNumber.h:67
FFrameNumber & operator-=(FFrameNumber RHS)
Definition FrameNumber.h:43
friend bool operator==(FFrameNumber A, FFrameNumber B)
Definition FrameNumber.h:52
friend bool operator>=(FFrameNumber A, FFrameNumber B)
Definition FrameNumber.h:58
friend FFrameNumber operator*(FFrameNumber A, float Scalar)
Definition FrameNumber.h:66
friend FFrameNumber operator-(FFrameNumber A, FFrameNumber B)
Definition FrameNumber.h:61
FFrameNumber & operator+=(FFrameNumber RHS)
Definition FrameNumber.h:42
friend bool operator!=(FFrameNumber A, FFrameNumber B)
Definition FrameNumber.h:53
friend FFrameNumber operator%(FFrameNumber A, FFrameNumber B)
Definition FrameNumber.h:62
static constexpr NumericType Max()
Definition FrameNumber.h:90
static constexpr NumericType Lowest()
Definition FrameNumber.h:95
static constexpr NumericType Min()
Definition FrameNumber.h:85