//void Update()
    //{
    //    timer += Time.deltaTime;
    //    if (timer >= 1)
    //    {
    //        timer = 0;
    //        if (!imageLoaded && OwnerID != new CSteamID(0))
    //        {
    //            Texture2D tex = GetUserAvatar(OwnerID);
    //            SetTex(tex);
    //        }
    //    }
    //}

    public void SelectAvatar()
    {
        if (Client.Users == null)
        {
            return;
        }

        for (int i = 0; i < Client.Users.Count; i++)
        {
            string data = SteamMatchmaking.GetLobbyMemberData(Client.Lobby.LobbyID, Client.Users[i].SteamID, "AvatarID");
            if (data == "")
            {
                continue;
            }
            int index;
            if (int.TryParse(data, out index))
            {
                if (index == avatarID)
                {
                    return;
                }
            }
        }
        byte[] d = ArrayPool <byte> .Get(1);

        d[0] = (byte)avatarID;

        Client.SendPacketToHost(d, 0, 1, PacketType.RequestAvatarSelection, EP2PSend.k_EP2PSendReliable);

        ArrayPool <byte> .Recycle(d);
    }
示例#2
0
    void ControlAvatarDisponibility(byte[] data, uint dataLenght, CSteamID sender)
    {
        int avatarIndex = data[0];

        for (int i = 0; i < Client.Users.Count; i++)
        {
            string userIndex = SteamMatchmaking.GetLobbyMemberData(Client.Lobby.LobbyID, Client.Users[i].SteamID, "AvatarID");
            if (userIndex == "")
            {
                continue;
            }
            int index;
            if (int.TryParse(userIndex, out index))
            {
                if (index == avatarIndex)
                {
                    return;
                }
            }
        }

        byte[] d = ArrayPool <byte> .Get(1);

        d[0] = (byte)avatarIndex;

        Client.SendPacket(d, 0, d.Length, PacketType.AnswerAvatarSelection, Client.MyID, sender, EP2PSend.k_EP2PSendReliable);

        ArrayPool <byte> .Recycle(d);
    }
示例#3
0
        /// <summary>
        /// Returns a new Query representing the current Query where each element has been
        /// mapped onto a new Query, and then all Queries are concatenated into a
        /// single long sequence.
        ///
        /// For example:
        ///   (1, 2, 3, 4).Query().SelectMany(count => new List().Fill(count, count.ToString()).Query())
        /// Would result in:
        ///   ("1", "2", "2", "3", "3", "3", "4", "4", "4", "4")
        /// </summary>
        public static Query <K> SelectMany <T, K>(this Query <T> query, Func <T, Query <K> > selector)
        {
            using (var slice = query.Deconstruct()) {
                var slices = ArrayPool <Query <K> .QuerySlice> .Spawn(slice.Count);

                int totalCount = 0;
                for (int i = 0; i < slice.Count; i++)
                {
                    slices[i]   = selector(slice[i]).Deconstruct();
                    totalCount += slices[i].Count;
                }

                var dstArray = ArrayPool <K> .Spawn(totalCount);

                int targetIndex = 0;
                for (int i = 0; i < slice.Count; i++)
                {
                    Array.Copy(slices[i].BackingArray, 0, dstArray, targetIndex, slices[i].Count);
                    targetIndex += slices[i].Count;
                    slices[i].Dispose();
                }

                ArrayPool <Query <K> .QuerySlice> .Recycle(slices);

                return(new Query <K>(dstArray, totalCount));
            }
        }
示例#4
0
    private void EnemyDeath(Enemy enemy)
    {
        if (HostEnemySpawner.Instance.enemiesCount < HostEnemySpawner.MAX_NUM_ENEMIES)
        {
            if (enemy.Destroy)
            {
                byte[] d = ArrayPool <byte> .Get(sizeof(int));

                ByteManipulator.Write(d, 0, enemy.NetworkId.NetworkId);

                Client.SendPacketToInGameUsers(d, 0, d.Length, PacketType.EnemyDeath, Steamworks.EP2PSend.k_EP2PSendReliable);

                ArrayPool <byte> .Recycle(d);

                enemy.Destroy = false;
            }
            enemy.randomSpawnTimer -= Time.deltaTime;
            if (enemy.randomSpawnTimer <= 0)
            {
                HostEnemySpawner.Instance.InstantiateEnemy();
                enemy.randomSpawnTimer = UnityEngine.Random.Range(0f, 5.0f);
                enemy.Recycling        = false;
                EnemyToRecycleToRemove.Add(enemy);
            }
        }
    }
