Exemple #1
0
 public void UpdateComponents(ref GameTime gameTime)
 {
     for (int i = 0; i < Components.Count; i++)
     {
         XComponent Component = Components[i];
         if (Component is XIUpdateable)
         {
             Component.Update(ref gameTime);
         }
     }
 }
Exemple #2
0
        public void DrawScene(ref GameTime gameTime, ref XCamera Camera, List <XComponent> NoDrawComponents, List <Type> NoDrawTypes)
        {
            X.GraphicsDevice.RenderState.DepthBufferEnable      = true;
            X.GraphicsDevice.RenderState.DepthBufferWriteEnable = true;
            X.GraphicsDevice.RenderState.AlphaBlendEnable       = false;

            List <XComponent> Alpha = new List <XComponent>();

            //ActorsInView.Clear();

            //Begin 2D Sprite Batch
            X.spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Deferred, SaveStateMode.SaveState);
#if DEBUG
            //draw axis for debug info, so I can get an idea of where i am in the game
            X.DebugDrawer.DrawLine(new Vector3(-1000, 0, 0), new Vector3(1000, 0, 0), Color.Red);
            X.DebugDrawer.DrawLine(new Vector3(0, -1000, 0), new Vector3(0, 1000, 0), Color.Green);
            X.DebugDrawer.DrawLine(new Vector3(0, 0, -1000), new Vector3(0, 0, 1000), Color.Blue);

            /*X
             * for (int x = -100; x < 100; x++)
             * {
             *  X.DebugDrawer.DrawLine(new Vector3(x, -1000, 0), new Vector3(x, 1000, 0), Color.Red);
             *  for (int z = -100; z < 100; z++)
             *  {
             *      X.DebugDrawer.DrawLine(new Vector3(x, -1000, z), new Vector3(x, 1000, z), Color.Red);
             *  }
             *
             * }
             *
             * //Y
             * for (int y = -100; y < 100; y++)
             * {
             *  X.DebugDrawer.DrawLine(new Vector3(0, y, -1000), new Vector3(0, y, 1000), Color.Green);
             *  for (int z = -100; z < 100; z++)
             *  {
             *      X.DebugDrawer.DrawLine(new Vector3(-1000, y, z), new Vector3(1000, y, z), Color.Blue);
             *      X.DebugDrawer.DrawLine(new Vector3(z, y, -1000), new Vector3(z, y, 1000), Color.Green);
             *  }
             * }
             *
             * //Z
             * for (int z = -100; z < 100; z++)
             * {
             *  X.DebugDrawer.DrawLine(new Vector3(-1000, 0, z), new Vector3(1000, 0, z), Color.Blue);
             * }*/
#endif
            for (int i = 0; i < X.Components.Count; i++)
            {
                XComponent component = X.Components[i];

                //if debug rendering is on draw the XTriggerVolume(s)
#if DEBUG
                if (component is XTriggerVolume)
                {
                    component.Draw(ref gameTime, ref Camera);
                }
#endif
                //is this XComponent Drawable? and not the renderer?
                if (!(component is XIDrawable) || (component is XRenderer))
                {
                    continue;
                }

                //Is this XComponent on the NoDraw types list??
                if (NoDrawTypes != null)
                {
                    if (NoDrawTypes.Contains(component.GetType()))
                    {
                        continue;
                    }
                }

                //Is this XComponent on the NoDraw list?
                if (NoDrawComponents != null)
                {
                    if (NoDrawComponents.Contains(component))
                    {
                        continue;
                    }
                }

                //Add these components to another list to be draw at the end since they are alphablendable
                //after adding it to the list continue to the next component in this loop!
                if (component.AlphaBlendable)
                {
                    Alpha.Add(component);
                    continue;
                }

                if (component is XActor)
                {
                    //Does XActor, XHeightMap,XWater culling, add other types as create them
                    //Only enter this if the XActor is within the view or its NoCull is set
                    //if (Camera.Frustrum.Contains(((XActor)component).boundingBox) != ContainmentType.Disjoint || component.NoCull)
                    if (component.NoCull || (component is XTree) || Camera.Frustrum.Contains(((XActor)component).PhysicsObject.PhysicsBody.CollisionSkin.WorldBoundingBox) != ContainmentType.Disjoint)
                    {
                        component.Draw(ref gameTime, ref Camera);
                    }
                }
                else if (component is XHeightMap)
                {
                    if (Camera.Frustrum.Contains(((XHeightMap)component).boundingBox) != ContainmentType.Disjoint || component.NoCull)
                    {
                        component.Draw(ref gameTime, ref Camera);
                    }
                }
                else if (component is XWater)
                {
                    if (Camera.Frustrum.Contains(((XWater)component).boundingBox) != ContainmentType.Disjoint || component.NoCull)
                    {
                        component.Draw(ref gameTime, ref Camera);
                    }
                }
                else
                {
                    //Frustum testing????? Dynamicsky console debug debug drawer, menu manager
                    component.Draw(ref gameTime, ref Camera);
                }
            }//end xcomponent foreach loop

            //This list of XActors are in view and have Alphablending turned on, RENDER THEM LAST SO THEY BLEND WITH EVERYTHING!
            for (int j = 0; j < Alpha.Count; j++)
            {
                Alpha[j].Draw(ref gameTime, ref Camera);
            }

            //End Sprite Batch
            X.spriteBatch.End();
        }
Exemple #3
0
 public void AddComponent(XComponent Component)
 {
     components.Add(Component);
 }