Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_VoiceoverSystemSerializer.c
Go to the documentation of this file.
1class SCR_VoiceoverSystemData : PersistentState
2{
3}
4
5class SCR_VoiceoverSystemSerializer : ScriptedStateSerializer
6{
7 //------------------------------------------------------------------------------------------------
8 override static typename GetTargetType()
9 {
11 }
12
13 //------------------------------------------------------------------------------------------------
14 override ESerializeResult Serialize(notnull Managed instance, notnull SaveContext context)
15 {
16 if (RplSession.Mode() != RplMode.None)
17 return ESerializeResult.DEFAULT;
18
20 if (!voiceover)
21 return ESerializeResult.DEFAULT;
22
23 const SCR_VoiceoverSystemSnapshot snapshot = voiceover.CreateSnapshot();
24 if (!snapshot.m_sCurrentSoundEvent && snapshot.m_aQueue.IsEmpty())
25 return ESerializeResult.DEFAULT;
26
27 context.WriteValue("version", 1);
28 context.WriteValueDefault("currentConfig", snapshot.m_sData, ResourceName.Empty);
29 context.WriteValueDefault("currentSoundEvent", snapshot.m_sCurrentSoundEvent, string.Empty);
30 context.WriteValueDefault("currentActorName", snapshot.m_sCurrentActorName, string.Empty);
31 context.WriteValueDefault("currentSubtitle", snapshot.m_sCurrentSubtitle, string.Empty);
32 context.WriteValueDefault("currentSequence", snapshot.m_sCurrentSequence, string.Empty);
33
34 string currentActorId = GetSystem().GetId(snapshot.m_CurrentActor);
35 if (currentActorId.IsEmpty() && snapshot.m_CurrentActor)
36 currentActorId = snapshot.m_CurrentActor.GetName();
37
38 context.WriteDefault(currentActorId, string.Empty);
39
40 if (!snapshot.m_mActorNames.IsEmpty() || !context.CanSeekMembers())
41 context.WriteValue("actorNames", snapshot.m_mActorNames);
42
43 array<string> actorIds();
44 foreach (IEntity actor : snapshot.m_aActors)
45 {
46 string id = GetSystem().GetId(actor);
47 if (id.IsEmpty() && actor)
48 id = actor.GetName();
49
50 if (!id.IsEmpty())
51 actorIds.Insert(id);
52 }
53 if (!actorIds.IsEmpty() || !context.CanSeekMembers())
54 context.Write(actorIds);
55
56 context.WriteValue("queue", snapshot.m_aQueue);
57
58 return ESerializeResult.OK;
59 }
60
61 //------------------------------------------------------------------------------------------------
62 override bool Deserialize(notnull Managed instance, notnull LoadContext context)
63 {
65 if (!voiceover)
66 return false;
67
68 int version;
69 context.Read(version);
70
71 SCR_VoiceoverSystemSnapshot snapshot();
72
73 context.ReadValueDefault("currentConfig", snapshot.m_sData, ResourceName.Empty);
74 context.ReadValueDefault("currentSoundEvent", snapshot.m_sCurrentSoundEvent, string.Empty);
75 context.ReadValueDefault("currentActorName", snapshot.m_sCurrentActorName, string.Empty);
76 context.ReadValueDefault("currentSubtitle", snapshot.m_sCurrentSubtitle, string.Empty);
77 context.ReadValueDefault("currentSequence", snapshot.m_sCurrentSequence, string.Empty);
78
79 string currentActorId;
80 context.ReadDefault(currentActorId, string.Empty);
81
82 context.ReadValue("actorNames", snapshot.m_mActorNames);
83
84 array<string> actorIds;
85 if (context.Read(actorIds))
86 snapshot.m_aActors.Resize(actorIds.Count());
87
88 context.ReadValue("queue", snapshot.m_aQueue);
89
90 if (UUID.IsUUID(currentActorId))
91 {
93 ctx.m_Snapshot = snapshot;
94 PersistenceWhenAvailableTask task(OnActorAvailable, ctx);
95 GetSystem().WhenAvailable(currentActorId, task, 30.0); // it may take some time after init to spawn the player character
96 }
97 else if (!currentActorId.IsEmpty())
98 {
99 snapshot.m_CurrentActor = GetGame().GetWorld().FindEntityByName(currentActorId);
100 }
101
102 if (actorIds)
103 {
104 foreach (int idx, string actorId : actorIds)
105 {
106 if (UUID.IsUUID(actorId))
107 {
109 ctx.m_Snapshot = snapshot;
110 ctx.m_iActorIdx = idx;
111 PersistenceWhenAvailableTask task(OnActorAvailable, ctx);
112 GetSystem().WhenAvailable(currentActorId, task, 30.0);
113 }
114 else
115 {
116 snapshot.m_aActors[idx] = GetGame().GetWorld().FindEntityByName(currentActorId);
117 }
118 }
119 }
120
121 TryApplySnapshot(snapshot);
122 return true;
123 }
124
125 //------------------------------------------------------------------------------------------------
126 protected static void OnActorAvailable(Managed instance, PersistenceDeferredDeserializeTask task, bool expired, Managed context)
127 {
128 auto actor = IEntity.Cast(instance);
129 if (!actor)
130 return;
131
132 auto ctx = SCR_VoiceoverSystemSerializerContext.Cast(context);
133 if (ctx.m_iActorIdx == -1)
134 {
135 ctx.m_Snapshot.m_CurrentActor = actor;
136 }
137 else
138 {
139 ctx.m_Snapshot.m_aActors[ctx.m_iActorIdx] = actor;
140 }
141
142 TryApplySnapshot(ctx.m_Snapshot);
143 }
144
145 //------------------------------------------------------------------------------------------------
146 protected static bool TryApplySnapshot(SCR_VoiceoverSystemSnapshot snapshot)
147 {
148 // Waiting for current actor to be linked
149 if (snapshot.m_sCurrentSoundEvent && !snapshot.m_CurrentActor)
150 return false;
151
152 // Waiting for any sequence actor to be linked
153 foreach (IEntity actor : snapshot.m_aActors)
154 {
155 if (!actor)
156 return false;
157 }
158
159 // Wait so player is mentally ready when the load ends to listen to voiceover
160 SCR_VoiceoverSystem voiceover = SCR_VoiceoverSystem.GetInstance();
161 GetGame().GetCallqueue().CallLater(voiceover.ApplySnapshot, 1000, false, snapshot);
162 return true;
163 }
164}
165
167{
168 ref SCR_VoiceoverSystemSnapshot m_Snapshot;
169 int m_iActorIdx = -1;
170}
class SCR_PersistentThreatSector GetTargetType()
ArmaReforgerScripted GetGame()
Definition game.c:1398
RplMode
Mode of replication.
Definition RplMode.c:9
enum EVehicleType IEntity
proto external string GetName()
void ApplySnapshot(notnull SCR_VoiceoverSystemSnapshot snapshot)
static SCR_VoiceoverSystem GetInstance()
SCR_VoiceoverSystemSnapshot CreateSnapshot()
bool Deserialize(notnull Managed instance, notnull LoadContext context)
ESerializeResult Serialize(notnull Managed instance, notnull SaveContext context)
Definition UUID.c:28
ESerializeResult
proto native bool IsEmpty()