Time Rewizer  v.1.1
Created by: Mark Oostveen
MarkOostveen.TimeRewizer.RewizeSystem Class Reference

Manages all rewinding objects, by updating, extracting and organising them. use this class for all changes to a rewindable object at runtime More...

+ Collaboration diagram for MarkOostveen.TimeRewizer.RewizeSystem:

Public Types

enum  ERewindingType { ERewindingType.Normal, ERewindingType.Baked }
 Rewind Setting of rewindables More...
 
enum  RewindOption { RewindOption.Normal, RewindOption.Rewind, RewindOption.Pauze, RewindOption.None }
 Global States of RewindManger More...
 

Public Member Functions

void Add (IRewizeable newobject, bool loadAsync, Type snapshottype)
 Add new object to RewizeSystem More...
 
void ChangeRewindable (GameObject target, RewindOption option)
 Will change rewind properties of object. Rewindind Option will rewind object Tracking will retrack an object pause will pauze the object compleetly More...
 
void ResetObject (GameObject[] objects)
 Reset Objects to state at start of scene More...
 
void ResetObject (GameObject target)
 Resets object to state when object Spawned More...
 
void StartPause ()
 pauze objects both in tracking and rewinding More...
 
void StopPause ()
 Resume Object More...
 
void Remove (IRewizeable target)
 Removes Internal references to this IRewizeable Instance, excluding callbacks More...
 
void Rewind ()
 rewinds all objects in tracking More...
 
void Track ()
 add all paused objects back to tracking More...
 

Static Public Member Functions

static T CreateControlledValueRewindInstance< T > (ref T input)
 Creates a new instance, only when input == null More...
 

Package Functions

 RewizeSystem (int maxrecordtime, RewindOption startpreset)
 
void FixedUpdate ()
 

Properties

static RewizeSystem Instance [get]
 Rewind Manager Singleton More...
 
RewindOption GlobalState [get]
 Current Global state of objects in rewind manager More...
 

Events

Action OnFixedUpdate
 Event that will be invoked on FixedUpdate More...
 
Action OnFixedUpdateParrallel
 

Detailed Description

Manages all rewinding objects, by updating, extracting and organising them. use this class for all changes to a rewindable object at runtime

Member Enumeration Documentation

◆ ERewindingType

Rewind Setting of rewindables

Enumerator
Normal 

Normal type for rewinding, will be threated without baked content

Baked 

Special case, will be threated with baked content

12  {
16  Normal,
17 
21  Baked
22  }

◆ RewindOption

Global States of RewindManger

Enumerator
Normal 

Tracking state

Rewind 

Rewinding state

Pauze 

Pause state

None 

Internal Manager use ONLY!!!

29  {
33  Normal,
34 
38  Rewind,
39 
43  Pauze,
44 
48  None
49  }

Constructor & Destructor Documentation

◆ RewizeSystem()

MarkOostveen.TimeRewizer.RewizeSystem.RewizeSystem ( int  maxrecordtime,
RewindOption  startpreset 
)
package
23  {
24  if (Instance == null)
25  {
26  Instance = this;
27  }
28 
29  Application.runInBackground = true;
30 
31  m_MaxRecordTime = maxrecordtime;
32  GlobalState = startpreset;
33 
34  m_Rewinding = new List<ListValue>(1000);
35  m_Tracking = new List<ListValue>(1000);
36  m_Pauzed = new List<ListValue>(1000);
37 
38  m_Dictionary = new ConcurrentDictionary<GameObject, List<IRewizeable>>();
39  m_UpdateRequestList = new List<UpdateObjectStateKeyValue>();
40 
41  m_ParallelUpdate = new Task[2];
42  m_ParallelUpdate[0] = Task.Factory.StartNew(UpdateTracking);
43  m_ParallelUpdate[1] = Task.Factory.StartNew(UpdateRewinding);
44  m_InternalUpdateTask = Task.Factory.StartNew(UpdateObjectLists);
45  }

Member Function Documentation

◆ Add()

void MarkOostveen.TimeRewizer.RewizeSystem.Add ( IRewizeable  newobject,
bool  loadAsync,
Type  snapshottype 
)

Add new object to RewizeSystem

