Ejemplo n.º 1
0
 public bool ReadFloatNullable(ref float?value)
 {
     try
     {
         if (m_binaryReader.ReadBoolean())
         {
             value = m_binaryReader.ReadSingle();
             if (!MyCommonDebugUtils.IsValid(value.Value))
             {
                 HandleError("Invalid float");
                 return(false);
             }
         }
         else
         {
             value = null;
         }
         return(true);
     }
     catch (Exception ex)
     {
         HandleError(ex);
         return(false);
     }
 }
        //  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);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        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);
            }
        }
Ejemplo n.º 5
0
        //  Calculate and then remember average material in this cell. It isn't single material, but average.
        public void CalcAverageCellMaterial()
        {
            if (m_singleMaterialForWholeCell == true)
            {
                //  For single material it's easy
                m_averageCellMaterial = m_singleMaterial;
            }
            else
            {
                //  If materials are stored in 3D array, we need to really calculate average material
                //  Iterate materials in this data cell
                for (int xyz = 0; xyz < voxelsInCell; xyz++)
                {
                    MyMwcVoxelMaterialsEnum material = m_materials[xyz];
                    m_cellMaterialCounts[(int)material]++;
                }

                int maxNum = 0;
                for (int i = 0; i < m_cellMaterialCounts.Length; i++)
                {
                    if (m_cellMaterialCounts[i] > maxNum)
                    {
                        maxNum = m_cellMaterialCounts[i];
                        m_averageCellMaterial = (MyMwcVoxelMaterialsEnum)i;
                    }
                    m_cellMaterialCounts[i] = 0; // Erase for next operation
                }
            }

            MyCommonDebugUtils.AssertRelease(m_averageCellMaterial.HasValue);
        }
Ejemplo n.º 6
0
        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;
            }
        }
Ejemplo 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);
 }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
0
 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);
 }
Ejemplo n.º 10
0
        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;
            }
        }
Ejemplo n.º 11
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);
        }
Ejemplo n.º 12
0
        /// <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);
        }
 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();
 }
Ejemplo n.º 14
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);
        }
Ejemplo n.º 15
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];
        }
Ejemplo n.º 16
0
        public static void WriteFloat(float val, BinaryWriter binaryWriter)
        {
            MyMwcUtils.FixDenormalizedFloat(ref val);

            if (!MyCommonDebugUtils.IsValid(val))
            {
                throw new InvalidOperationException("Cannot write invalid float (infinity or NaN) to network message!");
            }
            binaryWriter.Write(val);
        }
Ejemplo n.º 17
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");
 }
Ejemplo n.º 18
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;
 }
        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);
        }
Ejemplo n.º 20
0
        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
        }
Ejemplo n.º 21
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);
        }