示例#5
0
    public void SendShotCall()
    {
        byte[] d = ArrayPool <byte> .Get(sizeof(int));

        ByteManipulator.Write(d, 0, gnOnject.NetworkId);

        Client.SendPacketToInGameUsers(d, 0, d.Length, PacketType.ShootCall, Client.MyID, Steamworks.EP2PSend.k_EP2PSendUnreliable, false);

        ArrayPool <byte> .Recycle(d);
    }
示例#6
0
        /// <summary>
        /// Disposes of the resources that this query holds.  The Query cannot be
        /// used after this method is called.
        /// </summary>
        public void Dispose()
        {
            _validator.Validate();

            ArrayPool <T> .Recycle(_array);

            Validator.Invalidate(_validator);

            _array = null;
            _count = 0;
        }
示例#7
0
    void SendHitToHost(int id)
    {
        byte[] data = ArrayPool <byte> .Get(sizeof(int));

        ByteManipulator.Write(data, 0, id);

        Client.SendPacketToHost(data, 0, data.Length, PacketType.ShootHitServer, Steamworks.EP2PSend.k_EP2PSendReliable);

        ArrayPool <byte> .Recycle(data);

        Debug.Log("hit");
    }
        public void RecycleArray()
        {
            var array = ArrayPool <byte> .Spawn(4);

            ArrayPool <byte> .Recycle(array);

            var memBefore = GC.GetTotalMemory(true);

            ArrayPool <byte> .Spawn(4);

            var memAfter = GC.GetTotalMemory(true);

            Assert.IsTrue(memAfter <= memBefore);
        }
示例#9
0
    void Send(byte[] data, int startIndex, int length, PacketType command, CSteamID sender, CSteamID receiver, EP2PSend sendType)
    {
        if (MyID == receiver)
        {
            InvokeCommand((int)command, data, (uint)length, sender);
            return;
        }

        byte[] toSend = ArrayPool <byte> .Get(length + HeaderLength);

        ByteManipulator.Write(toSend, 0, (byte)command);
        ByteManipulator.Write(toSend, sizeof(byte), (ulong)sender);
        ByteManipulator.Write <byte>(data, startIndex, toSend, HeaderLength, length);

        SteamNetworking.SendP2PPacket(receiver, toSend, (uint)toSend.Length, sendType);

        ArrayPool <byte> .Recycle(toSend);
    }
示例#10
0
        /// <summary>
        /// Returns a new Query that represents the combination of this query sequence with a Collection.
        /// The two sequences are combined element-by-element using a selector function.
        /// The resulting sequence has a length equal to the smaller of the two sequences.
        ///
        /// For example:
        ///   sequenceA = (A, B, C, D)
        ///   sequenceB = (E, F, G, H)
        ///   sequenceA.Query().Zip(sequenceB, (a, b) => a + b)
        /// Would result in:
        ///   (AE, BF, CG, DH)
        /// </summary>
        public static Query <V> Zip <T, K, V>(this Query <T> query, ICollection <K> collection, Func <T, K, V> selector)
        {
            using (var slice = query.Deconstruct()) {
                int resultCount = Mathf.Min(slice.Count, collection.Count);
                var resultArray = ArrayPool <V> .Spawn(resultCount);

                var tmpArray = ArrayPool <K> .Spawn(collection.Count);

                collection.CopyTo(tmpArray, 0);

                for (int i = 0; i < resultCount; i++)
                {
                    resultArray[i] = selector(slice[i], tmpArray[i]);
                }

                ArrayPool <K> .Recycle(tmpArray);

                return(new Query <V>(resultArray, resultCount));
            }
        }
示例#11
0
    void Receive(uint lenght)
    {
        byte[] receiver = ArrayPool <byte> .Get((int)lenght);

        uint     dataLenght;
        CSteamID sender;

        SteamNetworking.ReadP2PPacket(receiver, lenght, out dataLenght, out sender);

        int      command      = receiver[0];
        CSteamID packetSender = (CSteamID)ByteManipulator.ReadUInt64(receiver, 1);

        int finalLength = (int)lenght - HeaderLength;

        ByteManipulator.Write <byte>(receiver, HeaderLength, receiver, 0, finalLength);

        InvokeCommand(command, receiver, (uint)finalLength, packetSender);

        ArrayPool <byte> .Recycle(receiver);
    }
        /// <summary>
        /// Returns true if any element in the Query is equal to a specific value.
        /// </summary>
        public static bool Contains <T>(this Query <T> query, T item)
        {
            T[] array;
            int count;

            query.Deconstruct(out array, out count);

            var comparer = EqualityComparer <T> .Default;

            for (int i = 0; i < count; i++)
            {
                if (comparer.Equals(item, array[i]))
                {
                    ArrayPool <T> .Recycle(array);

                    return(true);
                }
            }

            ArrayPool <T> .Recycle(array);

            return(false);
        }
