Example #1
0
        /// <returns>True if visible decals are found</returns>
        private static bool IterateVisibleRenderIDs(HashSet <uint> visibleRenderIDs, MyDecalFlags targetFlag, float squaredDistanceMax, uint sinceStartTs)
        {
            bool ret = false;

            foreach (uint renderID in visibleRenderIDs)
            {
                List <DecalNode> decals;
                bool             found = m_entityDecals.TryGetValue(renderID, out decals);
                if (!found)
                {
                    continue;
                }

                foreach (DecalNode node in decals)
                {
                    if (node.Value.FadeTimestamp < sinceStartTs)
                    {
                        RemoveDecalByNode(node);
                        continue;
                    }

                    MyScreenDecal decal = node.Value;
                    MyDecalFlags  flag  = decal.Flags & MyDecalFlags.Transparent;
                    if (flag == targetFlag && IsDecalWithinRadius(decal, squaredDistanceMax))
                    {
                        AddDecalNodeForDraw(node);
                        ret = true;
                    }
                }
            }

            return(ret);
        }
Example #2
0
        /// <returns>True if visible decals are found</returns>
        private static bool IterateDecals(HashSet <uint> visibleRenderIDs, MyDecalFlags targetFlag, float squaredDistanceMax, uint sinceStartTs)
        {
            bool ret = false;

            int       count   = m_decals.Count;
            DecalNode current = m_decals.First;
            int       it      = 0;

            while (current != null && it < count)
            {
                DecalNode next = current.Next;
                if (current.Value.FadeTimestamp < sinceStartTs)
                {
                    RemoveDecalByNode(current);
                    current = next;
                    continue;
                }

                MyScreenDecal decal = current.Value;
                MyDecalFlags  flag  = decal.Flags & MyDecalFlags.Transparent;
                if (flag == targetFlag && (visibleRenderIDs == null || visibleRenderIDs.Contains(decal.ParentID)) &&
                    IsDecalWithinRadius(decal, squaredDistanceMax))
                {
                    AddDecalNodeForDraw(current);
                    ret = true;
                }

                current = next;
                it++;
            }

            return(ret);
        }
        public static void AddDecal(uint ID, uint ParentID, ref MyDecalTopoData data, MyDecalFlags flags, string sourceTarget, string material, int matIndex)
        {
            if (m_decals.Count == m_decalsQueueSize)
            {
                MarkForRemove(m_decals.First.Value);
            }

            MyScreenDecal decal = new MyScreenDecal();

            decal.FadeTimestamp = uint.MaxValue;
            decal.ID            = ID;
            decal.ParentID      = ParentID;
            decal.Data          = data;
            decal.Flags         = flags;
            decal.OBBox         = ComputeOBB(ref data, flags);
            decal.SourceTarget  = sourceTarget;
            decal.Material      = material;
            decal.MaterialId    = X.TEXT_(material);
            decal.MaterialIndex = matIndex;

            DecalNode node = m_decals.AddLast(decal);

            m_nodeMap[ID] = node;

            List <DecalNode> handles;
            bool             found = m_entityDecals.TryGetValue(ParentID, out handles);

            if (!found)
            {
                handles = new List <DecalNode>();
                m_entityDecals.Add(ParentID, handles);
            }

            handles.Add(node);
        }
Example #4
0
        public static void AddDecal(uint ID, uint ParentID, Matrix localOBB, string material)
        {
            if (m_decals.Count == m_decalsQueueSize)
            {
                RemoveDecalByNode(m_decals.First);
            }

            MyScreenDecal decal = new MyScreenDecal();

            decal.ID       = ID;
            decal.ParentID = ParentID;
            decal.LocalOBB = localOBB;
            decal.Material = X.TEXT(material);

            DecalNode node = m_decals.AddLast(decal);

            m_nodeMap[ID] = node;

            List <DecalNode> handles;
            bool             found = m_entityDecals.TryGetValue(ParentID, out handles);

            if (!found)
            {
                handles = new List <DecalNode>();
                m_entityDecals.Add(ParentID, handles);
            }

            handles.Add(node);

            // FIX-ME Add proper support for voxel maps and re-enable some sanity checks
            //Debug.Assert(MyIDTracker<MyActor>.FindByID(ParentID) != null, "Decal added to non-existing render entity");
        }
