Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
pluginmessagemanager.c
Go to the documentation of this file.
1 
4 class PluginMessageManager extends PluginBase
5 {
6  int channelsUsed = 0;
8 
9  void PluginMessageManager()
10  {
11  for (int i = 0; i < NUM_OF_CHANNELS; i++)
12  {
13  channelList[i] = new array<ref MessageReceiverBase>;
14  }
15  }
16 
18  void Broadcast(int index)
19  {
20  //Debug.Log("Broadcasting message on a channel: "+ ToString(index), "Messaging System");
21  array<ref MessageReceiverBase> x = channelList[index];
22  //int test = channelList[index].Count();
23  for(int i = 0; i < x.Count(); i++)
24  {
25  MessageReceiverBase mrb = x.Get(i);
26 
27  if( mrb != NULL )
28  {
29  //string s = "Broadcasting message to: "+ToString(mrb);
30  //Log(s, LogTemplates.TEMPLATE_BROADCAST);
31  mrb.OnReceive(index);
32  }
33  }
34  }
35 
37  void BroadcastInt(int index, int value)
38  {
39  //Debug.Log("Broadcasting message on a channel: "+ ToString(index), "Messaging System");
40  array<ref MessageReceiverBase> x = channelList[index];
41  //int test = channelList[index].Count();
42  for(int i = 0; i < x.Count(); i++)
43  {
44  MessageReceiverBase mrb = x.Get(i);
45 
46  if( mrb )
47  {
48  //string s = "Broadcasting message to: "+ToString(mrb);
49  //Log(s, LogTemplates.TEMPLATE_BROADCAST);
50  mrb.OnReceiveInt(index, value);
51  }
52 
53  }
54  }
55 
56  void BroadcastFloat(int index, float value)
57  {
58  //Debug.Log("Broadcasting message on a channel: "+ ToString(index), "Messaging System");
59  array<ref MessageReceiverBase> x = channelList[index];
60  //int test = channelList[index].Count();
61  for(int i = 0; i < x.Count(); i++)
62  {
63  MessageReceiverBase mrb = x.Get(i);
64 
65  if( mrb )
66  {
67  //string s = "Broadcasting message to: "+ToString(mrb);
68  //Log(s, LogTemplates.TEMPLATE_BROADCAST);
69  mrb.OnReceiveFloat(index, value);
70  }
71 
72  }
73  }
74 
75  void BroadcastString(int index, string value)
76  {
77  //Debug.Log("Broadcasting message on a channel: "+ ToString(index), "Messaging System");
78  array<ref MessageReceiverBase> x = channelList[index];
79  //int test = channelList[index].Count();
80  for(int i = 0; i < x.Count(); i++)
81  {
82  if( x.Get(i) )
83  {
84  Print("broadcasting message to: ");
85  Print(x.Get(i));
86  x.Get(i).OnReceiveString(index, value);
87  }
88  }
89  }
90 
92  void BroadcastParam(int index, Param params)
93  {
94  //Debug.Log("Broadcasting message on a channel: "+ ToString(index), "Messaging System");
95  array<ref MessageReceiverBase> x = channelList[index];
96  //int test = channelList[index].Count();
97  for(int i = 0; i < x.Count(); i++)
98  {
99 
100  if( x.Get(i) )
101  {
102  x.Get(i).OnReceiveParam(index, params);
103  }
104 
105  }
106  }
107 
109  void Subscribe(MessageReceiverBase receiver, int index)
110  {
111  if(index > channelsUsed) //this is used to speed up the unsubscribeAll method, instead of all channels, we sweep just those in usage
112  {
113  channelsUsed = index;
114  }
115  array<ref MessageReceiverBase> chan = channelList[index];
116  if( chan.Find(receiver) >= 0 ) return;
117  chan.Insert(receiver);
118  }
119 
120  void Unsubscribe(MessageReceiverBase receiver, int index)
121  {
122  array<ref MessageReceiverBase> chan = channelList[index];
123  int i = chan.Find(receiver);
124  if( i >= 0 )
125  {
126  chan.Remove(i);
127  }
128  }
129 
130  void UnsubscribeAll(MessageReceiverBase receiver)//REWORK.V: this is slow, should be made quicker(by registering all subscribers in a separate array upon their subscription and then going through this array instead)
131  {
132  //GetGame().ProfilerStart("UnsubscribeAll");
133  for (int i = 0; i <= channelsUsed; i++)
134  {
135  array<ref MessageReceiverBase> chan = channelList[i];
136  int c = chan.Find(receiver);
137  if( c >= 0 )
138  {
139  chan.Remove(c);
140  }
141  }
142  //GetGame().ProfilerStop("UnsubscribeAll");
143  }
144 }
Param
Base Param Class with no parameters. Used as general purpose parameter overloaded with Param1 to Para...
Definition: param.c:11
Print
proto void Print(void var)
Prints content of variable to console/log.
PluginBase
Definition: pluginadminlog.c:1
MessageReceiverBase
Definition: messagereceiverbase.c:1
array< ref MessageReceiverBase >
x
Icon x
NUM_OF_CHANNELS
const int NUM_OF_CHANNELS
Definition: constants.c:325