Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_DebugShapeHelperComponent.c
Go to the documentation of this file.
1/*
2Similar to SCR_DebugShapeManager however it is designed to grant more freedom and ease of use.
3Is configured by placing a DebugShapeHelper.et in the world and configuring its SCR_DebugShapeHelperComponent.
4*/
5
6[EntityEditorProps(category: "GameScripted/Helpers", description: "Allows debug shapes to be rendered. Only spawn one-instance.")]
10
11class SCR_DebugShapeHelperComponent : ScriptComponent
12{
13 [Attribute(desc: "Limit amount of shapes drawn per tag. Older shapes get thrown out of draw list.", defvalue: "10000", category: "Limits", params: "0 inf")]
14 int m_iShapeLimit;
15
16 protected static SCR_DebugShapeHelperComponent s_Instance;
17 protected static int s_iShapeLimit = 10000;
18 protected static bool s_bKeepDrawList;
19
20 protected static ref map<string, ref array<ref Managed>> s_mTaggedShapes = new map<string, ref array<ref Managed>>();
21
22 protected static const int DEFAULT_COLOUR = MakeTransparent(Color.YELLOW);
23 protected static const ShapeFlags DEFAULT_SHAPE_FLAGS = ShapeFlags.TRANSP | ShapeFlags.DOUBLESIDE | ShapeFlags.NOOUTLINE;
24 protected static const ShapeFlags DEFAULT_SHAPE_FLAGS_NOZWRITE = ShapeFlags.TRANSP | ShapeFlags.DOUBLESIDE | ShapeFlags.NOOUTLINE | ShapeFlags.NOZWRITE;
25 protected static const ShapeFlags DEFAULT_TRIS_FLAGS = ShapeFlags.TRANSP | ShapeFlags.DOUBLESIDE | ShapeFlags.NOZWRITE;
26 protected static const ShapeFlags DEFAULT_TEXT_FLAGS = DebugTextFlags.CENTER | DebugTextFlags.FACE_CAMERA;
27 protected static const string DEBUG_TAG = "SCR_DebugShapeHelperComponent"; // Groups debug objects together.
28
29 //------------------------------------------------------------------------------------------------
38 static void CreateFloorCeilingTraceShapes(World world, vector startPos, TraceParam traceParam, vector floorPos, vector ceilingPos, bool enoughSpace, string text = "", string tag = "")
39 {
40 string shapeTag = string.Format("%1_%2", DEBUG_TAG, tag);
41 SCR_DebugShapeHelperComponent.AddSphere(startPos, 0.1, Color.VIOLET, DEFAULT_SHAPE_FLAGS_NOZWRITE, tag: shapeTag);
43 SCR_DebugShapeHelperComponent.AddText(world, startPos, text, tag: shapeTag);
44
45 TraceBox traceBox = TraceBox.Cast(traceParam);
46 if (traceBox)
47 {
48 SCR_DebugShapeHelperComponent.AddBox(Vector(floorPos[0] + traceBox.Mins[0], floorPos[1], floorPos[2] + traceBox.Mins[2]), Vector(ceilingPos[0] + traceBox.Maxs[0], ceilingPos[1], ceilingPos[2] + traceBox.Maxs[2]), SCR_DebugShapeHelperComponent.GetColorBasedOnSuccess(enoughSpace), DEFAULT_SHAPE_FLAGS_NOZWRITE, tag: shapeTag);
49 return;
50 }
51
52 TraceSphere traceSphere = TraceSphere.Cast(traceParam);
53 if (traceSphere)
54 {
55 int color = SCR_DebugShapeHelperComponent.GetColorBasedOnSuccess(enoughSpace);
56 vector sphereOffset = Vector(0, traceSphere.Radius, 0);
57 SCR_DebugShapeHelperComponent.AddCylinderBetween(floorPos + sphereOffset, ceilingPos - sphereOffset, traceSphere.Radius, color, DEFAULT_SHAPE_FLAGS_NOZWRITE, tag: shapeTag);
58 SCR_DebugShapeHelperComponent.AddSphere(floorPos + sphereOffset, traceSphere.Radius, color, DEFAULT_SHAPE_FLAGS_NOZWRITE, tag: shapeTag);
59 SCR_DebugShapeHelperComponent.AddSphere(ceilingPos - sphereOffset, traceSphere.Radius, color, DEFAULT_SHAPE_FLAGS_NOZWRITE, tag: shapeTag);
60 return;
61 }
62 }
63
64 //------------------------------------------------------------------------------------------------
69 static void AddSphere(vector center, float radius, int color, ShapeFlags shapeFlags = DEFAULT_SHAPE_FLAGS, string tag = "")
70 {
71 Shape shape = Shape.CreateSphere(
72 color,
73 shapeFlags,
74 center,
75 radius
76 );
77 AddShape(shape, tag);
78 }
79
80 //------------------------------------------------------------------------------------------------
86 static void AddCylinderBetween(vector bottom, vector top, float radius, int color, ShapeFlags shapeFlags = DEFAULT_SHAPE_FLAGS, string tag = "")
87 {
88 AddCylinder(0.5 * (bottom + top), radius, top[1] - bottom[1], color, shapeFlags, tag);
89 }
90
91 //------------------------------------------------------------------------------------------------
97 static void AddCylinder(vector center, float radius, float length, int color, ShapeFlags shapeFlags = DEFAULT_SHAPE_FLAGS, string tag = "")
98 {
99 Shape shape = Shape.CreateCylinder(
100 color,
101 shapeFlags,
102 center,
103 radius,
104 length
105 );
106 AddShape(shape, tag);
107 }
108
109 //------------------------------------------------------------------------------------------------
114 static void AddBox(vector mins, vector maxs, int color, ShapeFlags shapeFlags = DEFAULT_TRIS_FLAGS, string tag = "")
115 {
116 vector mesh[] = {
117 // -Z Mins Tri 1
118 Vector(mins[0], mins[1], mins[2]),
119 Vector(maxs[0], mins[1], mins[2]),
120 Vector(mins[0], maxs[1], mins[2]),
121 // -Z Maxs Tri 2
122 Vector(maxs[0], maxs[1], mins[2]),
123 Vector(mins[0], maxs[1], mins[2]),
124 Vector(maxs[0], mins[1], mins[2]),
125 // +Z Mins Tri 3
126 Vector(mins[0], mins[1], maxs[2]),
127 Vector(maxs[0], mins[1], maxs[2]),
128 Vector(mins[0], maxs[1], maxs[2]),
129 // +Z Maxs Tri 4
130 Vector(maxs[0], maxs[1], maxs[2]),
131 Vector(mins[0], maxs[1], maxs[2]),
132 Vector(maxs[0], mins[1], maxs[2]),
133 // -X Mins Tri 5
134 Vector(mins[0], mins[1], mins[2]),
135 Vector(mins[0], mins[1], maxs[2]),
136 Vector(mins[0], maxs[1], mins[2]),
137 // -X Maxs Tri 6
138 Vector(mins[0], maxs[1], maxs[2]),
139 Vector(mins[0], maxs[1], mins[2]),
140 Vector(mins[0], mins[1], maxs[2]),
141 // +X Mins Tri 7
142 Vector(maxs[0], mins[1], mins[2]),
143 Vector(maxs[0], mins[1], maxs[2]),
144 Vector(maxs[0], maxs[1], mins[2]),
145 // +X Maxs Tri 8
146 Vector(maxs[0], maxs[1], maxs[2]),
147 Vector(maxs[0], maxs[1], mins[2]),
148 Vector(maxs[0], mins[1], maxs[2]),
149 // -Y Mins Tri 9
150 Vector(mins[0], mins[1], mins[2]),
151 Vector(maxs[0], mins[1], mins[2]),
152 Vector(mins[0], mins[1], maxs[2]),
153 // -Y Maxs Tri 10
154 Vector(maxs[0], mins[1], maxs[2]),
155 Vector(mins[0], mins[1], maxs[2]),
156 Vector(maxs[0], mins[1], mins[2]),
157 // +Y Mins Tri 11
158 Vector(mins[0], maxs[1], mins[2]),
159 Vector(maxs[0], maxs[1], mins[2]),
160 Vector(mins[0], maxs[1], maxs[2]),
161 // +Y Maxs Tri 12
162 Vector(maxs[0], maxs[1], maxs[2]),
163 Vector(mins[0], maxs[1], maxs[2]),
164 Vector(maxs[0], maxs[1], mins[2]),
165 };
166 Shape shape = Shape.CreateTris(
167 color,
168 shapeFlags,
169 mesh,
170 12
171 );
172 AddShape(shape, tag);
173 }
174
175 //------------------------------------------------------------------------------------------------
181 static void AddBoxWithTransform(vector mins, vector maxs, vector ownerTransform[4], int color, ShapeFlags shapeFlags = DEFAULT_TRIS_FLAGS, string tag = "")
182 {
183 // First create the mesh array with local coordinates
184 vector mesh[] = {
185 // -Z Mins Tri 1
186 Vector(mins[0], mins[1], mins[2]),
187 Vector(maxs[0], mins[1], mins[2]),
188 Vector(mins[0], maxs[1], mins[2]),
189 // -Z Maxs Tri 2
190 Vector(maxs[0], maxs[1], mins[2]),
191 Vector(mins[0], maxs[1], mins[2]),
192 Vector(maxs[0], mins[1], mins[2]),
193 // +Z Mins Tri 3
194 Vector(mins[0], mins[1], maxs[2]),
195 Vector(maxs[0], mins[1], maxs[2]),
196 Vector(mins[0], maxs[1], maxs[2]),
197 // +Z Maxs Tri 4
198 Vector(maxs[0], maxs[1], maxs[2]),
199 Vector(mins[0], maxs[1], maxs[2]),
200 Vector(maxs[0], mins[1], maxs[2]),
201 // -X Mins Tri 5
202 Vector(mins[0], mins[1], mins[2]),
203 Vector(mins[0], mins[1], maxs[2]),
204 Vector(mins[0], maxs[1], mins[2]),
205 // -X Maxs Tri 6
206 Vector(mins[0], maxs[1], maxs[2]),
207 Vector(mins[0], maxs[1], mins[2]),
208 Vector(mins[0], mins[1], maxs[2]),
209 // +X Mins Tri 7
210 Vector(maxs[0], mins[1], mins[2]),
211 Vector(maxs[0], mins[1], maxs[2]),
212 Vector(maxs[0], maxs[1], mins[2]),
213 // +X Maxs Tri 8
214 Vector(maxs[0], maxs[1], maxs[2]),
215 Vector(maxs[0], maxs[1], mins[2]),
216 Vector(maxs[0], mins[1], maxs[2]),
217 // -Y Mins Tri 9
218 Vector(mins[0], mins[1], mins[2]),
219 Vector(maxs[0], mins[1], mins[2]),
220 Vector(mins[0], mins[1], maxs[2]),
221 // -Y Maxs Tri 10
222 Vector(maxs[0], mins[1], maxs[2]),
223 Vector(mins[0], mins[1], maxs[2]),
224 Vector(maxs[0], mins[1], mins[2]),
225 // +Y Mins Tri 11
226 Vector(mins[0], maxs[1], mins[2]),
227 Vector(maxs[0], maxs[1], mins[2]),
228 Vector(mins[0], maxs[1], maxs[2]),
229 // +Y Maxs Tri 12
230 Vector(maxs[0], maxs[1], maxs[2]),
231 Vector(mins[0], maxs[1], maxs[2]),
232 Vector(maxs[0], maxs[1], mins[2]),
233 };
234
235 // Then apply the transformation to each point
236 // We know there are 36 vertices in the mesh (12 triangles * 3 vertices)
237 for (int i = 0; i < 36; i++)
238 {
239 mesh[i] = mesh[i].Multiply4(ownerTransform);
240 }
241
242 Shape shape = Shape.CreateTris(
243 color,
244 shapeFlags,
245 mesh,
246 12
247 );
248 AddShape(shape, tag);
249 }
250
251 //------------------------------------------------------------------------------------------------
255 static void AddText(World world, vector origin, string text, ShapeFlags shapeFlags = DEFAULT_TEXT_FLAGS, string tag = "")
256 {
257 Managed shape = DebugTextWorldSpace.Create(
258 world,
259 text,
260 shapeFlags,
261 origin[0], origin[1], origin[2],
262 color: Color.WHITE,
263 bgColor: Color.BLACK,
264 size: 13.0
265 );
266 AddShape(shape, tag);
267 }
268
269 //------------------------------------------------------------------------------------------------
273 static void AddShape(notnull Managed shape, string tag = "")
274 {
275 if (!s_Instance)
276 return;
277
278 array<ref Managed> shapes;
279 if (!s_mTaggedShapes.Find(tag, shapes))
280 {
281 shapes = {};
282 s_mTaggedShapes.Insert(tag, shapes);
283 }
284 shapes.Insert(shape);
285 while (shapes.Count() > s_iShapeLimit)
286 {
287 shapes.Remove(0);
288 }
289 }
290
291 //------------------------------------------------------------------------------------------------
295 static int MakeTransparent(int color)
296 {
297 int a, r, g, b;
298 Color.UnpackInt(color, a, r, g, b);
299 a = 0x20;
300 return ARGB(a, r, g, b);
301 }
302
303 //------------------------------------------------------------------------------------------------
307 static int GetColorBasedOnSuccess(bool success)
308 {
309 if (success)
310 return MakeTransparent(Color.GREEN);
311 else
312 return MakeTransparent(Color.RED);
313 }
314
315 //------------------------------------------------------------------------------------------------
319 static float GetDebugRadiusFromTraceParam(TraceParam traceParam)
320 {
321 TraceSphere traceSphere = TraceSphere.Cast(traceParam);
322 if (traceSphere)
323 return traceSphere.Radius;
324 TraceBox traceBox = TraceBox.Cast(traceParam);
325 if (traceBox) // Uses same radius for TraceOBB
326 return Math.Max(traceBox.Maxs[0] - traceBox.Mins[0], traceBox.Maxs[2] - traceBox.Mins[2]);
327 PrintFormat("[SCR_DebugShapeHelperComponent] GetDebugRadiusFromTraceParam has no case for TraceParam of type %1", traceParam.Type(), LogLevel.WARNING);
328 return 1;
329 }
330
331 //------------------------------------------------------------------------------------------------
335 static void RemoveShape(notnull Managed shape, string tag = "")
336 {
337 array<ref Managed> shapes;
338 if (s_mTaggedShapes.Find(tag, shapes))
339 shapes.RemoveItem(shape);
340 }
341
342 //------------------------------------------------------------------------------------------------
345 static void RemoveTag(string tag)
346 {
347 array<ref Managed> shapes;
348 if (!s_mTaggedShapes.Find(tag, shapes))
349 return;
350
351 s_mTaggedShapes.Remove(tag);
352 shapes.Clear();
353 }
354
355 //------------------------------------------------------------------------------------------------
357 static void Clear()
358 {
359 s_mTaggedShapes.Clear();
360 }
361
362 //------------------------------------------------------------------------------------------------
364 override protected void OnPostInit(IEntity owner)
365 {
366 s_bKeepDrawList = false;
367 s_Instance = this;
368
369 if (IsActive())
370 s_iShapeLimit = Math.Max(0, m_iShapeLimit);
371 else
372 s_iShapeLimit = 0;
373 }
374
375 //------------------------------------------------------------------------------------------------
378 override void OnDelete(IEntity owner)
379 {
380 if (!s_bKeepDrawList)
381 Clear();
382 }
383
384 //------------------------------------------------------------------------------------------------
389 override void _WB_OnInit(IEntity owner, inout vector mat[4], IEntitySource src)
390 {
391 s_Instance = this;
392 }
393
394 //------------------------------------------------------------------------------------------------
396 override bool _WB_OnKeyChanged(IEntity owner, BaseContainer src, string key, BaseContainerList ownerContainers, IEntity parent)
397 {
398 if (key == "coords")
399 return true;
400
401 if (key == "m_iShapeLimit")
402 {
403 s_bKeepDrawList = true;
404 return false;
405 }
406
407 if (key == "Enabled")
408 return false;
409
410 return true;
411 }
412}
int size
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
override void _WB_OnInit(IEntity owner, inout vector mat[4], IEntitySource src)
override bool _WB_OnKeyChanged(IEntity owner, BaseContainer src, string key, BaseContainerList ownerContainers, IEntity parent)
Any property value has been changed. You can use editor API here and do some additional edit actions ...
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
SCR_SpawnerSlotManagerClass s_Instance
Class used for managing changes and removals of slots present in world.
Definition Color.c:13
Definition Math.c:13
static bool IsEmptyOrWhiteSpace(string input)
Definition World.c:16
Definition Types.c:486
DebugTextFlags
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
ShapeFlags
Definition ShapeFlags.c:13
proto void PrintFormat(string fmt, void param1=NULL, void param2=NULL, void param3=NULL, void param4=NULL, void param5=NULL, void param6=NULL, void param7=NULL, void param8=NULL, void param9=NULL, LogLevel level=LogLevel.NORMAL)
SCR_FieldOfViewSettings Attribute
proto native vector Vector(float x, float y, float z)
proto native void Clear()
Remove all calls from list.
proto int ARGB(int a, int r, int g, int b)