void UpdateNormalizedValue()
 {
     MyCommonDebugUtils.AssertDebug(m_minValue < m_maxValue);
     MyCommonDebugUtils.AssertDebug(m_value >= m_minValue);
     MyCommonDebugUtils.AssertDebug(m_value <= m_maxValue);
     m_valueNormalized = MathHelper.Clamp((m_value.Value - m_minValue) / (m_maxValue - m_minValue), 0, 1);
 }
        public void PrepareCache(MyVoxelVertex[] vertices, int vertexCount, MyVoxelTriangle[] triangles, int triangleCount)
        {
            lock (m_syncRoot)
            {
                if (vertexCount == 0)
                {
                    VoxelVerticesCount  = 0;
                    VoxelTrianglesCount = 0;
                    m_octree            = null;
                    VoxelVertices       = null;
                    return;
                }
                MyCommonDebugUtils.AssertDebug(vertexCount <= Int16.MaxValue);

                MyRender.GetRenderProfiler().StartProfilingBlock("build octree");
                if (m_octree == null)
                {
                    m_octree = new MyOctree();
                }
                m_octree.Init(ref vertices, ref vertexCount, ref triangles, ref triangleCount, out VoxelTriangles);
                MyRender.GetRenderProfiler().EndProfilingBlock();

                // copy voxel vertices
                VoxelVertices = new MyVoxelVertex[vertexCount];
                for (int i = 0; i < vertexCount; i++)
                {
                    VoxelVertices[i] = vertices[i];
                }

                // set size only after the arrays are fully allocated
                VoxelVerticesCount  = vertexCount;
                VoxelTrianglesCount = triangleCount;
            }
        }
        /// <summary>
        /// Consistancy check
        /// </summary>
        public bool CheckIslands()
        {
            for (int j = 0; j < m_islands.Count; j++)
            {
                for (int i = 0; i < m_islands[j].GetRigids().Count; i++)
                {
                    MyRigidBody rbo = m_islands[j].GetRigids()[i];

                    // check the if rigid is in only 1 island
                    for (int k = 0; k < m_islands.Count; k++)
                    {
                        if (k != j)
                        {
                            for (int l = 0; l < m_islands[k].GetRigids().Count; l++)
                            {
                                MyRigidBody testRbo = m_islands[k].GetRigids()[l];
                                if (testRbo == rbo)
                                {
                                    MyCommonDebugUtils.AssertDebug(false);
                                    return(false);
                                }
                            }
                        }
                    }
                }
            }
            return(true);
        }
        //  Add cell into cache and returns reference to it. Cache item with lowest priority is choosen.
        //  Call this method when you want allocate new item in the cache.
        static MyVoxelCacheCellRender AddCell(int voxelMapId, ref MyMwcVector3Int cellCoord, MyLodTypeEnum cellHashType)
        {
            Int64 key = MyVoxelMaps.GetCellHashCode(voxelMapId, ref cellCoord, cellHashType);

            //  Cache item with lowest priority is choosen.
            LinkedListNode <MyVoxelCacheCellRender> first = m_priority.First;

            lock (m_priorityLocker)
            {
                m_priority.RemoveFirst();
                m_priority.AddLast(first);
            }

            //  If this object already contained some vertex buffers (and of course some render cell), we need to dispose its vertex buffers and
            //  remove from hash table, so that render cell will no longer be in the render cell cache
            if (first.Value.Contains == true)
            {
                System.Diagnostics.Debug.Assert(false, "Cache is full - increase it atm");

                Int64 keyForRemoving = MyVoxelMaps.GetCellHashCode(first.Value.VoxelMap.VoxelMapId, ref first.Value.CellCoord, first.Value.CellHashType);
                m_cellsByCoordinate.Remove(keyForRemoving);
                first.Value.Reset();
            }

            //  Remember where is render cell cache for this render cell
            m_cellsByCoordinate.Add(key, first);

            //  You have reached the capacity of RENDER cells cache. Consider increasing it.
            MyCommonDebugUtils.AssertDebug(m_cellsByCoordinate.Count <= m_capacity);

            return(first.Value);
        }
        public int CountLeaves(int nodeId)
        {
            MyPerformanceCounter.PerCameraDraw.StartTimer("DAABB");
            using (m_rwLock.AcquireSharedUsing())
            {
                if (nodeId == NullNode)
                {
                    MyPerformanceCounter.PerCameraDraw.StopTimer("DAABB");
                    return(0);
                }

                MyCommonDebugUtils.AssertDebug(0 <= nodeId && nodeId < _nodeCapacity);
                DynamicTreeNode node = _nodes[nodeId];

                if (node.IsLeaf())
                {
                    MyCommonDebugUtils.AssertDebug(node.Height == 1);
                    return(1);
                }

                int count1 = CountLeaves(node.Child1);
                int count2 = CountLeaves(node.Child2);
                int count  = count1 + count2;
                MyCommonDebugUtils.AssertDebug(count == node.Height);
                MyPerformanceCounter.PerCameraDraw.StopTimer("DAABB");
                return(count);
            }
        }
