Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
displaystatus.c
Go to the documentation of this file.
1 enum DSLevels
2 {
3  NORMAL = 0,//no bit, default
4  WARNING = 1,//first bit
5  CRITICAL = 2,//second bit
6  BLINKING = 3,//first + second bit
7  EXTRA = 4,//third bit
8 }
9 
10 enum DSLevelsTemp
11 {
12  NORMAL = 0,//no bit, default
13  WARNING_MINUS = 1,//
14  CRITICAL_MINUS = 2,//
15  BLINKING_MINUS = 3,//
16  WARNING_PLUS = 4,//
17  CRITICAL_PLUS = 5,//
18  BLINKING_PLUS = 6,//
19 }
20 
21 class VirtualHud
22 {
23  const int NUMBER_OF_MASKS = 2;//how many INT numbers we need to accommodate all elements
25  //ref map<int, ref DisplayElement> m_Elements;
26  const int NUMBER_OF_ELEMENTS = eDisplayElements.COUNT;
32  string m_System = "VirtualHud";
33 
35 
36  void VirtualHud(PlayerBase player)
37  {
38  m_Player = player;
39  m_LastTick = 0;
40 
41  RegisterElement(new BadgeStuffed(m_Player));
42  RegisterElement(new BadgeWet(m_Player));
43  RegisterElement(new BadgeSick(m_Player));
44  RegisterElement(new BadgePills(m_Player));
45  RegisterElement(new BadgePoisoned(m_Player));
46  RegisterElement(new BadgeFracture(m_Player));
47  RegisterElement(new TendencyHealth(m_Player));
48  RegisterElement(new TendencyBlood(m_Player));
49  RegisterElement(new TendencyTemperature(m_Player));
50 
51  RegisterElement(new TendencyHunger(m_Player));
52  RegisterElement(new TendencyThirst(m_Player));
53  RegisterElement(new TendencyBacteria(m_Player));
54  RegisterElement(new BadgeHeartbeat(m_Player));
55  RegisterElement(new BadgeLegs(m_Player));
56 
57 
58  RegisterElement(new ElementStance(m_Player));// client only
59  RegisterElement(new BadgeBleeding(m_Player));// client only
60 
61 
62  mission = GetGame().GetMission();
63  if ( mission )
64  {
65  m_Hud = mission.GetHud();
66  }
67  //UpdateStatus();
68  }
69 
70 
72  {
73  if ( GetGame().IsServer() )
74  {
76  {
77  SendRPC();
78  m_LastTick = GetGame().GetTime();
79  }
80  }
81  if ( !GetGame().IsDedicatedServer() )
82  {
84  //DisplayPresence();
85  }
86  }
87 
89  {
90  int id = element.GetType();
91  m_Elements[id] = element;
92  //Log("adding element:"+id.ToString());
93  }
94 
95  DisplayElementBase GetElement(eDisplayElements element_id)
96  {
97  if ( element_id < 0 || element_id >= NUMBER_OF_ELEMENTS )
98  {
99  return null;
100  }
101  return m_Elements[element_id];
102  }
103 
104  //this will serialize all elements and 'compresses' them into integer(s) through bit shifting, these integers are placed into an array
105  void SerializeElements(ref array<int> mask_array)
106  {
107  int offset = 0;
108  int mask = 0;
109 
110  for (int i = 0; i < NUMBER_OF_ELEMENTS; i++)
111  {
112  if ( GetElement(i) && !GetElement(i).IsClientOnly() )
113  {
114  if ( (GetElement(i).GetNumberOfBits() + offset) > BIT_INT_SIZE )
115  {
116  mask_array.Insert(mask);
117  offset = 0;
118  mask = 0;
119  }
120  mask = mask | (GetElement(i).GetValue() << offset);
121  offset = offset + GetElement(i).GetNumberOfBits();
122  }
123  }
124  mask_array.Insert(mask);
125  }
126 
127  void DeserializeElements(ref array<int> mask_array)//extracts elements from mask
128  {
129  int maskArrayIndex = 0;
130  int offset = 0;
131  int mask = 0;
132 
133  for (int i = 0; i < NUMBER_OF_ELEMENTS;i++)
134  {
135  if ( GetElement(i) && !GetElement(i).IsClientOnly() )
136  {
137  //Log("entity> " + ToString(GetElement(i)) );
138  if (offset + GetElement(i).GetNumberOfBits() > BIT_INT_SIZE)
139  {
140  maskArrayIndex++;
141  offset = 0;
142  }
143  mask = mask_array.Get(maskArrayIndex);
144  int value = BitToDec( mask, offset, GetElement(i).GetCompareMask() );
145  offset = offset + GetElement(i).GetNumberOfBits();
146  GetElement(i).SetValue( value );
147  }
148  }
149  }
150 
151  int BitToDec(int mask, int index, int compareMask)
152  {
153  int value = mask & (compareMask << index);
154  value = value >> index;
155  return value;
156  }
157 
158 
160  {
161  for (int i = 0; i < NUMBER_OF_ELEMENTS; i++)
162  {
163  PrintString(i.ToString() +": "+ GetElement(i).m_Value.ToString() );
164  }
165  }
166 
167  void SendRPC()
168  {
169  array<int> mask_array = new array<int>;
170  SerializeElements(mask_array);
171  if ( !m_LastSentArray || !AreArraysSame(m_LastSentArray, mask_array) )
172  {
173  ScriptRPC rpc = new ScriptRPC();
174  rpc.Write(mask_array);
175  rpc.Send(m_Player, ERPCs.RPC_SYNC_DISPLAY_STATUS, false, m_Player.GetIdentity());
176  m_LastSentArray = mask_array;
177  }
178  }
179 
180  bool AreArraysSame( notnull array<int> array_a, notnull array<int> array_b )
181  {
182  if ( array_a.Count() != array_b.Count() ) return false;
183  for (int i = 0; i <array_a.Count(); i++)
184  {
185  if ( array_a.Get(i) != array_b.Get(i) )
186  {
187  return false;
188  }
189  }
190  return true;
191  }
192 
194  {
195  for (int i = 0; i < NUMBER_OF_ELEMENTS;i++)
196  {
197  DisplayElementBase element = GetElement(i);
198  if ( element && element.IsClientOnly() && element.IsValueChanged() )
199  element.UpdateHUD();
200  }
201  }
202 
204  {
205  //Log("UpdateStatus called for entity: "+ToString(m_Player));
206  for (int i = 0; i < NUMBER_OF_ELEMENTS; i++)
207  {
208  DisplayElementBase element = GetElement(i);
209  if ( element && !element.IsClientOnly() && element.IsValueChanged() )
210  {
211  element.UpdateHUD();
212  }
213  }
214  }
215 
216  void OnRPC(ParamsReadContext ctx)//on Client
217  {
218  //Log("OnRPC called");
219  array<int> mask_array = new array<int>;
220  ctx.Read(mask_array);
221  DeserializeElements(mask_array);
222  UpdateStatus();
223  }
224 
225  void Debug()
226  {
227  Log("debug");
228  PluginPlayerStatus m_ModulePlayerStatus = PluginPlayerStatus.Cast(GetPlugin(PluginPlayerStatus));
229  m_ModulePlayerStatus.DisplayTendency(NTFKEY_HUNGRY, 2);
230  }
231 }
GetGame
proto native CGame GetGame()
m_Player
PlayerBase m_Player
Definition: displaystatus.c:31
mission
Mission mission
Definition: displaystatus.c:28
m_Hud
Hud m_Hud
Definition: displaystatus.c:29
Mission
Mission class.
Definition: gameplay.c:670
CRITICAL
@ CRITICAL
Definition: displaystatus.c:5
VIRTUAL_HUD_UPDATE_INTERVAL
VIRTUAL_HUD_UPDATE_INTERVAL
how often virtual hud checks if there is a difference since last sync
VirtualHud
void VirtualHud(PlayerBase player)
Definition: displaystatus.c:36
Log
class LogTemplates Log(string message, LogTemplateID template_id=0)
Creates debug log (optional) from LogTemplate which are registred.
Definition: logtemplates.c:75
NTFKEY_HUNGRY
const int NTFKEY_HUNGRY
Definition: _constants.c:34
SendRPC
void SendRPC()
Definition: displaystatus.c:167
m_LastTick
int m_LastTick
Definition: displaystatus.c:30
m_LastSentArray
ref array< int > m_LastSentArray
Definition: displaystatus.c:24
WARNING_PLUS
enum DSLevels WARNING_PLUS
GetElement
DisplayElementBase GetElement(eDisplayElements element_id)
Definition: displaystatus.c:95
m_Value
string m_Value
Definition: enentity.c:5
GetPlugin
PluginBase GetPlugin(typename plugin_type)
Definition: pluginmanager.c:316
Serializer
Serialization general interface. Serializer API works with:
Definition: serializer.c:55
OnRPC
void OnRPC(ParamsReadContext ctx)
Definition: displaystatus.c:216
WARNING
@ WARNING
Definition: displaystatus.c:4
PrintElements
void PrintElements()
Definition: displaystatus.c:159
PlayerBase
Definition: playerbaseclient.c:1
BitToDec
int BitToDec(int mask, int index, int compareMask)
Definition: displaystatus.c:151
NUMBER_OF_MASKS
enum DSLevels NUMBER_OF_MASKS
WARNING_MINUS
enum DSLevels WARNING_MINUS
RegisterElement
void RegisterElement(DisplayElementBase element)
Definition: displaystatus.c:88
BLINKING
@ BLINKING
Definition: displaystatus.c:6
BLINKING_PLUS
enum DSLevels BLINKING_PLUS
NORMAL
enum DSLevels NORMAL
Definition: displaystatus.c:3
DisplayElementBase
Definition: displayelementbadge.c:1
ScriptRPC
Definition: gameplay.c:104
OnScheduledTick
void OnScheduledTick()
Definition: displaystatus.c:71
CRITICAL_PLUS
enum DSLevels CRITICAL_PLUS
PrintString
void PrintString(string s)
Helper for printing out string expression. Example: PrintString("Hello " + var);.
Definition: enscript.c:345
array
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
Definition: isboxcollidinggeometryproxyclasses.c:27
CRITICAL_MINUS
enum DSLevels CRITICAL_MINUS
DeserializeElements
void DeserializeElements(ref array< int > mask_array)
Definition: displaystatus.c:127
m_ModulePlayerStatus
PluginPlayerStatus m_ModulePlayerStatus
Definition: modifierbase.c:30
BLINKING_MINUS
enum DSLevels BLINKING_MINUS
ImmediateUpdate
void ImmediateUpdate()
Definition: displaystatus.c:193
Debug
void Debug()
Definition: displaystatus.c:225
rpcParams
ref array< ref Param > rpcParams
Definition: displaystatus.c:34
ERPCs
ERPCs
Definition: erpcs.c:1
GetTime
float GetTime()
Definition: notificationsystem.c:35
NUMBER_OF_ELEMENTS
const int NUMBER_OF_ELEMENTS
Definition: displaystatus.c:26
DSLevels
DSLevels
Definition: displaystatus.c:1
SerializeElements
void SerializeElements(ref array< int > mask_array)
Definition: displaystatus.c:105
BIT_INT_SIZE
const int BIT_INT_SIZE
Definition: bitarray.c:4
EXTRA
@ EXTRA
Definition: displaystatus.c:7
AreArraysSame
bool AreArraysSame(notnull array< int > array_a, notnull array< int > array_b)
Definition: displaystatus.c:180
UpdateStatus
void UpdateStatus()
Definition: displaystatus.c:203
m_Elements
ref DisplayElementBase m_Elements[NUMBER_OF_ELEMENTS]
Definition: displaystatus.c:27
m_System
string m_System
Definition: displaystatus.c:32
Hud
Definition: gameplay.c:623