Example #5
0
        private static void RemoveDecalByNode(DecalNode node)
        {
            MyScreenDecal decal = node.Value;

            m_entityDecals[decal.ParentID].Remove(node);
            m_decals.Remove(node);
            m_nodeMap.Remove(decal.ID);
        }
Example #6
0
        static void AddDecalForDraw(MyScreenDecal decal)
        {
            List <MyScreenDecal> decals;
            bool found = m_materialsToDraw.TryGetValue(decal.Material, out decals);

            if (!found)
            {
                decals = new List <MyScreenDecal>();
                m_materialsToDraw[decal.Material] = decals;
            }

            decals.Add(decal);
        }
Example #7
0
        private static void RemoveDecalByNode(DecalNode node)
        {
            MyScreenDecal    decal  = node.Value;
            List <DecalNode> decals = m_entityDecals[decal.ParentID];

            decals.Remove(node);
            if (decals.Count == 0)
            {
                m_entityDecals.Remove(decal.ParentID);
            }

            m_decals.Remove(node);
            m_nodeMap.Remove(decal.ID);
        }
Example #8
0
        private static void RemoveDecalByNode(DecalNode node)
        {
            MyScreenDecal    decal  = node.Value;
            List <DecalNode> decals = m_entityDecals[decal.ParentID];

            decals.Remove(node);
            if (decals.Count == 0)
            {
                m_entityDecals.Remove(decal.ParentID);
            }

            m_decals.Remove(node);
            m_nodeMap.Remove(decal.ID);
            MyRenderProxy.RemoveMessageId(decal.ID, MyRenderProxy.ObjectType.ScreenDecal);
        }
Example #9
0
        internal static void AddDecal(uint ID, uint ParentID, ref MyDecalTopoData topoData, MyDecalFlags flags, string sourceTarget, string material, int matIndex)
        {
            if (m_decals.Count >= m_decalsQueueSize && m_decals.Count != 0)
            {
                MarkForRemove(m_decals.First);
            }

            MyScreenDecal decal = new MyScreenDecal();

            decal.FadeTimestamp = uint.MaxValue;
            decal.ID            = ID;
            decal.ParentID      = ParentID;
            decal.TopoData      = topoData;
            decal.Flags         = flags;
            decal.SourceTarget  = sourceTarget;
            decal.Material      = material;
            decal.MaterialId    = X.TEXT_(material);
            decal.MaterialIndex = matIndex;

            if (!flags.HasFlag(MyDecalFlags.World))
            {
                var parent = MyIDTracker <MyActor> .FindByID(ParentID);

                if (parent == null)
                {
                    return;
                }

                decal.TopoData.WorldPosition = Vector3D.Transform(topoData.MatrixCurrent.Translation, ref parent.WorldMatrix);
            }

            DecalNode node = m_decals.AddLast(decal);

            m_nodeMap[ID] = node;

            List <DecalNode> handles;
            bool             found = m_entityDecals.TryGetValue(ParentID, out handles);

            if (!found)
            {
                handles = new List <DecalNode>();
                m_entityDecals.Add(ParentID, handles);
            }

            handles.Add(node);
        }
Example #10
0
        static void AddDecalForDraw(MyScreenDecal decal)
        {
            List <MyScreenDecal> decals;
            MyMaterialIdentity   identity = new MyMaterialIdentity()
            {
                Material = decal.MaterialId, Index = decal.MaterialIndex
            };
            bool found = m_materialsToDraw.TryGetValue(identity, out decals);

            if (!found)
            {
                decals = new List <MyScreenDecal>();
                m_materialsToDraw[identity] = decals;
            }

            decals.Add(decal);
        }
        public static void UpdateDecals(List <MyDecalPositionUpdate> decals)
        {
            for (int it = 0; it < decals.Count; it++)
            {
                MyDecalPositionUpdate position = decals[it];

                DecalNode node;
                bool      found = m_nodeMap.TryGetValue(position.ID, out node);
                if (!found)
                {
                    continue;
                }

                MyScreenDecal decal = node.Value;
                decal.Data.Position = position.Position;
                decal.Data.Normal   = position.Normal;
                node.Value.OBBox    = ComputeOBB(ref decal.Data, decal.Flags);
            }
        }