Parameters
newobject
loadAsync
snapshottype
15  {
16  void AddItem()
17  {
18  ListValue newValue;
19 
20  //look for baked rewinding info
21  if (newobject.LoadScriptableContent() != null)
22  {
23  ISnapShot[] prerewind = newobject.LoadScriptableContent().GetSnapshots(snapshottype);
24  newValue = AddPreRewind(newobject, prerewind);
25  }
26  else
27  {
28  newValue = AddNormal(newobject);
29  }
30 
31  if (!m_Dictionary.ContainsKey(newobject.Linkedobj))
32  {
33  m_Dictionary.TryAdd(newobject.Linkedobj, new List<IRewizeable>() { newobject });
34  }
35  else
36  {
37  UpdateDictionaryItem(newobject.Linkedobj, newobject, DictionaryUpdateFlag.Add);
38  }
39 
40  UpdateObjectStateKeyValue pair;
41 
42  //set state
43  if (GlobalState == RewindOption.Pauze)
44  {
45  pair = new UpdateObjectStateKeyValue(newValue, RewindOption.Pauze);
46  }
47  else
48  {
49  pair = new UpdateObjectStateKeyValue(newValue, RewindOption.Normal);
50  }
51 
52  lock (m_UpdateRequestList)
53  {
54  m_UpdateRequestList.Add(pair);
55  }
56  }
57 
58  if (loadAsync)
59  {
60  Createtask(AddItem);
61  }
62  else
63  {
64  AddItem();
65  }
66  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ChangeRewindable()

void MarkOostveen.TimeRewizer.RewizeSystem.ChangeRewindable ( GameObject  target,
RewindOption  option 
)

Will change rewind properties of object. Rewindind Option will rewind object Tracking will retrack an object pause will pauze the object compleetly

Parameters
target
option
22  {
23  Parallel.Invoke(() =>
24  {
25  //check if object exists in dictionary
26  if (m_Dictionary.ContainsKey(target))
27  {
28  m_Dictionary.TryGetValue(target, out List<IRewizeable> rewindable);
29 
30  switch (option)
31  {
32  case RewindOption.Pauze:
33  Parallel.For(0, rewindable.Count, i =>
34  {
35  ListValue value = SearchValue(rewindable[i]);
36  m_UpdateRequestList.Add(new UpdateObjectStateKeyValue(value, RewindOption.Pauze));
37  });
38  break;
39 
40  case RewindOption.Rewind:
41  Parallel.For(0, rewindable.Count, i =>
42  {
43  ListValue value = SearchValue(rewindable[i]);
44  m_UpdateRequestList.Add(new UpdateObjectStateKeyValue(value, RewindOption.Rewind));
45  });
46  break;
47 
48  case RewindOption.Normal:
49  Parallel.For(0, rewindable.Count, i =>
50  {
51  ListValue value = SearchValue(rewindable[i]);
52  m_UpdateRequestList.Add(new UpdateObjectStateKeyValue(value, RewindOption.Normal));
53  });
54  break;
55  }
56  }
57  });
58  }

◆ CreateControlledValueRewindInstance< T >()

static T MarkOostveen.TimeRewizer.RewizeSystem.CreateControlledValueRewindInstance< T > ( ref T  input)
static

Creates a new instance, only when input == null

Template Parameters
T
Parameters
input
Returns
Type Constraints
T :new() 
13  : new()
14  {
15  if (EqualityComparer<T>.Default.Equals(input, default))
16  {
17  input = RewizeUtilityFunctions.CreateInstance<T>();
18  }
19 
20  return input;
21  }

◆ FixedUpdate()

void MarkOostveen.TimeRewizer.RewizeSystem.FixedUpdate ( )
package
66  {
67  //wait for internal update to be completed
68  Task.WaitAll(m_InternalUpdateTask);
69 
70  Task parallel = Task.Factory.StartNew(() =>
71  {
72  OnFixedUpdateParrallel?.Invoke();
73  });
74 
75  OnFixedUpdate?.Invoke();
76  Task.WaitAll(parallel);
77 
78  //Execute on different thread
79  ParallelUpdate();
80  }

◆ Remove()

void MarkOostveen.TimeRewizer.RewizeSystem.Remove ( IRewizeable  target)

Removes Internal references to this IRewizeable Instance, excluding callbacks

Parameters
target
12  {
13  Task.Factory.StartNew(() =>
14  m_UpdateRequestList.Add(new UpdateObjectStateKeyValue(SearchValue(target), RewindOption.None)));
15  }
+ Here is the caller graph for this function:

◆ ResetObject() [1/2]

void MarkOostveen.TimeRewizer.RewizeSystem.ResetObject ( GameObject []  objects)

Reset Objects to state at start of scene

Parameters
objects
65  {
66  Parallel.For(0, objects.Length, i => ResetObject(objects[i]));
67  }

◆ ResetObject() [2/2]

void MarkOostveen.TimeRewizer.RewizeSystem.ResetObject ( GameObject  target)

Resets object to state when object Spawned

Parameters
target
74  {
75  IRewizeable[] rewizeables = GetRewindablesFromGameObject(target);
76 
77  Parallel.For(0, rewizeables.Length, i =>
78  {
79  ListValue value = SearchValue(rewizeables[i]);
80  value.m_Data.m_Data = new List<ISnapShot>(m_MaxRecordTime * 60) { value.m_Data.m_FirstData };
81  value.m_Data.m_DataFrameCount = new List<int>(m_MaxRecordTime * 60) { 0 };
82  m_UpdateRequestList.Add(new UpdateObjectStateKeyValue(value, RewindOption.Rewind));
83  });
84  }

◆ Rewind()

void MarkOostveen.TimeRewizer.RewizeSystem.Rewind ( )

rewinds all objects in tracking

14  {
15  Task.WaitAll(m_ParallelUpdate);
16 
17  for (int i = 0; i < m_Tracking.Count; i++)
18  {
19  m_UpdateRequestList.Add(new UpdateObjectStateKeyValue(m_Tracking[i], RewindOption.Rewind));
20  }
21 
22  GlobalState = RewindOption.Rewind;
23  }

◆ StartPause()

void MarkOostveen.TimeRewizer.RewizeSystem.StartPause ( )

pauze objects both in tracking and rewinding

14  {
15  for (int i = 0; i < m_Tracking.Count; i++)
16  {
17  m_UpdateRequestList.Add(new UpdateObjectStateKeyValue(m_Tracking[i], RewindOption.Pauze));
18  }
19 
20  for (int i = 0; i < m_Rewinding.Count; i++)
21  {
22  m_UpdateRequestList.Add(new UpdateObjectStateKeyValue(m_Rewinding[i], RewindOption.Pauze));
23  }
24 
25  m_PreviousState = GlobalState;
26  GlobalState = RewindOption.Pauze;
27  }

◆ StopPause()

void MarkOostveen.TimeRewizer.RewizeSystem.StopPause ( )

Resume Object

33  {
34  GlobalState = m_PreviousState;
35 
36  for (int i = 0; i < m_Pauzed.Count; i++)
37  {
38  ListValue value = m_Pauzed[i];
39  if (value.m_Object.Rewinding)
40  {
41  m_UpdateRequestList.Add(new UpdateObjectStateKeyValue(value, RewindOption.Rewind));
42  }
43  else
44  {
45  m_UpdateRequestList.Add(new UpdateObjectStateKeyValue(value, RewindOption.Normal));
46  }
47  }
48  }

◆ Track()

void MarkOostveen.TimeRewizer.RewizeSystem.Track ( )

add all paused objects back to tracking

14  {
15  Task.WaitAll(m_ParallelUpdate);
16 
17  for (int i = 0; i < m_Rewinding.Count; i++)
18  {
19  m_UpdateRequestList.Add(new UpdateObjectStateKeyValue(m_Rewinding[i], RewindOption.Normal));
20  }
21 
22  GlobalState = RewindOption.Normal;
23  }

Property Documentation

◆ GlobalState

RewindOption MarkOostveen.TimeRewizer.RewizeSystem.GlobalState
get

Current Global state of objects in rewind manager

55 { get; private set; }

◆ Instance

RewizeSystem MarkOostveen.TimeRewizer.RewizeSystem.Instance
staticget

Rewind Manager Singleton

50 { get; private set; }

Event Documentation

◆ OnFixedUpdate

Action MarkOostveen.TimeRewizer.RewizeSystem.OnFixedUpdate

Event that will be invoked on FixedUpdate

◆ OnFixedUpdateParrallel

Action MarkOostveen.TimeRewizer.RewizeSystem.OnFixedUpdateParrallel