DayZ 1.24
Loading...
Searching...
No Matches
PluginMessageManager.c
Go to the documentation of this file.
1
4class PluginMessageManager extends PluginBase
5{
6 int channelsUsed = 0;
8
10 {
11 for (int i = 0; i < NUM_OF_CHANNELS; i++)
12 channelList[i] = new array<ref MessageReceiverBase>;
13 }
14
16 void Broadcast(int index)
17 {
18 //Debug.Log("Broadcasting message on a channel: "+ ToString(index), "Messaging System");
20 //int test = channelList[index].Count();
21 for (int i = 0; i < x.Count(); i++)
22 {
24
25 if (mrb != NULL)
26 {
27 //string s = "Broadcasting message to: "+ToString(mrb);
28 //Log(s, LogTemplates.TEMPLATE_BROADCAST);
29 mrb.OnReceive(index);
30 }
31 }
32 }
33
35 void BroadcastInt(int index, int value)
36 {
37 //Debug.Log("Broadcasting message on a channel: "+ ToString(index), "Messaging System");
39 //int test = channelList[index].Count();
40 for (int i = 0; i < x.Count(); i++)
41 {
43
44 if (mrb)
45 {
46 //string s = "Broadcasting message to: "+ToString(mrb);
47 //Log(s, LogTemplates.TEMPLATE_BROADCAST);
48 mrb.OnReceiveInt(index, value);
49 }
50
51 }
52 }
53
54 void BroadcastFloat(int index, float value)
55 {
56 //Debug.Log("Broadcasting message on a channel: "+ ToString(index), "Messaging System");
58 //int test = channelList[index].Count();
59 for (int i = 0; i < x.Count(); i++)
60 {
62
63 if (mrb)
64 {
65 //string s = "Broadcasting message to: "+ToString(mrb);
66 //Log(s, LogTemplates.TEMPLATE_BROADCAST);
67 mrb.OnReceiveFloat(index, value);
68 }
69
70 }
71 }
72
73 void BroadcastString(int index, string value)
74 {
75 //Debug.Log("Broadcasting message on a channel: "+ ToString(index), "Messaging System");
77 //int test = channelList[index].Count();
78 for (int i = 0; i < x.Count(); i++)
79 {
80 if (x.Get(i))
81 {
82 Print("broadcasting message to: ");
83 Print(x.Get(i));
84 x.Get(i).OnReceiveString(index, value);
85 }
86 }
87 }
88
91 {
92 //Debug.Log("Broadcasting message on a channel: "+ ToString(index), "Messaging System");
94 //int test = channelList[index].Count();
95 for (int i = 0; i < x.Count(); i++)
96 {
97
98 if (x.Get(i))
99 x.Get(i).OnReceiveParam(index, params);
100
101 }
102 }
103
106 {
107 if (index > channelsUsed) //this is used to speed up the unsubscribeAll method, instead of all channels, we sweep just those in usage
108 channelsUsed = index;
110 if (chan.Find(receiver) >= 0) return;
111 chan.Insert(receiver);
112 }
113
115 {
117 int i = chan.Find(receiver);
118 if (i >= 0)
119 chan.Remove(i);
120 }
121
122 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)
123 {
124 //GetGame().ProfilerStart("UnsubscribeAll");
125 for (int i = 0; i <= channelsUsed; i++)
126 {
128 int c = chan.Find(receiver);
129 if (c >= 0)
130 chan.Remove(c);
131 }
132 //GetGame().ProfilerStop("UnsubscribeAll");
133 }
134}
Icon x
LayoutHolder Get(int x)
Definition Container.c:1014
Base Param Class with no parameters. Used as general purpose parameter overloaded with Param1 to Para...
Definition param.c:12
void BroadcastFloat(int index, float value)
void Broadcast(int index)
Broadcasts an empty message on a channel provided in the 'index' parameter.
void BroadcastParam(int index, Param params)
Broadcasts a message on a channel provided in the 'index' parameter, passes the Param type object to ...
void PluginMessageManager()
void Unsubscribe(MessageReceiverBase receiver, int index)
void UnsubscribeAll(MessageReceiverBase receiver)
void BroadcastString(int index, string value)
void BroadcastInt(int index, int value)
Broadcasts a message on a channel provided in the 'index' parameter, passes the Int variable.
void Subscribe(MessageReceiverBase receiver, int index)
Subscribes an object to listen to messages on a channel provided in the 'index' parameter.
proto void Print(void var)
Prints content of variable to console/log.
const int NUM_OF_CHANNELS
Definition constants.c:325