Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
NetworkGuid.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 "Containers/UnrealString.h"
7
8/**
9 * Implements a globally unique identifier for network related use.
10 *
11 * For now, this is just a uint32 with some bits meaning special things.
12 * This may be expanded (beyond a uint32) eventually while keeping the API the same.
13 */
14class FNetworkGUID
15{
16public:
17
18 uint32 Value;
19
20public:
21
22 FNetworkGUID()
23 : Value(0)
24 { }
25
26 FNetworkGUID( uint32 V )
27 : Value(V)
28 { }
29
30public:
31
32 friend bool operator==( const FNetworkGUID& X, const FNetworkGUID& Y )
33 {
34 return (X.Value == Y.Value);
35 }
36
37 friend bool operator!=( const FNetworkGUID& X, const FNetworkGUID& Y )
38 {
39 return (X.Value != Y.Value);
40 }
41
42 friend FArchive& operator<<( FArchive& Ar, FNetworkGUID& G )
43 {
44 Ar.SerializeIntPacked(G.Value);
45 return Ar;
46 }
47
48public:
49
50 void BuildFromNetIndex( int32 StaticNetIndex )
51 {
52 Value = (StaticNetIndex << 1 | 1);
53 }
54
55 int32 ExtractNetIndex()
56 {
57 if (Value & 1)
58 {
59 return Value >> 1;
60 }
61 return 0;
62 }
63
64 friend uint32 GetTypeHash( const FNetworkGUID& Guid )
65 {
66 return Guid.Value;
67 }
68
69 bool IsDynamic() const
70 {
71 return Value > 0 && !(Value & 1);
72 }
73
74 bool IsStatic() const
75 {
76 return Value & 1;
77 }
78
79 bool IsValid() const
80 {
81 return Value > 0;
82 }
83
84 bool NetSerialize( FArchive& Ar, class UPackageMap* Map, bool& bOutSuccess );
85
86 /** A Valid but unassigned NetGUID */
87 bool IsDefault() const
88 {
89 return (Value == 1);
90 }
91
92 static FNetworkGUID GetDefault()
93 {
94 return FNetworkGUID(1);
95 }
96
97 void Reset()
98 {
99 Value = 0;
100 }
101
102 FString ToString() const
103 {
104 return FString::Printf(TEXT("%d"), Value);
105 }
106
107public:
108
109 static FNetworkGUID Make(int32 seed, bool bIsStatic)
110 {
111 return FNetworkGUID(seed << 1 | (bIsStatic ? 1 : 0));
112 }
113};
#define TEXT(x)
Definition Platform.h:1108