Ejemplo n.º 1
0
 public NeutronCache(int id, byte[] buffer, NeutronPlayer owner, CachedPacket packet, CacheMode cacheMode)
 {
     Id        = id;
     Buffer    = buffer;
     Owner     = owner;
     Packet    = packet;
     CacheMode = cacheMode;
 }
    protected void HandleGetCached(Player mSender, CachedPacket packetToSendCache)
    {
        List <byte[]> iP = new List <byte[]>();

        //========================================================\\
        if (packetToSendCache == CachedPacket.ResyncInstantiate)
        {
            foreach (var _ps in playersState.Values)
            {
                if (_ps._Player.Equals(mSender))
                {
                    continue;
                }
                if (_ps._Player.currentChannel == mSender.currentChannel)
                {
                    using (NeutronWriter writer = new NeutronWriter())
                    {
                        writer.Write(_ps.lastPosition);
                        writer.Write(_ps.lastRotation);
                        writer.Write(_ps._prefabName);
                        writer.Write(_ps._Player.Serialize());
                        //========================================================\\
                        iP.Add(writer.GetBuffer());
                    }
                }
                else
                {
                    continue;
                }
            }
            OnEndBuffer();
        }

        void OnEndBuffer()
        {
            if (iP.Count > 0)
            {
                using (NeutronWriter writer = new NeutronWriter())
                {
                    writer.WritePacket(CachedPacket.ResyncInstantiate);
                    writer.Write(iP.ToArray().Serialize());
                    //=============================================================================\\
                    mSender.Send(SendTo.Only, writer.GetBuffer(), Broadcast.None, null, ProtocolType.Tcp, null, null);
                }
            }
        }
    }
Ejemplo n.º 3
0
 public static void AddCache(int id, int viewId, NeutronStream.IWriter writer, NeutronPlayer player, CacheMode cache, CachedPacket cachedPacket)
 {
     //LogHelper.Error(ThreadHelper.GetThreadID());
     if (cache != CacheMode.None)
     {
         INeutronMatchmaking neutronMatchmaking = player.Matchmaking;
         if (neutronMatchmaking != null)
         {
             NeutronCache dataCache = new NeutronCache(id, writer.ToArray(), player, cachedPacket, cache);
             neutronMatchmaking.Add(dataCache, viewId);
         }
         else
         {
             LogHelper.Error("Cache: Matchmaking not found!");
         }
     }
 }