Ejemplo n.º 22
0
        public static void LoadData()
        {
            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("MyVoxelMaterials.LoadData");

            m_materials     = new MyVoxelMaterial[MyMwcUtils.GetMaxValueFromEnum <MyMwcVoxelMaterialsEnum>() + 1];
            m_meshMaterials = new MyMeshMaterial[MyMwcUtils.GetMaxValueFromEnum <MyMwcVoxelMaterialsEnum>() + 1];

            Add(MyMwcVoxelMaterialsEnum.Indestructible_01, "Indestructible_01", true, true, 0.6f, 100, false);
            Add(MyMwcVoxelMaterialsEnum.Indestructible_02, "Indestructible_02", true, true, 0.6f, 100, false);
            Add(MyMwcVoxelMaterialsEnum.Indestructible_03, "Indestructible_03", true, true, 0.6f, 100, false);
            Add(MyMwcVoxelMaterialsEnum.Indestructible_04, "Indestructible_04", true, true, 0.6f, 100, false);
            Add(MyMwcVoxelMaterialsEnum.Indestructible_05_Craters_01, "Indestructible_05_Craters_01", true, true, 0.1f, 100, false);
            Add(MyMwcVoxelMaterialsEnum.Ice_01, "Ice_01", false, true, 1, 20.0f, false);
            Add(MyMwcVoxelMaterialsEnum.Treasure_01, "Treasure_01", false, false, 0.9f, 10.0f, false);
            Add(MyMwcVoxelMaterialsEnum.Treasure_02, "Treasure_02", false, false, 0.7f, 20.0f, false);
            Add(MyMwcVoxelMaterialsEnum.Iron_01, "Iron_01", false, false, 0.7f, 2.0f, false);
            Add(MyMwcVoxelMaterialsEnum.Iron_02, "Iron_02", false, false, 0.6f, 2, false);
            Add(MyMwcVoxelMaterialsEnum.Stone_01, "Stone_01", false, true, 0.6f, 100.0f, true);
            Add(MyMwcVoxelMaterialsEnum.Stone_02, "Stone_02", false, true, 0.6f, 100.0f, true);
            Add(MyMwcVoxelMaterialsEnum.Stone_03, "Stone_03", false, true, 0.6f, 100.0f, true);
            Add(MyMwcVoxelMaterialsEnum.Stone_04, "Stone_04", false, true, 0.6f, 100.0f, true);
            Add(MyMwcVoxelMaterialsEnum.Stone_05, "Stone_05", false, false, 0.6f, 100.0f, true);
            Add(MyMwcVoxelMaterialsEnum.Stone_06, "Stone_06", false, false, 0.6f, 100.0f, true);
            Add(MyMwcVoxelMaterialsEnum.Stone_07, "Stone_07", false, false, 0.6f, 100.0f, true);
            Add(MyMwcVoxelMaterialsEnum.Stone_08, "Stone_08", false, false, 0.6f, 100.0f, true);
            Add(MyMwcVoxelMaterialsEnum.Stone_10, "Stone_10", false, true, 0.6f, 100.0f, true);
            Add(MyMwcVoxelMaterialsEnum.Stone_13_Wall_01, "Stone_13_Wall_01", false, true, 0.6f, 50, true);
            Add(MyMwcVoxelMaterialsEnum.Uranite_01, "Uraninite_01", false, false, 1.2f, 50.0f, false);
            Add(MyMwcVoxelMaterialsEnum.Helium3_01, "Helium3_01", false, false, 0.4f, 20.0f, false);
            Add(MyMwcVoxelMaterialsEnum.Helium4_01, "Helium4_01", false, true, 0.9f, 60.0f, false);
            Add(MyMwcVoxelMaterialsEnum.Organic_01, "Organic_01", false, false, 0, 1, false);
            Add(MyMwcVoxelMaterialsEnum.Gold_01, "Gold_01", false, false, 1.5f, 2.0f, false);
            Add(MyMwcVoxelMaterialsEnum.Silver_01, "Silver_01", false, false, 0.8f, 1.0f, false);
            Add(MyMwcVoxelMaterialsEnum.Nickel_01, "Nickel_01", false, false, 0.6f, 2, false);
            Add(MyMwcVoxelMaterialsEnum.Magnesium_01, "Magnesium_01", false, true, 0.6f, 2, false);
            Add(MyMwcVoxelMaterialsEnum.Platinum_01, "Platinum_01", false, false, 0.8f, 2.0f, false);
            Add(MyMwcVoxelMaterialsEnum.Silicon_01, "Silicon_01", false, true, 2.0f, 50.0f, false);
            Add(MyMwcVoxelMaterialsEnum.Cobalt_01, "Cobalt_01", false, false, 0.6f, 10.0f, false);
            Add(MyMwcVoxelMaterialsEnum.Snow_01, "Snow_01", false, false, 0.1f, 0.1f, false);
            Add(MyMwcVoxelMaterialsEnum.Lava_01, "lava_01", false, true, 0, 1, false);
            Add(MyMwcVoxelMaterialsEnum.Concrete_01, "Concrete_01", false, true, 0.6f, 2, false);
            Add(MyMwcVoxelMaterialsEnum.Concrete_02, "Concrete_02", false, true, 0.6f, 2, false);
            Add(MyMwcVoxelMaterialsEnum.Sandstone_01, "Sandstone_01", false, true, 0.6f, 2, false);
            Add(MyMwcVoxelMaterialsEnum.Stone_Red, "Stone_Red", false, true, 0.6f, 2, false);

            foreach (MyMwcVoxelMaterialsEnum material in Enum.GetValues(typeof(MyMwcVoxelMaterialsEnum)))
            {
                MyCommonDebugUtils.AssertRelease(Get(material) != null);
            }

            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();
        }
