Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_VehicleTrackDecalComponent.c
Go to the documentation of this file.
1 // Spawns Track Decal
2 
4 {
5  TrackDecal m_Decal;
6  vector m_vLastAxlePos;
7  vector m_vLastTracePos;
8  vector m_vLastTraceNormal;
9  float m_fLength;
10  bool m_bConnectToPrevious;
11 
12  void TrackDecalInfo()
13  {
14  m_Decal = null;
15  m_vLastAxlePos = vector.Zero;
16  m_vLastTracePos = vector.Zero;
17  m_vLastTraceNormal = vector.Zero;
18  m_fLength = 0;
19  m_bConnectToPrevious = false;
20  }
21 
22  void Finalize(float dist)
23  {
24  if(!m_Decal) return;
25 
26  if(dist < 0.01)
27  {
28  m_Decal.FinalizeTrackDecal(false, 0);
29  m_bConnectToPrevious = true;
30  }
31  else
32  {
33  m_Decal.FinalizeTrackDecal(true, dist);
34  m_bConnectToPrevious = false;
35  }
36 
37  m_Decal = null;
38  m_fLength = 0;
39  }
40 };
41 
42 [ComponentEditorProps(category: "GameScripted/Test", description:"SCR_VehicleTrackDecal")]
43 class SCR_VehicleTrackDecalClass : ScriptComponentClass
44 {
45 };
46 
48 {
49  [Attribute("", UIWidgets.ResourceNamePicker, desc: "Material for track decal", params: "emat")]
50  private ResourceName m_TrackMaterial;
51 
52  [Attribute( "0.5", UIWidgets.EditBox, "Minimal lateral slip of wheel" )]
53  float m_fMinimalLateralSlip;
54 
55  [Attribute( "0.5", UIWidgets.EditBox, "Minimal longitudinal slip of wheel" )]
56  float m_fMinimalLongitudinalSlip;
57 
58  VehicleWheeledSimulation m_VehicleWheeledSimulation;
59  VehicleWheeledSimulation_SA m_VehicleWheeledSimulation_SA;
60 
61  ref array<ref TrackDecalInfo> m_TrackDecalsInfo;
62  int m_iWheelCount = 0;
63 
64  //------------------------------------------------------------------------------------------------
65  override void OnPostInit(IEntity owner)
66  {
67  // Don't run this component on console app
68  if (System.IsConsoleApp())
69  {
70  Deactivate(owner);
71  return;
72  }
73 
74  SetEventMask(owner, EntityEvent.INIT);
75  }
76 
77  //------------------------------------------------------------------------------------------------
78  override void EOnInit(IEntity owner)
79  {
80  super.EOnInit(owner);
81  GenericEntity generic_entity = GenericEntity.Cast(owner);
82 
83  if(generic_entity)
84  {
86  {
87  m_VehicleWheeledSimulation = VehicleWheeledSimulation.Cast(generic_entity.FindComponent(VehicleWheeledSimulation));
88  m_iWheelCount = m_VehicleWheeledSimulation.WheelCount();
89  //m_iWheelCount = 1;
90  }
91  else
92  {
93  m_VehicleWheeledSimulation_SA = VehicleWheeledSimulation_SA.Cast(generic_entity.FindComponent(VehicleWheeledSimulation_SA));
94  m_iWheelCount = m_VehicleWheeledSimulation_SA.WheelCount();
95  //m_iWheelCount = 1;
96  }
97 
98  }
99 
100  m_TrackDecalsInfo = new array<ref TrackDecalInfo>();
101  m_TrackDecalsInfo.Resize(m_iWheelCount);
102 
103  for(int i = 0; i < m_iWheelCount; i++)
104  {
105  m_TrackDecalsInfo[i] = new TrackDecalInfo();
106  }
107 
108  SetEventMask(owner, EntityEvent.FRAME);
109  }
110 
111  //------------------------------------------------------------------------------------------------
112  override void EOnFrame(IEntity owner, float timeSlice)
113  {
114  for(int i = 0; i < m_iWheelCount; i++)
115  {
116  UpdateTrack(owner, i);
117  }
118  }
119 
120  void UpdateTrack(IEntity owner, int wheelIdx)
121  {
122  TrackDecalInfo trackInfo = m_TrackDecalsInfo[wheelIdx];
123 
124  float lateralSlip = 0;
125  float latitudeSlip = 0;
126 
127  bool shouldAddTrackDecal = 0;
128 
130  {
131  lateralSlip = m_VehicleWheeledSimulation.WheelGetLateralSlip(wheelIdx);
132  latitudeSlip = m_VehicleWheeledSimulation.WheelGetLongitudinalSlip(wheelIdx);
133 
134  shouldAddTrackDecal = m_VehicleWheeledSimulation.WheelHasContact(wheelIdx) && (lateralSlip >= m_fMinimalLateralSlip || latitudeSlip >= m_fMinimalLongitudinalSlip);
135  }
136  else
137  {
138  lateralSlip = m_VehicleWheeledSimulation_SA.WheelGetLateralSlip(wheelIdx);
139  latitudeSlip = m_VehicleWheeledSimulation_SA.WheelGetLongitudinalSlip(wheelIdx);
140 
141  shouldAddTrackDecal = m_VehicleWheeledSimulation_SA.WheelHasContact(wheelIdx) && (lateralSlip >= m_fMinimalLateralSlip || latitudeSlip >= m_fMinimalLongitudinalSlip);
142  }
143 
144  if(!shouldAddTrackDecal)
145  {
146  if(trackInfo.m_Decal)
147  {
148  Print("No contact");
149  trackInfo.Finalize(0.25);
150  }
151  return;
152  }
153 
154  vector position;
155  vector normal;
156  IEntity contactEntity;
157 
159  {
160  position = m_VehicleWheeledSimulation.WheelGetContactPosition(wheelIdx);
161  normal = m_VehicleWheeledSimulation.WheelGetContactNormal(wheelIdx);
162  contactEntity = m_VehicleWheeledSimulation.WheelGetContactEntity(wheelIdx);
163  }
164  else
165  {
166  position = m_VehicleWheeledSimulation_SA.WheelGetContactPosition(wheelIdx);
167  normal = m_VehicleWheeledSimulation_SA.WheelGetContactNormal(wheelIdx);
168  contactEntity = m_VehicleWheeledSimulation_SA.WheelGetContactEntity(wheelIdx);
169  }
170 
171  if(!trackInfo.m_Decal)
172  {
173  if(trackInfo.m_bConnectToPrevious)
174  {
175  trackInfo.m_Decal = GetOwner().GetWorld().CreateTrackDecal(contactEntity, trackInfo.m_vLastTracePos, trackInfo.m_vLastTraceNormal, 0.25, 120.0, m_TrackMaterial, null, 1.0);
176  trackInfo.m_bConnectToPrevious = false;
177  Print("Connected");
178  }
179  else
180  {
181  trackInfo.m_Decal = GetOwner().GetWorld().CreateTrackDecal(contactEntity, position, normal, 0.25, 120.0, m_TrackMaterial, null, 0.0);
182  Print("New");
183  }
184  }
185  else if(vector.DistanceSq(trackInfo.m_vLastAxlePos, position) > 0.01)
186  {
187  trackInfo.m_vLastAxlePos = position;
188 
189  int validationEnum = trackInfo.m_Decal.CanAddToTrackDecal(contactEntity, m_TrackMaterial, position);
190 
191  switch(validationEnum)
192  {
193  case -1:
194  Print("Track error");
195  break;
196  case 0: //Valid
197  {
198  trackInfo.m_fLength += vector.Distance(position, trackInfo.m_vLastTracePos);
199 
200  if(!trackInfo.m_Decal.AddPointToTrackDecal(position, normal, 1.0))
201  {
202  trackInfo.Finalize(0.0);
203  Print("Finalized point");
204  }
205  }
206  break;
207  case 1: // Different entity
208  {
209  TrackDecal oldDecal = trackInfo.m_Decal;
210  oldDecal.FinalizeTrackDecal(false, 0);
211 
212  trackInfo.m_Decal = GetOwner().GetWorld().CreateTrackDecal(contactEntity, position, normal, 0.25, 120.0, m_TrackMaterial, oldDecal, 1.0);
213  trackInfo.m_bConnectToPrevious = false;
214  Print("Diff ent");
215  }
216  break;
217  case 2: // Too far from last point
218  {
219  trackInfo.Finalize(0.1);
220  trackInfo.m_fLength = 0.0;
221  trackInfo.m_Decal = GetOwner().GetWorld().CreateTrackDecal(contactEntity, position, normal, 0.25, 120.0, m_TrackMaterial, null, 0.0);
222  trackInfo.m_bConnectToPrevious = false;
223  Print("Too far");
224  }
225  break;
226  }
227  }
228 
229  trackInfo.m_vLastTracePos = position;
230  trackInfo.m_vLastTraceNormal = normal;
231  }
232 };
ComponentEditorProps
SCR_FragmentEntityClass ComponentEditorProps
m_Decal
SCR_EditableDecalComponentClass m_Decal
ScriptComponent
SCR_SiteSlotEntityClass ScriptComponent
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
TrackDecalInfo
Definition: SCR_VehicleTrackDecalComponent.c:3
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
GenericEntity
SCR_GenericBoxEntityClass GenericEntity
GetIsClientAuthority
override bool GetIsClientAuthority()
Definition: game.c:268
SCR_VehicleTrackDecal
Definition: SCR_VehicleTrackDecalComponent.c:47
SCR_VehicleTrackDecalClass
Definition: SCR_VehicleTrackDecalComponent.c:43
Attribute
typedef Attribute
Post-process effect of scripted camera.
Deactivate
protected void Deactivate()
Definition: SCR_BaseHintCondition.c:27
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
position
vector position
Definition: SCR_DestructibleTreeV2.c:30
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180