Example #12
0
        static bool IsDecalWithinRadius(MyScreenDecal decal, float squaredDistanceMax)
        {
            var parent = MyIDTracker <MyActor> .FindByID(decal.ParentID);

            bool world = decal.Flags.HasFlag(MyDecalFlags.World);

            Vector3 distance;

            if (world)
            {
                distance = (decal.TopoData.WorldPosition - MyRender11.Environment.Matrices.CameraPosition);
            }
            else
            {
                MatrixD volumeMatrixD = ((MatrixD)decal.TopoData.MatrixCurrent) * parent.WorldMatrix;
                distance = (volumeMatrixD.Translation - MyRender11.Environment.Matrices.CameraPosition);
            }

            float squaredDistance = (float)distance.LengthSquared();

            return(squaredDistance <= squaredDistanceMax);
        }
Example #13
0
        public static void UpdateDecals(IReadOnlyList <MyDecalPositionUpdate> decals)
        {
            uint    currentObjectId    = MyRenderProxy.RENDER_ID_UNASSIGNED;
            MatrixD currentWorldMatrix = new MatrixD();

            for (int it = 0; it < decals.Count; it++)
            {
                MyDecalPositionUpdate position = decals[it];

                DecalNode node;
                bool      found = m_nodeMap.TryGetValue(position.ID, out node);
                if (!found)
                {
                    continue;
                }
                MyScreenDecal decal = node.Value;
                if (decal.Flags.HasFlag(MyDecalFlags.World))
                {
                    decal.TopoData.WorldPosition = position.Position;
                }
                else
                {
                    if (currentObjectId != decal.ParentID)
                    {
                        var parent = MyIDTracker <MyActor> .FindByID(decal.ParentID);

                        currentWorldMatrix = parent.WorldMatrix;
                        currentObjectId    = decal.ParentID;
                    }

                    decal.TopoData.WorldPosition = Vector3D.Transform(position.Transform.Translation, ref currentWorldMatrix);
                }

                node.Value.TopoData.MatrixCurrent = position.Transform;
            }
        }
        private static void MarkForRemove(MyScreenDecal decal)
        {
            uint now = GetTimeStampSinceStart();

            decal.FadeTimestamp = now + DECAL_FADE_DURATION;
        }
        static void AddDecalForDraw(MyScreenDecal decal)
        {
            List<MyScreenDecal> decals;
            bool found = m_materialsToDraw.TryGetValue(decal.Material, out decals);
            if (!found)
            {
                decals = new List<MyScreenDecal>();
                m_materialsToDraw[decal.Material] = decals;
            }

            decals.Add(decal);
        }
Example #16
0
        static bool IsDecalWithinRadius(MyScreenDecal decal, float squaredDistanceMax)
        {
            float squaredDistance = (float)(decal.TopoData.WorldPosition - MyRender11.Environment.Matrices.CameraPosition).LengthSquared();

            return(squaredDistance <= squaredDistanceMax);
        }
        public static void AddDecal(uint ID, uint ParentID, Matrix localOBB, string material)
        {
            if (m_decals.Count == m_decalsQueueSize)
                RemoveDecalByNode(m_decals.First);

            MyScreenDecal decal = new MyScreenDecal();
            decal.ID = ID;
            decal.ParentID = ParentID;
            decal.LocalOBB = localOBB;
            decal.Material = X.TEXT_(material);

            DecalNode node = m_decals.AddLast(decal);

            m_nodeMap[ID] = node;

            List<DecalNode> handles;
            bool found = m_entityDecals.TryGetValue(ParentID, out handles);
            if (!found)
            {
                handles = new List<DecalNode>();
                m_entityDecals.Add(ParentID, handles);
            }

            handles.Add(node);

            // FIX-ME Add proper support for voxel maps and re-enable some sanity checks
            //Debug.Assert(MyIDTracker<MyActor>.FindByID(ParentID) != null, "Decal added to non-existing render entity");
        }