File size: 1,480 Bytes
ac55997
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System;

namespace Quantum
{
	public unsafe static class UTManager
	{
		public static Action<EntityRef, string> SetupDebugger;

		public static Action<EntityRef, long> ConsiderationChosen;
		public static Action<EntityRef> OnUpdate;

		/// <summary>
		/// Initializes the Utility Reasoner, allocating all frame data needed.
		/// If no UTRoot asset is passed by parameter, it will try to initialize with one already set on the Component, if any.
		/// </summary>
		public static void Init(Frame frame, UtilityReasoner* reasoner, AssetRefUTRoot utRootRef = default, EntityRef entity = default)
		{
			reasoner->Initialize(frame, utRootRef, entity);
		}

		public static void Free(Frame frame, UtilityReasoner* reasoner)
		{
			reasoner->Free(frame);
		}

		/// <summary>
		/// Ticks the UtilityReasoner. The Considerations will be evaluated and the most useful will be executed.
		/// It can be agnostic to entities, meaning that it is possible to have a UtilityReasoner as part of Global
		/// </summary>
		/// <param name="frame"></param>
		/// <param name="reasoner"></param>
		/// <param name="entity"></param>
		public static void Update(Frame frame, UtilityReasoner* reasoner, EntityRef entity = default)
		{
			if (entity != default)
			{
				OnUpdate?.Invoke(entity);
			}

			if (reasoner == default && entity != default)
			{
				reasoner = &frame.Unsafe.GetPointer<UTAgent>(entity)->UtilityReasoner;
			}

			reasoner->Update(frame, reasoner, entity);
		}
	}
}