Пример #1
0
        private void UpdateRenderInstanceData(Dictionary <MyInstanceBucket, Tuple <List <MyCubeInstanceMergedData>, Sandbox.Game.Entities.Cube.MyInstanceInfo> > instanceParts, RenderFlags renderFlags)
        {
            if (this.m_parentCullObject == uint.MaxValue)
            {
                object[] objArray1 = new object[] { this.m_gridRenderComponent.Container.Entity.DisplayName, " ", this.m_gridRenderComponent.Container.Entity.EntityId, ", cull object" };
                this.AddRenderObjectId(true, out this.m_parentCullObject, MyRenderProxy.CreateManualCullObject(string.Concat(objArray1), this.m_gridRenderComponent.Container.Entity.PositionComp.WorldMatrix));
            }
            if (this.m_instanceBufferId == uint.MaxValue)
            {
                object[] objArray2 = new object[] { this.m_gridRenderComponent.Container.Entity.DisplayName, " ", this.m_gridRenderComponent.Container.Entity.EntityId, ", instance buffer ", this.DebugName };
                this.AddRenderObjectId(false, out this.m_instanceBufferId, MyRenderProxy.CreateRenderInstanceBuffer(string.Concat(objArray2), MyRenderInstanceBufferType.Cube, this.m_gridRenderComponent.GetRenderObjectID()));
            }
            this.m_instanceInfo.Clear();
            m_tmpDecalData.AssertEmpty <MyCubeInstanceDecalData>();
            m_tmpInstanceData.AssertEmpty <MyCubeInstanceData>();
            int num = -1;

            foreach (KeyValuePair <MyInstanceBucket, Tuple <List <MyCubeInstanceMergedData>, Sandbox.Game.Entities.Cube.MyInstanceInfo> > pair in instanceParts)
            {
                MyInstanceBucket key = pair.Key;
                Tuple <List <MyCubeInstanceMergedData>, Sandbox.Game.Entities.Cube.MyInstanceInfo> tuple = pair.Value;
                this.m_instanceInfo.Add(key, new MyRenderInstanceInfo(this.m_instanceBufferId, m_tmpInstanceData.Count, tuple.Item1.Count, tuple.Item2.MaxViewDistance, tuple.Item2.Flags));
                List <MyCubeInstanceMergedData> list = tuple.Item1;
                for (int i = 0; i < list.Count; i++)
                {
                    num++;
                    m_tmpInstanceData.Add(list[i].CubeInstanceData);
                    ConcurrentDictionary <uint, bool> decals = list[i].Decals;
                    if (decals != null)
                    {
                        foreach (uint num3 in decals.Keys)
                        {
                            MyCubeInstanceDecalData item = new MyCubeInstanceDecalData {
                                DecalId       = num3,
                                InstanceIndex = num
                            };
                            m_tmpDecalData.Add(item);
                        }
                    }
                }
            }
            if (m_tmpInstanceData.Count > 0)
            {
                MyRenderProxy.UpdateRenderCubeInstanceBuffer(this.m_instanceBufferId, ref m_tmpInstanceData, (int)(m_tmpInstanceData.Count * 1.2f), ref m_tmpDecalData);
            }
            m_tmpDecalData.AssertEmpty <MyCubeInstanceDecalData>();
            m_tmpInstanceData.AssertEmpty <MyCubeInstanceData>();
            this.UpdateRenderEntitiesInstanceData(renderFlags, this.m_parentCullObject);
        }
Пример #2
0
        private void AddInstancePart(Dictionary <MyInstanceBucket, Tuple <List <MyCubeInstanceMergedData>, Sandbox.Game.Entities.Cube.MyInstanceInfo> > instanceParts, int modelId, MyStringHash skinSubtypeId, ref MyCubeInstanceData instance, ConcurrentDictionary <uint, bool> decals, MyInstanceFlagsEnum flags, float maxViewDistance = 3.402823E+38f)
        {
            Tuple <List <MyCubeInstanceMergedData>, Sandbox.Game.Entities.Cube.MyInstanceInfo> tuple;
            MyInstanceBucket key = new MyInstanceBucket(modelId, skinSubtypeId);

            if (!instanceParts.TryGetValue(key, out tuple))
            {
                tuple = Tuple.Create <List <MyCubeInstanceMergedData>, Sandbox.Game.Entities.Cube.MyInstanceInfo>(new List <MyCubeInstanceMergedData>(), new Sandbox.Game.Entities.Cube.MyInstanceInfo(flags, maxViewDistance));
                instanceParts.Add(key, tuple);
            }
            Vector3 translation = instance.LocalMatrix.Translation;

            this.m_tmpBoundingBox.Min = translation - new Vector3(this.m_gridRenderComponent.GridSize);
            this.m_tmpBoundingBox.Max = translation + new Vector3(this.m_gridRenderComponent.GridSize);
            this.m_boundingBox.Include(this.m_tmpBoundingBox);
            MyCubeInstanceMergedData item = new MyCubeInstanceMergedData {
                CubeInstanceData = instance,
                Decals           = decals
            };

            tuple.Item1.Add(item);
        }