Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_EditorPreviewParams.c
Go to the documentation of this file.
1 
5 {
7  RplId m_ParentID = RplId.Invalid();
8  bool m_bParentChanged;
9 
10  RplId m_TargetRplID = RplId.Invalid();
11  EntityID m_TargetStaticID;
13  EEditableEntityInteraction m_TargetInteraction;
14 
15  vector m_vTransform[4];
16  vector m_Offset;
17  bool m_bIsUnderwater;
18  EEditorTransformVertical m_VerticalMode;
19  EEditorPlacingFlags m_PlacingFlags;
20  SCR_EditableEntityComponent m_CurrentLayer; //--- No replicated, used to extract data from SCR_PlacingEditorComponent.SpawnEntityResource()
21 
22  //------------------------------------------------------------------------------------------------
23  static void Encode(SSnapSerializerBase snapshot, ScriptCtx hint, ScriptBitSerializer packet)
24  {
25  snapshot.Serialize(packet, 84);
26  }
27 
28  //------------------------------------------------------------------------------------------------
29  static bool Decode(ScriptBitSerializer packet, ScriptCtx hint, SSnapSerializerBase snapshot)
30  {
31  return snapshot.Serialize(packet, 84);
32  }
33 
34  //------------------------------------------------------------------------------------------------
35  static bool SnapCompare(SSnapSerializerBase lhs, SSnapSerializerBase rhs, ScriptCtx hint)
36  {
37  return lhs.CompareSnapshots(rhs, 84);
38  }
39 
40  //------------------------------------------------------------------------------------------------
41  static bool PropCompare(SCR_EditorPreviewParams prop, SSnapSerializerBase snapshot, ScriptCtx hint)
42  {
43  return snapshot.Compare(prop.m_vTransform, 48)
44  && snapshot.Compare(prop.m_ParentID, 4)
45  && snapshot.Compare(prop.m_bParentChanged, 4)
46  && snapshot.Compare(prop.m_VerticalMode, 4)
47  && snapshot.Compare(prop.m_bIsUnderwater, 4)
48  && snapshot.Compare(prop.m_TargetRplID, 4)
49  && snapshot.Compare(prop.m_TargetStaticID, 8)
50  && snapshot.Compare(prop.m_TargetInteraction, 4)
51  && snapshot.Compare(prop.m_PlacingFlags, 4);
52  }
53 
54  //------------------------------------------------------------------------------------------------
55  static bool Extract(SCR_EditorPreviewParams prop, ScriptCtx hint, SSnapSerializerBase snapshot)
56  {
57  snapshot.SerializeBytes(prop.m_vTransform, 48);
58  snapshot.SerializeBytes(prop.m_ParentID, 4);
59  snapshot.SerializeBytes(prop.m_bParentChanged, 4);
60  snapshot.SerializeBytes(prop.m_VerticalMode, 4);
61  snapshot.SerializeBytes(prop.m_bIsUnderwater, 4);
62  snapshot.SerializeBytes(prop.m_TargetRplID, 4);
63  snapshot.SerializeBytes(prop.m_TargetStaticID, 8);
64  snapshot.SerializeBytes(prop.m_TargetInteraction, 4);
65  snapshot.SerializeBytes(prop.m_PlacingFlags, 4);
66 
67  return true;
68  }
69 
70  //------------------------------------------------------------------------------------------------
71  static bool Inject(SSnapSerializerBase snapshot, ScriptCtx hint, SCR_EditorPreviewParams prop)
72  {
73  snapshot.SerializeBytes(prop.m_vTransform, 48);
74  snapshot.SerializeBytes(prop.m_ParentID, 4);
75  snapshot.SerializeBytes(prop.m_bParentChanged, 4);
76  snapshot.SerializeBytes(prop.m_VerticalMode, 4);
77  snapshot.SerializeBytes(prop.m_bIsUnderwater, 4);
78  snapshot.SerializeBytes(prop.m_TargetRplID, 4);
79  snapshot.SerializeBytes(prop.m_TargetStaticID, 8);
80  snapshot.SerializeBytes(prop.m_TargetInteraction, 4);
81  snapshot.SerializeBytes(prop.m_PlacingFlags, 4);
82 
83  return true;
84  }
85 
86  //------------------------------------------------------------------------------------------------
89  void GetWorldTransform(out vector outTransform[4])
90  {
91  if (m_Offset == vector.Zero)
92  {
93  //--- Exact position
94  //outTransform = m_vTransform; //--- Doesn't work, reference is lost
95  Math3D.MatrixCopy(m_vTransform, outTransform);
96  }
97  else
98  {
99  //--- Offset when multiple entities are being placed (e.g., waypoints for a group)
100  vector coefMatrix[4] = {m_vTransform[0], m_vTransform[1], m_vTransform[2], vector.Zero};
101  vector offsetMatrix[4] = { vector.Zero, vector.Zero, vector.Zero, m_Offset};
102  Math3D.MatrixMultiply4(coefMatrix, offsetMatrix, offsetMatrix);
103  outTransform = {m_vTransform[0], m_vTransform[1], m_vTransform[2], m_vTransform[3] + offsetMatrix[3]};
104  }
105  }
106 
107  //------------------------------------------------------------------------------------------------
110  bool Deserialize()
111  {
112  m_Parent = SCR_EditableEntityComponent.Cast(Replication.FindItem(m_ParentID));
113  if (!m_Parent && m_ParentID.IsValid())
114  {
115  Print(string.Format("Cannot deserialize entity, parent with RplId = %1 not found!", m_ParentID), LogLevel.ERROR);
116  return false;
117  }
118 
119  m_Target = SCR_EditableEntityComponent.Cast(Replication.FindItem(m_TargetRplID));
120 
121  if (!m_Target)
122  m_Target = SCR_EditableEntityComponent.GetEditableEntity(GetGame().GetWorld().FindEntityByID(m_TargetStaticID));
123 
124  if (!m_Target && m_TargetRplID.IsValid())
125  {
126  Print(string.Format("Cannot deserialize entity, target neither with RplId = %1 nor with EntityID = %2 found!", m_TargetRplID, m_TargetStaticID), LogLevel.ERROR);
127  return false;
128  }
129 
130  return true;
131  }
132 
133  //------------------------------------------------------------------------------------------------
136  void SetTarget(SCR_EditableEntityComponent target)
137  {
138  if (target && target.GetOwner())
139  {
140  m_TargetRplID = Replication.FindId(target);
141  if (!m_TargetRplID.IsValid())
142  m_TargetStaticID = target.GetOwner().GetID();
143  }
144  }
145 
146  //------------------------------------------------------------------------------------------------
155  static SCR_EditorPreviewParams CreateParams(
156  vector transform[4],
157  RplId parentID = Replication.INVALID_ID,
159  bool isUnderwater = false,
160  SCR_EditableEntityComponent target = null,
162  )
163  {
165  Math3D.MatrixCopy(transform, params.m_vTransform);
166  params.m_ParentID = parentID;
167  params.m_VerticalMode = verticalMode;
168  params.m_bIsUnderwater = isUnderwater;
169  params.m_TargetInteraction = targetInteraction;
170  params.SetTarget(target);
171  return params;
172  }
173 
174  //------------------------------------------------------------------------------------------------
180  // TODO: notnull or nullcheck previewManager
181  static SCR_EditorPreviewParams CreateParamsFromPreview(SCR_PreviewEntityEditorComponent previewManager, SCR_EditableEntityComponent parent = null, bool parentChanged = false)
182  {
183  //--- Check if target interaction is valid
184  if (previewManager.GetTarget() && previewManager.GetTargetInteraction() == EEditableEntityInteraction.NONE)
185  {
186  SCR_NotificationsComponent.SendLocal(ENotification.EDITOR_TRANSFORMING_INCORRECT_TARGET);
187  return null;
188  }
189 
191 
192  previewManager.GetPreviewTransform(params.m_vTransform);
193  params.m_VerticalMode = previewManager.GetVerticalModeReal();
194  params.m_bIsUnderwater = previewManager.IsUnderwater();
195  params.m_TargetInteraction = previewManager.GetTargetInteraction();
196  params.SetTarget(previewManager.GetTarget());
197  params.m_ParentID = Replication.FindId(parent);
198  params.m_bParentChanged = parentChanged;
199 
200  return params;
201  }
202 }
EEditableEntityInteraction
EEditableEntityInteraction
Type of suggested interaction when hovering edited entity on top of another entity.
Definition: EEditableEntityInteraction.c:5
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
m_Target
class SCR_AIPolar m_Target
ENotification
ENotification
Definition: ENotification.c:4
EEditorTransformVertical
EEditorTransformVertical
Vertical transformation mode.
Definition: EEditorTransformVertical.c:5
EntityID
SCR_CompositionSlotManagerComponentClass EntityID
EEditorPlacingFlags
EEditorPlacingFlags
Definition: EEditorPlacingFlags.c:1
SCR_EditableEntityComponent
Definition: SCR_EditableEntityComponent.c:13
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
SCR_EditorPreviewParams
Network packet of variables for entity placing and transformation.
Definition: SCR_EditorPreviewParams.c:4
SCR_PreviewEntityEditorComponent
Definition: SCR_PreviewEntityEditorComponent.c:12