Ejemplo n.º 23
0
        static void Add(MyMwcVoxelMaterialsEnum materialEnum, string assetName, bool isIndestructible, bool useTwoTextures, float specularShininess, float specularPower, bool hasBuilderVersion)
        {
            //  Check if not yet assigned
            MyCommonDebugUtils.AssertRelease(m_materials[(int)materialEnum] == null);

            //MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("new MyVoxelMaterial");

            //  Create and add into array
            MyVoxelMaterial voxelMaterial = new MyVoxelMaterial(materialEnum, assetName, isIndestructible, useTwoTextures, specularShininess, specularPower, hasBuilderVersion);

            m_materials[(int)materialEnum]     = voxelMaterial;
            m_meshMaterials[(int)materialEnum] = new MyMeshMaterial("Textures\\Voxels\\" + assetName + "_ForAxisXZ", assetName, voxelMaterial.GetTextures().TextureDiffuseForAxisXZ, voxelMaterial.GetTextures().TextureNormalMapForAxisXZ);
        }
Ejemplo n.º 24
0
        //  Parameter 'useTwoTexturesPerMaterial' tells us if we use two textures per material. One texture for axis XZ and second for axis Y.
        //  Use it for rock/stone materials. Don't use it for gold/silver, because there you don't need to make difference between side and bottom materials.
        //  Using this we save texture memory, but pixel shader still used differenced textures (two samplers looking to same texture)
        public MyVoxelMaterial(MyMwcVoxelMaterialsEnum materialEnum, string assetName, bool isIndestructible, bool useTwoTextures, float specularIntensity, float specularPower, bool hasBuilderVersion)
        {
            //  SpecularPower must be > 0, because pow() makes NaN results if called with zero
            MyCommonDebugUtils.AssertRelease(specularPower > 0);

            m_assetName         = assetName;
            IsIndestructible    = isIndestructible;
            SpecularIntensity   = specularIntensity;
            SpecularPower       = specularPower;
            UseTwoTextures      = useTwoTextures;
            m_materialEnum      = materialEnum;
            m_hasBuilderVersion = hasBuilderVersion && MyFakes.MWBUILDER;
        }
Ejemplo n.º 25
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();
        }
Ejemplo n.º 26
0
        public MyObjectsPoolSimple(int capacity)
        {
            //  Pool should contain at least one preallocated item!
            MyCommonDebugUtils.AssertRelease(capacity > 0);

            ClearAllAllocated();

            //  Preallocate items
            m_items = new T[capacity];
            for (int i = 0; i < m_items.Length; i++)
            {
                m_items[i] = new T();
            }
        }