Esempio n. 6
0
        // Obtain sector type based on the session type parameter
        public static MyMwcSectorTypeEnum GetSectorTypeFromSessionType(MyMwcStartSessionRequestTypeEnum sessionType)
        {
            MyMwcSectorTypeEnum?sectorType = null;

            if ((sessionType == MyMwcStartSessionRequestTypeEnum.EDITOR_SANDBOX) ||
                (sessionType == MyMwcStartSessionRequestTypeEnum.SANDBOX_FRIENDS) ||
                (sessionType == MyMwcStartSessionRequestTypeEnum.SANDBOX_OWN) ||
                (sessionType == MyMwcStartSessionRequestTypeEnum.SANDBOX_RANDOM))
            {
                sectorType = MyMwcSectorTypeEnum.SANDBOX;
            }
            else if (
                (sessionType == MyMwcStartSessionRequestTypeEnum.EDITOR_STORY) ||
                (sessionType == MyMwcStartSessionRequestTypeEnum.NEW_STORY) ||
                (sessionType == MyMwcStartSessionRequestTypeEnum.LOAD_CHECKPOINT))
            {
                sectorType = MyMwcSectorTypeEnum.STORY;
            }
            else if (
                (sessionType == MyMwcStartSessionRequestTypeEnum.EDITOR_MMO) ||
                (sessionType == MyMwcStartSessionRequestTypeEnum.MMO))
            {
                sectorType = MyMwcSectorTypeEnum.MMO;
            }

            MyCommonDebugUtils.AssertDebug(sectorType.HasValue);

            return(sectorType.Value);
        }
