How to read and reset a pooled token in a pooled token?
SPF
✭
in Photon Bolt
Example codes:
My confusion is that Pooled tokens need to initialized in this way: ProtocolTokenUtils.GetToken<Card>()
But "ReadToken()" in "Read" method and "card = default" in "Reset" method are not using the GetToken way to make new instance.
Right now I'm using normal un-pooled tokens for Card: "Card: IProtocolToken". But I do want to make Card as pooled ones to take advantages of the pools, since "Card" tokens are used very frequently.
Thank you!
P.S. I do need a token within another token to pass complex data along with event. The root token will be sent with event, and the inner tokens are the complex data container.
public class DrawCardEventToken : PooledProtocolToken { public byte actorID; public Card card; public override void Read(UdpPacket packet) { actorID = packet.ReadByte(); card = packet.ReadToken() as Card; // Need help here!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! } public override void Write(UdpPacket packet) { packet.WriteByte(actorID); packet.WriteToken(card); } public override void Reset() { actorID = default; card = default; // and here!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! } }
public class Card: PooledProtocolToken { public int key; public int attack; public override void Read(UdpPacket packet) { key = packet.ReadInt(); attack = packet.ReadInt(); } public override void Write(UdpPacket packet) { packet.WriteInt(key); packet.WriteInt(attack); } public override void Reset() { key = default(int); attack = default(int); } static public Card NewCard(int key, int id) { var card = ProtocolTokenUtils.GetToken<Card>(); card.key = key; card.attack = 10; return card; } }
My confusion is that Pooled tokens need to initialized in this way: ProtocolTokenUtils.GetToken<Card>()
But "ReadToken()" in "Read" method and "card = default" in "Reset" method are not using the GetToken way to make new instance.
Right now I'm using normal un-pooled tokens for Card: "Card: IProtocolToken". But I do want to make Card as pooled ones to take advantages of the pools, since "Card" tokens are used very frequently.
Thank you!
P.S. I do need a token within another token to pass complex data along with event. The root token will be sent with event, and the inner tokens are the complex data container.
0