Exemplo n.º 1
0
        private void MoveSphere(Vector2 mouseScreenPos)
        {
            // Borrowed from Stride documentation
            var     invViewProj = Matrix.Invert(playerInputCamera.ViewProjectionMatrix);
            Vector3 sPos;

            sPos.X = mouseScreenPos.X * 2f - 1f;
            sPos.Y = 1f - mouseScreenPos.Y * 2f;
            sPos.Z = 0f;

            var vectorNear = Vector3.Transform(sPos, invViewProj);

            vectorNear /= vectorNear.W;
            sPos.Z      = 1f;
            var vectorFar = Vector3.Transform(sPos, invViewProj);

            vectorFar /= vectorFar.W;

            resultList.Clear();
            this.GetSimulation().RaycastPenetrating(vectorNear.XYZ(), vectorFar.XYZ(),
                                                    resultList, CollisionFilterGroups.DefaultFilter, CollisionFilterGroupFlags.CustomFilter10);

            if (!resultList.Any())
            {
                Log.Debug($"Destination point could not be found, are you clicking ground?");
                return;
            }

            var targetPosition = resultList.First().Point;

            sphere.Transform.Position = new Vector3(targetPosition.X, .5f, targetPosition.Z);
            Log.Debug($"Sphere position has been updated.");
        }
Exemplo n.º 2
0
        /// <summary>
        /// write transaction's raw page data into journal
        /// </summary>
        public void Write(LowLevelTransaction tx, CompressedPagesResult pages, LazyTransactionBuffer lazyTransactionScratch)
        {
            var ptt       = new Dictionary <long, PagePosition>(NumericEqualityComparer.BoxedInstanceInt64);
            var cur4KbPos = _writePosIn4Kb;

            Debug.Assert(pages.NumberOf4Kbs > 0);

            UpdatePageTranslationTable(tx, _unusedPagesHashSetPool, ptt);

            using (_locker2.Lock())
            {
                Debug.Assert(!_unusedPages.Any(_unusedPagesHashSetPool.Contains)); // We ensure there cannot be duplicates here (disjoint sets).

                foreach (var item in _unusedPagesHashSetPool)
                {
                    _unusedPages.Add(item);
                }
            }
            _unusedPagesHashSetPool.Clear();

            if (tx.IsLazyTransaction == false && (lazyTransactionScratch == null || lazyTransactionScratch.HasDataInBuffer() == false))
            {
                try
                {
                    _journalWriter.Write(cur4KbPos, pages.Base, pages.NumberOf4Kbs);
                }
                catch (Exception e)
                {
                    _env.Options.SetCatastrophicFailure(ExceptionDispatchInfo.Capture(e));
                    throw;
                }
            }
            else
            {
                if (lazyTransactionScratch == null)
                {
                    throw new InvalidOperationException("lazyTransactionScratch cannot be null if the transaction is lazy (or a previous one was)");
                }
                lazyTransactionScratch.EnsureSize(_journalWriter.NumberOfAllocated4Kb);
                lazyTransactionScratch.AddToBuffer(cur4KbPos, pages);

                // non lazy tx will add itself to the buffer and then flush scratch to journal
                if (tx.IsLazyTransaction == false ||
                    lazyTransactionScratch.NumberOfPages > tx.Environment.ScratchBufferPool.GetAvailablePagesCount() / 2)
                {
                    try
                    {
                        lazyTransactionScratch.WriteBufferToFile(this, tx);
                    }
                    catch (Exception e)
                    {
                        _env.Options.SetCatastrophicFailure(ExceptionDispatchInfo.Capture(e));
                        throw;
                    }
                }
                else
                {
                    lazyTransactionScratch.EnsureHasExistingReadTransaction(tx);
                }
            }

            using (_locker2.Lock())
            {
                _pageTranslationTable.SetItems(tx, ptt);
                // it is important that the last write position will be set
                // _after_ the PTT update, because a flush that is concurrent
                // with the write will first get the WritePosIn4KB and then
                // do the flush based on the PTT. Worst case, we'll flush
                // more then we need, but won't get into a position where we
                // think we flushed, and then realize that we didn't.
                Interlocked.Add(ref _writePosIn4Kb, pages.NumberOf4Kbs);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// write transaction's raw page data into journal
        /// </summary>
        public void Write(LowLevelTransaction tx, CompressedPagesResult pages, LazyTransactionBuffer lazyTransactionScratch)
        {
            var ptt       = new Dictionary <long, PagePosition>(NumericEqualityComparer.Instance);
            var cur4KbPos = _writePosIn4Kb;

            Debug.Assert(pages.NumberOf4Kbs > 0);

            UpdatePageTranslationTable(tx, _unusedPagesHashSetPool, ptt);

            using (_locker2.Lock())
            {
                _writePosIn4Kb += pages.NumberOf4Kbs;

                Debug.Assert(!_unusedPages.Any(_unusedPagesHashSetPool.Contains)); // We ensure there cannot be duplicates here (disjoint sets).

                foreach (var item in _unusedPagesHashSetPool)
                {
                    _unusedPages.Add(item);
                }
            }
            _unusedPagesHashSetPool.Clear();

            if (tx.IsLazyTransaction == false && (lazyTransactionScratch == null || lazyTransactionScratch.HasDataInBuffer() == false))
            {
                try
                {
                    _journalWriter.Write(cur4KbPos, pages.Base, pages.NumberOf4Kbs);
                }
                catch (Exception e)
                {
                    _env.Options.SetCatastrophicFailure(ExceptionDispatchInfo.Capture(e));
                    throw;
                }
            }
            else
            {
                if (lazyTransactionScratch == null)
                {
                    throw new InvalidOperationException("lazyTransactionScratch cannot be null if the transaction is lazy (or a previous one was)");
                }
                lazyTransactionScratch.EnsureSize(_journalWriter.NumberOfAllocated4Kb);
                lazyTransactionScratch.AddToBuffer(cur4KbPos, pages);

                // non lazy tx will add itself to the buffer and then flush scratch to journal
                if (tx.IsLazyTransaction == false ||
                    lazyTransactionScratch.NumberOfPages > tx.Environment.ScratchBufferPool.GetAvailablePagesCount() / 2)
                {
                    try
                    {
                        lazyTransactionScratch.WriteBufferToFile(this, tx);
                    }
                    catch (Exception e)
                    {
                        _env.Options.SetCatastrophicFailure(ExceptionDispatchInfo.Capture(e));
                        throw;
                    }
                }
                else
                {
                    lazyTransactionScratch.EnsureHasExistingReadTransaction(tx);
                }
            }

            using (_locker2.Lock())
            {
                _pageTranslationTable.SetItems(tx, ptt);
            }
        }