Пример #1
0
        //  We have only Update method for explosions, because drawing of explosion is mantained by particles and lights itself
        public override void UpdateBeforeSimulation()
        {
            SwapBuffers();

            foreach (var explosionInfo in m_explosionsRead)
            {
                MyExplosion explosion = null;
                m_explosions.AllocateOrCreate(out explosion);

                if (explosion != null)
                {
                    explosion.Start(explosionInfo);
                }
            }

            m_explosionsRead.Clear();

            //  Go over every active explosion and draw it, unless it isn't dead.
            foreach (var explosion in m_explosions.Active)
            {
                if (explosion.Update() == false)
                {
                    m_explosions.MarkForDeallocate(explosion);
                }
            }

            //  Deallocate/delete all lights that are turned off
            m_explosions.DeallocateAllMarked();
        }
Пример #2
0
        static void UpdateExplosionLines()
        {
            foreach (LinkedListNode <ExplosionLine> explosionLine in m_preallocatedExplosionLines)
            {
                explosionLine.Value.ActualTime += MyConstants.PHYSICS_STEP_SIZE_IN_MILLISECONDS;
                if (explosionLine.Value.ActualTime > explosionLine.Value.TotalTime)
                {
                    m_preallocatedExplosionLines.MarkForDeallocate(explosionLine);
                    continue;
                }

                explosionLine.Value.ActualDir = Vector3.Lerp(explosionLine.Value.StartDir, explosionLine.Value.EndDir, explosionLine.Value.ActualTime / (float)explosionLine.Value.TotalTime);
            }

            m_preallocatedExplosionLines.DeallocateAllMarked();
            if (m_State == NuclearState.FADE_IN && MyMwcUtils.GetRandomFloat(0, 1) > 0.75f)
            {
                ExplosionLine line = m_preallocatedExplosionLines.Allocate(true);
                if (line != null)
                {
                    line.TotalTime  = 5000;
                    line.ActualTime = 0;
                    line.StartDir   = MyMwcUtils.GetRandomVector3Normalized();

                    Vector3 rotDir    = MyMwcUtils.GetRandomVector3Normalized();
                    Matrix  rotMatrix = Matrix.CreateFromAxisAngle(rotDir, 0.3f);
                    line.EndDir = Vector3.Transform(line.StartDir, rotMatrix);
                }
            }
        }
Пример #3
0
        //  Update active projectiles. If projectile dies/timeouts, remove it from the list.
        public static void Update()
        {
            foreach (LinkedListNode <MyProjectile> item in m_projectiles)
            {
                if (item.Value.Update() == false)
                {
                    item.Value.Close();
                    m_projectiles.MarkForDeallocate(item);
                }
            }

            m_projectiles.DeallocateAllMarked();
        }
Пример #4
0
        //  Update active projectiles. If projectile dies/timeouts, remove it from the list.
        public override void UpdateBeforeSimulation()
        {
            foreach (MyProjectile item in m_projectiles.Active)
            {
                if (item.Update() == false)
                {
                    item.Close();
                    m_projectiles.MarkForDeallocate(item);
                }
            }

            m_projectiles.DeallocateAllMarked();
        }
Пример #5
0
        //  We have only Update method for explosions, because drawing of explosion is mantained by particles and lights itself
        public static void Update()
        {
            //  Go over every active explosion and draw it, unless it isn't dead.
            foreach (LinkedListNode <MyExplosion> item in m_explosions)
            {
                if (item.Value.Update() == false)
                {
                    m_explosions.MarkForDeallocate(item);
                }
            }

            //  Deallocate/delete all lights that are turned off
            m_explosions.DeallocateAllMarked();
        }
Пример #6
0
        public void DisposeAll()
        {
            foreach (var shadowmap in m_objectsPoolSingleShadowmap.Active)
            {
                shadowmap.Destroy();
                m_objectsPoolSingleShadowmap.MarkForDeallocate(shadowmap);
            }
            m_objectsPoolSingleShadowmap.DeallocateAllMarked();

            foreach (var shadowmap in m_objectsPoolCsm.Active)
            {
                shadowmap.Destroy();
                m_objectsPoolCsm.MarkForDeallocate(shadowmap);
            }
            m_objectsPoolCsm.DeallocateAllMarked();
        }
Пример #7
0
 public static void Deallocate(LinkedListNode <MyVoxelContentCellContent> item)
 {
     m_preallocatedContents.MarkForDeallocate(item);
     m_preallocatedContents.DeallocateAllMarked();
 }
Пример #8
0
        //  Copy triangles to array of vertexes (which is then copyed to vertex buffer) and return count of triangles to draw
        public int CopyDecalsToVertices(MyVertexFormatGlassDecal[] vertexes)
        {
            int trianglesToDraw = 0;

            foreach (LinkedListNode <MyCockpitGlassDecalTriangle> item in m_triangles)
            {
                MyCockpitGlassDecalTriangle triangle = item.Value;

                int deltaTime = MyMinerGame.TotalGamePlayTimeInMilliseconds - triangle.CreatedTime;

                //  If triangleVertexes is completely faded-out, we remove it from buffer and don't draw it now
                if (deltaTime >= (m_fadeOutStartInMiliseconds + m_fadeOutLengthInMiliseconds))
                {
                    m_triangles.MarkForDeallocate(item);
                    continue;
                }

                int vertexIndexStart = trianglesToDraw * MyCockpitGlassDecalsConstants.VERTEXES_PER_DECAL;

                //  Texture coords
                vertexes[vertexIndexStart + 0].TexCoord = triangle.TexCoord0;
                vertexes[vertexIndexStart + 1].TexCoord = triangle.TexCoord1;
                vertexes[vertexIndexStart + 2].TexCoord = triangle.TexCoord2;

                float alpha = 1.0f;
                if (deltaTime <= m_fadeInPhaseInMiliseconds)
                {
                    //  If we are in fade-in phase (initial phase)
                    alpha = (float)deltaTime / (float)m_fadeInPhaseInMiliseconds;
                }
                else if (deltaTime >= m_fadeOutStartInMiliseconds)
                {
                    //  If fading-out started, change alpha here
                    alpha = 1.0f - ((float)(deltaTime - m_fadeOutStartInMiliseconds) / (float)m_fadeOutLengthInMiliseconds);
                }

                //  Vertex position
                vertexes[vertexIndexStart + 0].SetPositionAndAlpha(ref triangle.Position0, System.Math.Min(alpha, triangle.Alpha012.X));
                vertexes[vertexIndexStart + 1].SetPositionAndAlpha(ref triangle.Position1, System.Math.Min(alpha, triangle.Alpha012.Y));
                vertexes[vertexIndexStart + 2].SetPositionAndAlpha(ref triangle.Position2, System.Math.Min(alpha, triangle.Alpha012.Z));

                //  Normal vectors
                Vector3 normal0 = triangle.Normal0;
                Vector3 normal1 = triangle.Normal1;
                Vector3 normal2 = triangle.Normal2;

                // Normals for glass decals aren't normalized
                normal0.Normalize();
                normal1.Normalize();
                normal2.Normalize();

                vertexes[vertexIndexStart + 0].Normal = normal0;
                vertexes[vertexIndexStart + 1].Normal = normal1;
                vertexes[vertexIndexStart + 2].Normal = normal2;

                trianglesToDraw++;
            }

            m_triangles.DeallocateAllMarked();

            return(trianglesToDraw);
        }