Package com.smartfoxserver.util
Interface IPlayerIdGenerator
- All Known Implementing Classes:
DefaultPlayerIdGenerator
public interface IPlayerIdGenerator
Overview
The interface provides the blueprint for a PlayerId Generator implementation used in game Rooms. The purpose of a PlayerId Generator is to create unique player ids to users joining a Game Room. By default SmartFoxServer provides its default implementation which uses incremental integer values starting from index 1.-
Method Summary
Modifier and TypeMethodDescriptionvoidfreePlayerSlot(int playerId) This method is called by the parent Room when a Player leaves the game and his player slot can be freed up.Get a reference to the parent RoomintReturn a new player slot/idvoidinit()The init() method is invoked immediately after the successful creation of the Game Room.voidThis method is invoked upon a Room size change.voidsetParentRoom(Room room)
-
Method Details
-
init
void init()The init() method is invoked immediately after the successful creation of the Game Room. Here the developer can add any initialization code. It is recommended to use this method instead of the constructor to setup your data structures etc... This is because only in the init() method you will be able to access the parent Room.- See Also:
-
getPlayerSlot
int getPlayerSlot()Return a new player slot/id- Returns:
- the new player id
-
freePlayerSlot
void freePlayerSlot(int playerId) This method is called by the parent Room when a Player leaves the game and his player slot can be freed up.- Parameters:
playerId- the id that should be freed up
-
onRoomResize
void onRoomResize()This method is invoked upon a Room size change. Depending on the logic that generates Player id(s) it might be necessary to take rearrange player id data after a Room resize. -
setParentRoom
- Internal
-
getParentRoom
Room getParentRoom()Get a reference to the parent Room- Returns:
- the parent Room
-