Esempio n. 7
0
 /// <summary>
 /// Finds a path using waypoints. Use whenever the direct path is blocked.
 /// </summary>
 /// <param name="from">First endpoint of the path. Will be duplicated in the returned path.</param>
 /// <param name="to">First endpoint of the path. Will be duplicated in the returned path.</param>
 /// <param name="pathFoundHandler">To be called after the pathfinder is finished. Will receive the found path, or null when there's none.</param>
 /// <param name="userData">An object that will be passed to pathFoundHandler. Can be used to identify the query.</param>
 /// <param name="useRaycasts">Whether the bot should use raycasts.</param>
 public static void FindPathInBackground(Vector3 from, Vector3 to, PathFoundHandler pathFoundHandler, object userData, bool useRaycasts)
 {
     MyCommonDebugUtils.AssertDebug(from != null && to != null && pathFoundHandler != null);
     m_queue.Enqueue(new PathToBeFound(from, to, pathFoundHandler, userData, useRaycasts));
     //m_event.Set();
     m_findPathTask = Parallel.Start(m_pathfindingHelper);
 }
        public MySensorElement CreateSensorElement(MySensorElementDesc desc)
        {
            switch (desc.GetElementType())
            {
            case MySensorElementType.ET_SPHERE:
            {
                MySphereSensorElement element = m_SphereSensorElementPool.Allocate();

                MyCommonDebugUtils.AssertDebug(element != null);

                if (element.LoadFromDesc(desc))
                {
                    return(element);
                }
                else
                {
                    m_SphereSensorElementPool.Deallocate(element);
                    return(null);
                }
            }
            break;

            default:
                return(null);

                break;
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Loads descriptor of the sensor and initialize the sensor
        /// </summary>
        public bool LoadFromDesc(MySensorDesc desc)
        {
            if (m_Inserted)
            {
                return(false);
            }

            if (!desc.IsValid())
            {
                return(false);
            }

            m_Matrix  = desc.m_Matrix;
            m_Element = desc.m_Element;

            m_Element.Sensor = this;

            m_SensorEventHandler = desc.m_SensorEventHandler;
            MyCommonDebugUtils.AssertDebug(m_Interactions.Count == 0);
            m_Interactions.Clear();

            m_Guid = GUID_COUNTER;
            if (GUID_COUNTER > ushort.MaxValue)
            {
                GUID_COUNTER = 0;
            }

            GUID_COUNTER++;

            return(true);
        }
Esempio n. 10
0
        public override void CreateVolume(MyElement element)
        {
            MyCommonDebugUtils.AssertDebug(element.ProxyData == MyElement.PROXY_UNASSIGNED);
            BoundingBox aabb = element.GetWorldSpaceAABB();

            element.ProxyData = m_DAABBTree.AddProxy(ref aabb, element, (uint)element.Flags);
        }
 private static void LoadCellInBackground(
     MyVoxelMap voxelMap, ref MyMwcVector3Int renderCellCoord, MyLodTypeEnum cellHashType)
 {
     System.Diagnostics.Debug.Assert(false, "Not implemented");
     MyCommonDebugUtils.AssertDebug(voxelMap != null);
     //m_queue.Enqueue(new RenderCellLoadJob(voxelMap, ref renderCellCoord, cellHashType));
     //m_event.Set();
 }
Esempio n. 12
0
        //  Find max numeric value in enum
        public static int GetMaxValueFromEnum <T>()
        {
            Array values = Enum.GetValues(typeof(T));

            //  Doesn't make sence to find max in empty enum
            MyCommonDebugUtils.AssertDebug(values.Length >= 1);

            int  max            = int.MinValue;
            Type underlyingType = Enum.GetUnderlyingType(typeof(T));

            if (underlyingType == typeof(System.Byte))
            {
                foreach (byte value in values)
                {
                    if (value > max)
                    {
                        max = value;
                    }
                }
            }
            else if (underlyingType == typeof(System.Int16))
            {
                foreach (short value in values)
                {
                    if (value > max)
                    {
                        max = value;
                    }
                }
            }
            else if (underlyingType == typeof(System.UInt16))
            {
                foreach (ushort value in values)
                {
                    if (value > max)
                    {
                        max = value;
                    }
                }
            }
            else if (underlyingType == typeof(System.Int32))
            {
                foreach (int value in values)
                {
                    if (value > max)
                    {
                        max = value;
                    }
                }
            }
            else
            {
                //  Unhandled underlying type - probably "long"
                throw new MyMwcExceptionApplicationShouldNotGetHere();
            }

            return(max);
        }
Esempio n. 13
0
        public MyRingBuffer(uint size)
        {
            MyCommonDebugUtils.AssertDebug((size & (size - 1)) == 0);

            m_Capacity = size;
            m_Get      = 0;
            m_Put      = 0;

            m_Buffer = new T[size];
        }
        internal override void Write(BinaryWriter binaryWriter)
        {
            base.Write(binaryWriter);

            MyCommonDebugUtils.AssertDebug(Inventory != null);

            // Drone type
            MyMwcLog.IfNetVerbose_AddToLog("DroneType: " + DroneType);
            MyMwcMessageOut.WriteByte((byte)DroneType, binaryWriter);
        }
Esempio n. 15
0
 /// <summary>
 /// Get the fat BoundingBox for a proxy.
 /// </summary>
 /// <param name="proxyId">The proxy id.</param>
 /// <param name="fatAABB">The fat BoundingBox.</param>
 public void GetFatAABB(int proxyId, out BoundingBox fatAABB)
 {
     MyPerformanceCounter.PerCameraDraw.StartTimer("DAABB");
     using (m_rwLock.AcquireSharedUsing())
     {
         MyCommonDebugUtils.AssertDebug(0 <= proxyId && proxyId < _nodeCapacity);
         fatAABB = _nodes[proxyId].Aabb;
     }
     MyPerformanceCounter.PerCameraDraw.StopTimer("DAABB");
 }
Esempio n. 16
0
 private void FreeNode(int nodeId)
 {
     MyCommonDebugUtils.AssertDebug(0 <= nodeId && nodeId < _nodeCapacity);
     MyCommonDebugUtils.AssertDebug(0 < _nodeCount);
     _nodes[nodeId].ParentOrNext = _freeList;
     _nodes[nodeId].Height       = -1;
     _nodes[nodeId].UserData     = null;
     _freeList = nodeId;
     --_nodeCount;
 }
        public void Start()
        {
#if PROFILING
            //  You called Start twice, without calling End. Proper way is to call Start and than End.
            MyCommonDebugUtils.AssertDebug(m_isTimerRunning == false);

            m_isTimerRunning = true;
            m_startCount     = QueryPerformanceCounter();
            m_averageCounter++;
#endif //PROFILING
        }
Esempio n. 18
0
        protected override void OnContactStart(MyContactEventInfo contactInfo)
        {
            MyPhysicsBody ps1 = (MyPhysicsBody)contactInfo.m_RigidBody1.m_UserData;
            MyPhysicsBody ps2 = (MyPhysicsBody)contactInfo.m_RigidBody2.m_UserData;

            if (ps1.Entity is MyExplosionDebrisBase && ps2.Entity is MyExplosionDebrisBase)
            {
                MyCommonDebugUtils.AssertDebug(false);
            }

            base.OnContactStart(contactInfo);
        }
Esempio n. 19
0
        public static void UnloadData()
        {
            // all lights should be deallocated at this point
            MyCommonDebugUtils.AssertDebug(m_preallocatedLights.GetActiveCount() == 0, "MyLights.UnloadData: preallocated lights not emptied!");
            m_preallocatedLights.DeallocateAll();
            if (m_sortedLights != null)
            {
                m_sortedLights.Clear();
                m_sortedLights = null;
            }

            m_tree.Clear();
        }
Esempio n. 20
0
        public float Duration()
        {
            switch (m_type)
            {
            case MyMedicineType.MEDIKIT: return(MyMedicineConstants.MEDIKIT_DURATION);

            case MyMedicineType.ANTIRADIATION_MEDICINE: return(MyMedicineConstants.ANTIRADIATION_MEDICINE_DURATION);

            case MyMedicineType.HEALTH_ENHANCING_MEDICINE: return(MyMedicineConstants.HEALTH_ENHANCING_MEDICINE_DURATION);

            case MyMedicineType.PERFORMANCE_ENHANCING_MEDICINE: return(MyMedicineConstants.PERFORMANCE_ENHANCING_MEDICINE_DURATION);

            default: MyCommonDebugUtils.AssertDebug(false, "Unknown medicine type."); return(0);
            }
        }
        //  Add 3d line into cache, so then we can draw many lines at once - by calling DrawLinesFromCache()
        public static void AddLine(Vector3 pointFrom, Vector3 pointTo, Color colorFrom, Color colorTo)
        {
            MyCommonDebugUtils.AssertDebug(IsFull(0) == false);

            if (m_linesCount + 2 >= MyDebugDrawCachedLinesConstants.MAX_LINES_IN_CACHE)
            {
                return;
            }

            m_verticesLine[m_linesCount * 2 + 0].Position = pointFrom;
            m_verticesLine[m_linesCount * 2 + 0].Color    = colorFrom.ToVector4();
            m_verticesLine[m_linesCount * 2 + 1].Position = pointTo;
            m_verticesLine[m_linesCount * 2 + 1].Color    = colorTo.ToVector4();
            m_linesCount++;
        }
Esempio n. 22
0
        /// <summary>
        /// Simulation handlers can be registered here in order to receive simulation notifications
        /// </summary>
        public void RegisterSimulationHandler(MyPhysSimulationHandler simHandler)
        {
#if PHYSICS_CHECK
            for (int i = 0; i < m_SimulationHandlers.Count; i++)
            {
                MyPhysSimulationHandler simH = m_SimulationHandlers[i];
                if (simH == simHandler)
                {
                    // cannot add already existing item!
                    MyCommonDebugUtils.AssertDebug(false);
                }
            }
#endif
            m_SimulationHandlers.Add(simHandler);
        }
        public void End()
        {
#if PROFILING
            //  You called End without first calling Start. Proper way is to call Start and than End.
            MyCommonDebugUtils.AssertDebug(m_isTimerRunning == true);
            m_isTimerRunning = false;

            long stopCount = QueryPerformanceCounter();

            long elapsedCount = stopCount - m_startCount;
            m_currentTimeSpent = (double)elapsedCount / QueryPerformanceFrequency();

            m_totalTimeSpent   += m_currentTimeSpent;
            m_averageTimeSpent += m_currentTimeSpent;
#endif //PROFILING
        }
Esempio n. 24
0
        public MyDialogueSentence(MyActorEnum speaker, MySoundCuesEnum?cue, MyDialoguesWrapperEnum text, float noise = 0.0f, float pauseBefore_ms = 0.0f, MyActorEnum?listener = null)
        {
            Actor          = speaker;
            Listener       = listener;
            Cue            = cue;
            Text           = text;
            PauseBefore_ms = pauseBefore_ms;

            SentenceTime_ms = MathHelper.Clamp(MyDialoguesWrapper.Get(Text).Length * 66, MIN_SENTENCE_TIME, MAX_SENTENCE_TIME) + PauseBefore_ms;
            MyCommonDebugUtils.AssertDebug(noise >= 0 && noise <= 1, "Bad dialogue sentence noise value!");
            Noise = noise;

            if (MyActorConstants.IsNoiseActor(speaker))
            {
                Noise = 1f;
            }
        }
Esempio n. 25
0
        public MyRigidBody CreateRigidBody(MyRigidBodyDesc desc)
        {
            if (!desc.IsValid())
            {
                // invalid desc
                MyCommonDebugUtils.AssertDebug(false);
                return(null);
            }

            MyRigidBody rbo = m_RigidsPool.Allocate();

            MyCommonDebugUtils.AssertDebug(rbo != null);

            rbo.LoadFromDesc(desc);

            return(rbo);
        }
Esempio n. 26
0
        public MySensor CreateSensor(MySensorDesc desc)
        {
            if (!desc.IsValid())
            {
                // invalid desc
                MyCommonDebugUtils.AssertDebug(false);
                return(null);
            }

            MySensor sensor = m_SensorsPool.Allocate();

            MyCommonDebugUtils.AssertDebug(sensor != null);

            sensor.LoadFromDesc(desc);

            return(sensor);
        }
Esempio n. 27
0
        public void Close()
        {
            MyCommonDebugUtils.AssertDebug(m_isMarkedForClose);
            MyCommonDebugUtils.AssertDebug(m_Interactions.Count == 0);

            if (m_Element != null)
            {
                m_Element.Close();
                m_Element = null;
            }

            m_SensorEventHandler = null;

            m_Interactions.Clear();
            m_Interactions = null;

            m_UserData = null;
        }
Esempio n. 28
0
        /// <summary>
        /// Destroy a proxy. This asserts if the id is invalid.
        /// </summary>
        /// <param name="proxyId">The proxy id.</param>
        public void RemoveProxy(int proxyId)
        {
            MyPerformanceCounter.PerCameraDraw.StartTimer("DAABB");
            MyPerformanceCounter.PerCameraDraw.Increment("DAABB Remove");

            using (m_rwLock.AcquireExclusiveUsing())
            {
                MyCommonDebugUtils.AssertDebug(0 <= proxyId && proxyId < _nodeCapacity);
                MyCommonDebugUtils.AssertDebug(_nodes[proxyId].IsLeaf());

                _leafElementCache.Remove(proxyId);

                RemoveLeaf(proxyId);
                FreeNode(proxyId);
            }

            MyPerformanceCounter.PerCameraDraw.StopTimer("DAABB");
        }
        /// <summary>
        /// Adds interaction between 2 given elements
        /// </summary>
        public MyRBElementInteraction AddRBElementInteraction(MyRBElement el1, MyRBElement el2)
        {
            // get it
            int t1 = (int)el1.GetElementType();
            int t2 = (int)el2.GetElementType();
            List <MyRBElementInteraction> intrList = null;

            if (t1 < t2)
            {
                intrList = m_IslandsPool[t1, t2];
            }
            else
            {
                intrList = m_IslandsPool[t2, t1];
            }

            //pada to jinak
            if (intrList.Count == 0)
            {
                return(null);
            }

            MyCommonDebugUtils.AssertDebug(intrList.Count != 0);

            if (intrList.Count == 1)
            {
                MyRBElementInteraction ins = intrList[0].CreateNewInstance();
                intrList.Add(ins);
            }

            MyRBElementInteraction intr = intrList[intrList.Count - 1];

            intrList.RemoveAt(intrList.Count - 1);

            intr.RBElement1 = el1;
            intr.RBElement2 = el2;

            el1.GetRBElementInteractions().Add(intr);
            el2.GetRBElementInteractions().Add(intr);

            return(intr);
        }
Esempio n. 30
0
        //  Fading in/out at the beginning and at the end of trailer
        public static float GetBackgroundFadeAlpha()
        {
            MyCommonDebugUtils.AssertDebug(m_isEnabled == true);

            int fromFade = m_fromTick + m_fadeInOutInTicks;
            int toFade   = m_toTick - m_fadeInOutInTicks;

            if (m_activeTick <= fromFade)
            {
                return((float)(fromFade - m_activeTick) / (float)m_fadeInOutInTicks);
            }
            else if (m_activeTick >= toFade)
            {
                return((float)(m_activeTick - toFade) / (float)m_fadeInOutInTicks);
            }
            else
            {
                return(0);
            }
        }