Ejemplo n.º 27
0
        public static void LoadContent()
        {
            MyMwcLog.WriteLine("MyDecals.LoadContent() - START");
            MyMwcLog.IncreaseIndent();
            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("MyDecals::LoadContent");

            //  Reason is that if count of neighbour triangles is more then decal triangles buffer, we won't be able to add any triangleVertexes to the buffer.
            MyCommonDebugUtils.AssertRelease(MyDecalsConstants.MAX_DECAL_TRIANGLES_IN_BUFFER > MyDecalsConstants.TEXTURE_LARGE_MAX_NEIGHBOUR_TRIANGLES);

            MyCommonDebugUtils.AssertRelease(MyDecalsConstants.MAX_DECAL_TRIANGLES_IN_BUFFER_LARGE <= MyDecalsConstants.MAX_DECAL_TRIANGLES_IN_BUFFER);
            MyCommonDebugUtils.AssertRelease(MyDecalsConstants.MAX_DECAL_TRIANGLES_IN_BUFFER_SMALL <= MyDecalsConstants.MAX_DECAL_TRIANGLES_IN_BUFFER);

            //  Reason is that if count of neighbour triangles is more then decal triangles buffer, we won't be able to add any triangleVertexes to the buffer.
            MyCommonDebugUtils.AssertRelease(MyDecalsConstants.MAX_DECAL_TRIANGLES_IN_BUFFER > MyDecalsConstants.TEXTURE_SMALL_MAX_NEIGHBOUR_TRIANGLES);

            //  Reason is that if count of neighbour triangles is more then this fade limit, we won't be able to add decals that lay on more triangles, because buffer will be never released to us.
            MyCommonDebugUtils.AssertRelease(MyDecalsConstants.TEXTURE_LARGE_MAX_NEIGHBOUR_TRIANGLES < (MyDecalsConstants.MAX_DECAL_TRIANGLES_IN_BUFFER * MyDecalsConstants.TEXTURE_LARGE_FADING_OUT_MINIMAL_TRIANGLE_COUNT_PERCENT));

            //  Reason is that if count of neighbour triangles is more then this fade limit, we won't be able to add decals that lay on more triangles, because buffer will be never released to us.
            MyCommonDebugUtils.AssertRelease(MyDecalsConstants.TEXTURE_SMALL_MAX_NEIGHBOUR_TRIANGLES < (MyDecalsConstants.MAX_DECAL_TRIANGLES_IN_BUFFER * MyDecalsConstants.TEXTURE_SMALL_FADING_OUT_MINIMAL_TRIANGLE_COUNT_PERCENT));

            //  Large must be bigger than small
            MyCommonDebugUtils.AssertRelease(MyDecalsConstants.TEXTURE_LARGE_MAX_NEIGHBOUR_TRIANGLES > MyDecalsConstants.TEXTURE_SMALL_MAX_NEIGHBOUR_TRIANGLES);

            m_vertices           = new MyVertexFormatDecal[MyDecalsConstants.MAX_DECAL_TRIANGLES_IN_BUFFER * MyDecalsConstants.VERTEXES_PER_DECAL];
            m_neighbourTriangles = new List <MyTriangle_Vertex_Normals>(MyDecalsConstants.TEXTURE_LARGE_MAX_NEIGHBOUR_TRIANGLES);

            m_decalsForModels = new MyDecalsForPhysObjects(MyDecalsConstants.DECAL_BUFFERS_COUNT);
            m_decalsForVoxels = new MyDecalsForVoxels(MyDecalsConstants.DECAL_BUFFERS_COUNT);

            //  Decal textures
            int texturesCount = MyEnumsToStrings.Decals.Length;

            m_texturesDiffuse   = new MyTexture2D[texturesCount];
            m_texturesNormalMap = new MyTexture2D[texturesCount];

            for (int i = 0; i < texturesCount; i++)
            {
                MyMwcLog.WriteLine("textureManager " + i.ToString() + "Textures\\Decals\\" + MyEnumsToStrings.Decals[i] + "_Diffuse", SysUtils.LoggingOptions.MISC_RENDER_ASSETS);
                m_texturesDiffuse[i] = MyTextureManager.GetTexture <MyTexture2D>("Textures\\Decals\\" + MyEnumsToStrings.Decals[i] + "_Diffuse", null, LoadingMode.Immediate);
                MyMwcLog.WriteLine("textureManager " + i.ToString() + "Textures\\Decals\\" + MyEnumsToStrings.Decals[i] + "_NormalMap", SysUtils.LoggingOptions.MISC_RENDER_ASSETS);
                m_texturesNormalMap[i] = MyTextureManager.GetTexture <MyTexture2D>("Textures\\Decals\\" + MyEnumsToStrings.Decals[i] + "_NormalMap", CheckTexture, LoadingMode.Immediate);

                MyUtils.AssertTexture(m_texturesNormalMap[i]);
            }

            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();
            MyMwcLog.DecreaseIndent();
            MyMwcLog.WriteLine("MyDecals.LoadContent() - END");
        }
Ejemplo n.º 28
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++;
        }
Ejemplo n.º 30
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);
        }