SLikeNet 0.1.3

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TeamBalancer.h
Go to the documentation of this file.
1 /*
2 * Original work: Copyright (c) 2014, Oculus VR, Inc.
3 * All rights reserved.
4 *
5 * This source code is licensed under the BSD-style license found in the
6 * RakNet License.txt file in the licenses directory of this source tree. An additional grant
7 * of patent rights can be found in the RakNet Patents.txt file in the same directory.
8 *
9 *
10 * Modified work: Copyright (c) 2017, SLikeSoft UG (haftungsbeschränkt)
11 *
12 * This source code was modified by SLikeSoft. Modifications are licensed under the MIT-style
13 * license found in the license.txt file in the root directory of this source tree.
14 */
15
21
22
23 #include "NativeFeatureIncludes.h"
24 #if _RAKNET_SUPPORT_TeamBalancer==1
25
26 #ifndef __TEAM_BALANCER_H
27 #define __TEAM_BALANCER_H
28
29 #include "PluginInterface2.h"
30 #include "memoryoverride.h"
31 #include "NativeTypes.h"
32 #include "DS_List.h"
33 #include "string.h"
34
35 namespace SLNet
36 {
38 class RakPeerInterface;
39
45
49 typedef unsigned char TeamId;
50
51 #define UNASSIGNED_TEAM_ID 255
52
58 class RAK_DLL_EXPORT TeamBalancer : public PluginInterface2
59 {
60 public:
61 // GetInstance() and DestroyInstance(instance*)
62 STATIC_FACTORY_DECLARATIONS(TeamBalancer)
63
64 TeamBalancer();
65 virtual ~TeamBalancer();
66
72 void SetTeamSizeLimit(TeamId team, unsigned short limit);
73
74 enum DefaultAssigmentAlgorithm
75 {
77 SMALLEST_TEAM,
79 FILL_IN_ORDER
80 };
86 void SetDefaultAssignmentAlgorithm(DefaultAssigmentAlgorithm daa);
87
95 void SetForceEvenTeams(bool force);
96
102 void SetLockTeams(bool lock);
103
112 void RequestSpecificTeam(NetworkID memberId, TeamId desiredTeam);
113
118 void CancelRequestSpecificTeam(NetworkID memberId);
119
124 void RequestAnyTeam(NetworkID memberId);
125
132 TeamId GetMyTeam(NetworkID memberId) const;
133
138 void DeleteMember(NetworkID memberId);
139
140 struct TeamMember
141 {
142 RakNetGUID memberGuid;
143 NetworkID memberId;
144 TeamId currentTeam;
145 TeamId requestedTeam;
146 };
147 struct MyTeamMembers
148 {
149 NetworkID memberId;
150 TeamId currentTeam;
151 TeamId requestedTeam;
152 };
153
154 protected:
155
157 virtual PluginReceiveResult OnReceive(Packet *packet);
159 virtual void OnClosedConnection(const SystemAddress &systemAddress, RakNetGUID rakNetGUID, PI2_LostConnectionReason lostConnectionReason );
161 void OnAttach(void);
162
163 void OnStatusUpdateToNewHost(Packet *packet);
164 void OnCancelTeamRequest(Packet *packet);
165 void OnRequestAnyTeam(Packet *packet);
166 void OnRequestSpecificTeam(Packet *packet);
167
168 RakNetGUID hostGuid;
169 DefaultAssigmentAlgorithm defaultAssigmentAlgorithm;
170 bool forceTeamsToBeEven;
171 bool lockTeams;
172 // So if we lose the connection while processing, we request the same info of the new host
173 DataStructures::List<MyTeamMembers> myTeamMembers;
174
175 DataStructures::List<unsigned short> teamLimits;
176 DataStructures::List<unsigned short> teamMemberCounts;
177 DataStructures::List<TeamMember> teamMembers;
178 unsigned int GetMemberIndex(NetworkID memberId, RakNetGUID guid) const;
179 unsigned int AddTeamMember(const TeamMember &tm); // Returns index of new member
180 void RemoveTeamMember(unsigned int index);
181 void EvenTeams(void);
182 unsigned int GetMemberIndexToSwitchTeams(const DataStructures::List<TeamId> &sourceTeamNumbers, TeamId targetTeamNumber);
183 void GetOverpopulatedTeams(DataStructures::List<TeamId> &overpopulatedTeams, int maxTeamSize);
184 void SwitchMemberTeam(unsigned int teamMemberIndex, TeamId destinationTeam);
185 void NotifyTeamAssigment(unsigned int teamMemberIndex);
186 bool WeAreHost(void) const;
187 PluginReceiveResult OnTeamAssigned(Packet *packet);
188 PluginReceiveResult OnRequestedTeamChangePending(Packet *packet);
189 PluginReceiveResult OnTeamsLocked(Packet *packet);
190 void GetMinMaxTeamMembers(int &minMembersOnASingleTeam, int &maxMembersOnASingleTeam);
191 TeamId GetNextDefaultTeam(void); // Accounting for team balancing and team limits, get the team a player should be placed on
192 bool TeamWouldBeOverpopulatedOnAddition(TeamId teamId, unsigned int teamMemberSize); // Accounting for team balancing and team limits, would this team be overpopulated if a member was added to it?
193 bool TeamWouldBeUnderpopulatedOnLeave(TeamId teamId, unsigned int teamMemberSize);
194 TeamId GetSmallestNonFullTeam(void) const;
195 TeamId GetFirstNonFullTeam(void) const;
196 void MoveMemberThatWantsToJoinTeam(TeamId teamId);
197 TeamId MoveMemberThatWantsToJoinTeamInternal(TeamId teamId);
198 void NotifyTeamsLocked(RakNetGUID target, TeamId requestedTeam);
199 void NotifyTeamSwitchPending(RakNetGUID target, TeamId requestedTeam, NetworkID memberId);
200 void NotifyNoTeam(NetworkID memberId, RakNetGUID target);
201 void SwapTeamMembersByRequest(unsigned int memberIndex1, unsigned int memberIndex2);
202 void RemoveByGuid(RakNetGUID rakNetGUID);
203 bool TeamsWouldBeEvenOnSwitch(TeamId t1, TeamId t2);
204
205 };
206
207 } // namespace SLNet
208
209 #endif
210
211 #endif // _RAKNET_SUPPORT_*