示例#13
0
 public void Dispose()
 {
     ArrayPool <T> .Recycle(BackingArray);
 }
示例#14
0
 public void Dispose()
 {
     ArrayPool <T> .Recycle(_array);
 }
示例#15
0
    private void Update()
    {
        if (Input.GetKeyDown(resetKeycode))
        {
            ResetSimulation();
        }

        if ((loop && mainState->time > loopTime) || respawnMode)
        {
            ResetSimulation();
            return;
        }

        Random.InitState(Time.frameCount);
        _seed = Random.Range(int.MinValue, int.MaxValue);

        if (simulate)
        {
            stepSimulation();
        }

        if (_enableTrails)
        {
            using (new ProfilerSample("Simulate Trails")) {
                if (_profileTrails)
                {
                    var stopwatch = new System.Diagnostics.Stopwatch();
                    stopwatch.Reset();
                    stopwatch.Start();
                    const int FRAMES_TO_TEST = 1000;
                    for (int i = 0; i < FRAMES_TO_TEST; i++)
                    {
                        NBodyC.StepGalaxy(_trailState);
                    }
                    double seconds         = stopwatch.ElapsedTicks / (double)System.Diagnostics.Stopwatch.Frequency;
                    double framesPerSecond = FRAMES_TO_TEST / seconds;
                    _trailFramerate = framesPerSecond;
                    Debug.Log("#####: " + _trailFramerate);
                }
                else
                {
                    int simTime = 0;
                    while (_trailState->frames < mainState->frames + _maxTrailLength)
                    {
                        NBodyC.StepGalaxy(_trailState);

                        unsafe {
                            BlackHole * src = _trailState->blackHoles;
                            TrailRecord trail;
                            for (int j = 0; j < _trailState->numBlackHoles; j++, src++)
                            {
                                if (!_trails.TryGetValue(src->id, out trail))
                                {
                                    trail = new TrailRecord()
                                    {
                                        startFrame = _trailState->frames
                                    };
                                    _trails[src->id] = trail;
                                }

                                trail.queue.PushBack(src->position);
                            }
                        }

                        simTime++;
                        if (simTime >= _trailUpdateRate)
                        {
                            break;
                        }
                    }
                }
            }

            //Build and display trail mesh
            //but only if it's already reached its max length
            if (_trailState->frames - mainState->frames >= _trailShowLength)
            {
                using (new ProfilerSample("Display Trails")) {
                    _trailVerts.Clear();
                    _trailIndices.Clear();

                    using (new ProfilerSample("Build Vertex List")) {
                        foreach (var pair in _trails)
                        {
                            for (int i = 0; i < pair.Value.queue.Count; i++)
                            {
                                if (i != 0)
                                {
                                    _trailIndices.Add(_trailVerts.Count);
                                    _trailIndices.Add(_trailVerts.Count - 1);
                                }

                                _trailVerts.Add(pair.Value.queue[i]);
                            }
                        }
                    }

                    int[] indexArray;
                    using (new ProfilerSample("Build Index Array")) {
                        indexArray = ArrayPool <int> .Spawn(_trailIndices.Count);

                        for (int i = 0; i < _trailIndices.Count; i++)
                        {
                            indexArray[i] = _trailIndices[i];
                        }

                        for (int i = _trailIndices.Count; i < indexArray.Length; i++)
                        {
                            indexArray[i] = 0;
                        }
                    }

                    using (new ProfilerSample("Upload Mesh")) {
                        _trailMesh.Clear();
                        _trailMesh.SetVertices(_trailVerts);
                        _trailMesh.SetIndices(indexArray, MeshTopology.Lines, 0);

                        ArrayPool <int> .Recycle(indexArray);

                        indexArray = null;
                    }

                    if (_trailResetQueued)
                    {
                        ResetTrails(forceReset: true);
                    }
                }
            }

            _trailPropertyBlock.SetColor("_Color", _trailColor);
            Graphics.DrawMesh(_trailMesh, galaxyRenderer.displayAnchor.localToWorldMatrix, _trailMaterial, 0, null, 0, _trailPropertyBlock);
        }

        //Render the black holes themselves
        unsafe {
            BlackHole *prevSrc  = prevState->blackHoles;
            BlackHole *mainSrc  = mainState->blackHoles;
            float      fraction = Mathf.InverseLerp(prevState->time, mainState->time, simulationTime);
            for (int j = 0; j < mainState->numBlackHoles; j++, prevSrc++, mainSrc++)
            {
                Vector3 position = Vector3.Lerp(prevSrc->position, mainSrc->position, fraction);
                galaxyRenderer.DrawBlackHole(position);
            }
        }
    }