Ejemplo n.º 1
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.º 2
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.º 3
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.º 4
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.º 5
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.º 6
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.º 7
0
        public MyCockpitGlassDecalsBuffer(int capacity, int maxNeighbourTriangles, int fadeInPhaseInMiliseconds, int fadeOutStartInMiliseconds, int fadeOutLengthInMiliseconds)
        {
            //  Fade in (initial phase) can't interfere with fadeout phase
            MyCommonDebugUtils.AssertRelease(fadeInPhaseInMiliseconds < fadeOutStartInMiliseconds);

            //  Buffer can't store more decal triangles than vertex buffer used for drawing them!
            MyCommonDebugUtils.AssertRelease(capacity <= MyCockpitGlassDecalsConstants.MAX_DECAL_TRIANGLES_IN_BUFFER);

            MyCommonDebugUtils.AssertRelease(maxNeighbourTriangles <= MyCockpitGlassDecalsConstants.MAX_NEIGHBOUR_TRIANGLES);

            //  If there will be more neighbour triangles, we won't be able to add them into buffer in one call!
            MyCommonDebugUtils.AssertRelease(maxNeighbourTriangles < capacity);

            m_triangles                  = new MyObjectsPool <MyCockpitGlassDecalTriangle>(capacity);
            MaxNeighbourTriangles        = maxNeighbourTriangles;
            m_fadeInPhaseInMiliseconds   = fadeInPhaseInMiliseconds;
            m_fadeOutStartInMiliseconds  = fadeOutStartInMiliseconds;
            m_fadeOutLengthInMiliseconds = fadeOutLengthInMiliseconds;
        }
Ejemplo n.º 8
0
        public MyObjectsPool(int capacity)
        {
            //  Pool should contain at least one preallocated item!
            MyCommonDebugUtils.AssertRelease(capacity > 0);

            m_capacity          = capacity;
            m_notAllocatedItems = new Stack <LinkedListNode <T> >(m_capacity);
            m_itemsToDelete     = new Stack <LinkedListNode <T> >(m_capacity);
            m_activeItems       = new LinkedList <T>();
            m_itemToListNode    = new Dictionary <T, LinkedListNode <T> >(m_capacity);

            m_enumerator = new MyObjectsPoolEnumerator <T>(m_activeItems);

            //  Preallocate items
            m_itemsArray = new LinkedListNode <T> [m_capacity];
            for (int i = 0; i < m_capacity; i++)
            {
                m_itemsArray[i] = new LinkedListNode <T>(new T());
                m_notAllocatedItems.Push(m_itemsArray[i]);
            }
        }
Ejemplo n.º 9
0
        static void Validate <T>(Type type, T list) where T : IList <string>
        {
            Array values         = Enum.GetValues(type);
            Type  underlyingType = Enum.GetUnderlyingType(type);

            if (underlyingType == typeof(System.Byte))
            {
                foreach (byte value in values)
                {
                    MyCommonDebugUtils.AssertRelease(list[value] != null);
                }
            }
            else if (underlyingType == typeof(System.Int16))
            {
                foreach (short value in values)
                {
                    MyCommonDebugUtils.AssertRelease(list[value] != null);
                }
            }
            else if (underlyingType == typeof(System.UInt16))
            {
                foreach (ushort value in values)
                {
                    MyCommonDebugUtils.AssertRelease(list[value] != null);
                }
            }
            else if (underlyingType == typeof(System.Int32))
            {
                foreach (int value in values)
                {
                    MyCommonDebugUtils.AssertRelease(list[value] != null);
                }
            }
            else
            {
                //  Unhandled underlying type - probably "long"
                throw new MyMwcExceptionApplicationShouldNotGetHere();
            }
        }