コード例 #1
0
ファイル: Entity.cs プロジェクト: sam-j-mair/Xeno-Engine
        //----------------------------------------------------------------------------------
        //----------------------------------------------------------------------------------
        #region con/de-structor
        protected Entity()
        {
            //the device id is where we get the authoritative ID from.
            m_nDeviceID = 0;
            //the Entity id ...which is allocated from a static member across all entities and incremented.
            m_idEntityID = s_idEntityIdCount++;

            //set defaults.
            m_idParentID = -1;
            m_childList  = new List <int>();
            Active       = true;

            //flags for storing status.
            m_flags = new BitArray(3);
            m_flags.Set((int)Status.PENDING_DELETION, false);
            m_flags.Set((int)Status.DELETED, false);
            m_flags.Set((int)Status.INITILIZING, true);

            //if there is a template definition file (XML) for this entity type.
            //they get loaded here..
            TemplateDefinitions.LoadTemplateDefaults(this);

            //Add the entity to the update loop.
            EngineServices.GetSystem <IGameSystems>().Components.Add(this);
        }
コード例 #2
0
        //----------------------------------------------------------------------------
        /// <summary>
        /// Initialize Effect uniforms for shader.
        /// </summary>
        /// <param name="settings"></param>
        //----------------------------------------------------------------------------
        public virtual void InitialiseEffect(dynamic settings = null)
        {
            EffectParameterCollection parameters = Effect.Parameters;

            // Look up shortcuts for parameters that change every frame.
            m_effectViewParameter          = parameters["View"];
            m_effectProjectionParameter    = parameters["Projection"];
            m_effectViewportScaleParameter = parameters["ViewportScale"];
            m_effectTimeParameter          = parameters["CurrentTime"];

//
            // Set the values of parameters that do not change.
            parameters["Duration"].SetValue((float)TimeSpan.FromSeconds(2).TotalSeconds);
            parameters["DurationRandomness"].SetValue(1);
            parameters["Gravity"].SetValue(new Vector3(0, 15, 0));
            parameters["EndVelocity"].SetValue(0);
            parameters["MinColor"].SetValue(new Color(255, 255, 255, 10).ToVector4());
            parameters["MaxColor"].SetValue(new Color(255, 255, 255, 40).ToVector4());

            parameters["RotateSpeed"].SetValue(
                new Vector2(-1, 1));

            parameters["StartSize"].SetValue(
                new Vector2(5, 10));

            parameters["EndSize"].SetValue(
                new Vector2(10, 40));

            // Load the particle texture, and set it onto the effect.
            Texture2D texture = EngineServices.GetSystem <IGameSystems>().Content.Load <Texture2D>("explosion");

            parameters["Texture"].SetValue(texture);
        }
コード例 #3
0
        protected new void OnDeserialized(StreamingContext context)
        {
#warning I need to switch this to use the AssetLoader instead of the contentManager
            GraphicsDevice gdevice = EngineServices.GetSystem <IGameSystems>().GraphicsDevice;
            m_WrappedType = new Effect(gdevice, m_restoreData);
            m_restoreData = null;
        }
コード例 #4
0
        //----------------------------------------------------------------------------
        //----------------------------------------------------------------------------
        protected virtual void Dispose(bool bDisposing)
        {
            if (bDisposing)
            {
                bool bFlag = false;
                try
                {
                    Monitor.Enter(this, ref bFlag);
                    if (EngineServices.GetSystem <IGameSystems>() != null)
                    {
                        EngineServices.GetSystem <IGameSystems>().Components.Remove(this);
                    }

                    if (Disposed != null)
                    {
                        Disposed(this, EventArgs.Empty);
                    }
                }
                finally
                {
                    if (bFlag)
                    {
                        Monitor.Exit(this);
                    }
                }
            }
        }
コード例 #5
0
 protected new void OnDeserialized(StreamingContext context)
 {
     if (!string.IsNullOrEmpty(m_restoreData))
     {
         m_WrappedType = EngineServices.GetSystem <IGameSystems>().Content.Load <SpriteFont>(m_restoreData);
     }
 }
コード例 #6
0
        //----------------------------------------------------------------------------
        //----------------------------------------------------------------------------
        protected void Dispose(bool bDisposing)
        {
            if (bDisposing)
            {
                bool bFlag = false;
                try
                {
                    Monitor.Enter(this, ref bFlag);

                    m_stateMachine = null;
                    m_buttonDictionary.Clear();
                    m_buttonDictionary = null;
                    m_states.Clear();
                    m_states = null;

                    if (EngineServices.GetSystem <IGameSystems>() != null)
                    {
                        EngineServices.GetSystem <IGameSystems>().Components.Remove(this);
                    }

                    if (Disposed != null)
                    {
                        Disposed(this, EventArgs.Empty);
                    }
                }
                finally
                {
                    if (bFlag)
                    {
                        Monitor.Exit(this);
                    }
                }
            }
        }
コード例 #7
0
        //-------------------------------------------------------------------------------
        //-------------------------------------------------------------------------------
        public void Dispose(bool bDisposing)
        {
            if (bDisposing)
            {
                bool bFlag = false;
                try
                {
                    Monitor.Enter(this, ref bFlag);
                    m_RenderInfoList.Clear();
                    m_RenderInfoList = null;

                    if (EngineServices.GetSystem <IGameSystems>() != null)
                    {
                        EngineServices.GetSystem <IGameSystems>().Components.Remove(this);
                    }

                    if (Disposed != null)
                    {
                        Disposed(this, EventArgs.Empty);
                    }
                }
                finally
                {
                    if (bFlag)
                    {
                        Monitor.Exit(this);
                    }
                }
            }
        }
コード例 #8
0
        //----------------------------------------------------------------------------
        //----------------------------------------------------------------------------
        public ParticleEmitter(IRenderLayer <TInfoType> renderLayer, Type particleType, ParticleController <TInfoType> controller, string szAssetName, Vector3 v3Position, int nMaxSprites)
        {
            m_RenderLayer      = renderLayer;
            m_Particles        = new List <IParticle>(nMaxSprites);
            m_freeParticleList = new Queue <IParticle>(nMaxSprites);

            SaveSerializationData("MaxSprites", nMaxSprites);
            SaveSerializationData("AssetName", szAssetName);
            SaveSerializationData("ParticleType", particleType);

            ParticleController = controller;

            m_bActive            = false;
            m_bContinuosEmission = false;
            m_bAllowGeneration   = false;
            Position             = v3Position;
            Enabled = true;

            EngineServices.GetSystem <IGameSystems>().Components.Add(this);

            for (int nCounter = 0; nCounter < nMaxSprites; ++nCounter)
            {
                IParticle particle = Activator.CreateInstance(particleType, new object[] { m_RenderLayer, szAssetName, Position, Vector3.Zero, 0, 0, false }) as IParticle;
                particle.ParticleDead += DeadParticle_Event;
                m_Particles.Add(particle);
                m_freeParticleList.Enqueue(particle);
            }
        }
コード例 #9
0
ファイル: SpriteBase.cs プロジェクト: sam-j-mair/Xeno-Engine
 //-------------------------------------------------------------------------------
 //-------------------------------------------------------------------------------
 public SpriteBase(string szAssetName, Vector3 v3Position, Color colour, List <AnimationDescription> animList)
 {
     m_spriteInfo             = new SpriteInfo();
     m_spriteAnimation        = new SpriteAnimation(animList);
     m_spriteInfo.m_texture2D = EngineServices.GetSystem <IGameSystems>().Content.Load <Texture2D>(szAssetName);
     InitialiseSprite(ref v3Position, colour);
     //m_animDirection = AnimationDirection
 }
コード例 #10
0
        //----------------------------------------------------------------------------
        //----------------------------------------------------------------------------
        private void Render(List <RenderData> renderList)
        {
            foreach (RenderData data in renderList)
            {
                if (data.Model != null)
                {
                    Model           model      = data.Model;
                    AnimationPlayer animPlayer = data.AnimPlayer;

                    if (data.RenderCallback != null)
                    {
                        data.RenderCallback(data.Model);
                        return;
                    }
                    // Copy any parent transforms.
                    //Matrix[] a44Bones = null;

                    //if(animPlayer != null)
                    //    a44Bones = animPlayer.GetSkinTransforms();

                    Matrix[] transforms = new Matrix[model.Bones.Count];
                    ICamera  camera     = EngineServices.GetSystem <IGameSystems>().Camera;
                    LightRig lightRig   = EngineServices.GetSystem <IGameSystems>().LightRig;

                    model.CopyAbsoluteBoneTransformsTo(transforms);

                    // Draw the model. A model can have multiple meshes, so loop.
                    foreach (ModelMesh mesh in model.Meshes)
                    {
                        // This is where the mesh orientation is set, as well
                        // as our camera and projection.
                        foreach (BasicEffect effect in mesh.Effects)
                        {
                            //Matrix.CreateFromQuaternion()
                            effect.EnableDefaultLighting();
                            effect.World      = transforms[mesh.ParentBone.Index] * Matrix.CreateTranslation(data.Position) * Matrix.CreateFromQuaternion(data.Orientation);
                            effect.Projection = camera.ProjectionMatrix;
                            effect.View       = camera.ViewMatrix;

                            //SetLightingData(lightRig, effect);

                            //foreach (EffectTechnique technique in effect.Techniques)
                            //{
                            //if (a44Bones != null) effect.Parameters["Bones"].SetValue(a44Bones);


                            //effect.Parameters["Projection"].SetValue(camera.ProjectionMatrix);
                            //effect.Parameters["View"].SetValue(camera.ViewMatrix);
                            //}
                        }
                        // Draw the mesh, using the effects set above.
                        mesh.Draw();
                    }
                }
            }
        }
コード例 #11
0
ファイル: AssetGroup.cs プロジェクト: sam-j-mair/Xeno-Engine
        //----------------------------------------------------------------------------------
        //----------------------------------------------------------------------------------
        public void Load()
        {
            Debug.Assert(!m_bLoaded, "you are trying to load a region that is already loaded.");
            {
                AssetLoader assetLoader = EngineServices.GetSystem <IGameSystems>().AssetLoader;

                assetLoader.Load(m_szAssetGroupName, LoadComplete);
                m_bLoaded = true;
            }
        }
コード例 #12
0
ファイル: TextBox.cs プロジェクト: sam-j-mair/Xeno-Engine
        //----------------------------------------------------------------------------
        //----------------------------------------------------------------------------
        public override void Update(DeltaTime deltaTime)
        {
            m_accumulator += deltaTime.ElapsedGameTime;
            if (m_bAcceptingText && (m_accumulator > m_InputDelayTimer))
            {
                Input input = EngineServices.GetSystem <IGameSystems>().InputSystem;
                //here we need to direct read the key inputs.
                InputKeyboardListner listner = (InputKeyboardListner)input.GetInputListner(ControllerType.Keyboard);

                m_accumulator = TimeSpan.Zero;

                foreach (Keys key in listner.GetRawInputBuffer())
                {
                    switch (key)
                    {
                    case Keys.Back:
                    {
                        if (m_textSprite.TextString.Length != 0)
                        {
                            string szNewString = m_textSprite.TextString.Substring(0, m_textSprite.TextString.Length - 1);
                            m_textSprite.TextString = szNewString;
                        }
                    }
                    break;

                    case Keys.Enter:
                    {
                        if (TextEntered != null)
                        {
                            TextEntered(m_textSprite.TextString);
                        }
                    }
                    break;

                    default:
                    {
                        m_szBuilder.Append(key.ToString());
                    }
                    break;
                    }
                }

                if (m_szBuilder.Length > 0)
                {
                    m_textSprite.TextString += m_szBuilder.ToString();
                    m_szBuilder.Clear();
                }

                UpdateCursor();
            }

            base.Update(deltaTime);
        }
コード例 #13
0
 public RenderLayer(int nMaxItems)
 {
     m_RenderInfoList = new List <TInfoType>(nMaxItems);
     EngineServices.GetSystem <IGameSystems>().Components.Add(this);
     m_blendState      = new SerialiableBlendState();
     BlendState        = BlendState.AlphaBlend;
     m_depthStencil    = new SerializableDepthStencil();
     DepthStencilState = DepthStencilState.Default;
     m_nMaxItems       = nMaxItems;
     Enabled           = true;
     Visible           = true;
 }
コード例 #14
0
ファイル: AssetGroup.cs プロジェクト: sam-j-mair/Xeno-Engine
        //----------------------------------------------------------------------------------
        //----------------------------------------------------------------------------------
        public void UnLoad()
        {
            Debug.Assert(m_bLoaded, "you are trying to unload a region that is not loaded.");
            {
                AssetLoader assetLoader = EngineServices.GetSystem <IGameSystems>().AssetLoader;

                StartUnloading();

                assetLoader.Unload(m_szAssetGroupName);
                m_bLoaded = false;
            }
        }
コード例 #15
0
ファイル: StaticMesh.cs プロジェクト: sam-j-mair/Xeno-Engine
        public StaticMesh(Model model, Vector3 v3Position)
        {
            Space space = EngineServices.GetSystem <IGameSystems>().PhysicsSpace;

            Vector3[] aVertices;
            int[]     aIndices;

            m_model      = model;
            m_v3Position = v3Position;

            TriangleMesh.GetVerticesAndIndicesFromModel(m_model, out aVertices, out aIndices);
            m_staticMesh = new BEPUphysics.Collidables.StaticMesh(aVertices, aIndices, new AffineTransform(Matrix3X3.CreateFromAxisAngle(Vector3.Up, MathHelper.Pi), m_v3Position));

            space.Add(m_staticMesh);
        }
コード例 #16
0
ファイル: SpriteBase.cs プロジェクト: sam-j-mair/Xeno-Engine
        //-------------------------------------------------------------------------------
        //-------------------------------------------------------------------------------
        public SpriteBase(string szFontName, StreamChunk streamChunk, string szTextString, Vector3 v3Position, Color colour)
        {
            m_spriteInfo = new SpriteInfo();

            if (streamChunk != null)
            {
                m_spriteInfo.m_spriteFont = streamChunk.GetAssetObjectByName <SpriteFont>(szFontName);
            }
            else
            {
                m_spriteInfo.m_spriteFont = EngineServices.GetSystem <IGameSystems>().Content.Load <SpriteFont>(szFontName);
            }

            m_spriteInfo.m_szTextString = szTextString;
            InitialiseSprite(ref v3Position, colour);
        }
コード例 #17
0
ファイル: Button.cs プロジェクト: sam-j-mair/Xeno-Engine
        // a readonly proxy object will be here that will allow detection of
        // mouse position and clicks etc.

        public Button(string szAssetName,
                      string szFontName,
                      Vector3 v3Position,
                      Color colour,
                      List <IScriptUpdateable <Button> > buttonScripts) : base(buttonScripts)
        {
            Input inputSytem = EngineServices.GetSystem <IGameSystems>().InputSystem;
            IRenderLayer <SpriteInfo> spriteSystem = EngineServices.GetSystem <IGameSystems>().SpriteSystem;


            EngineServices.GetSystem <IGameSystems>().Components.Add(this);
            m_sprite = new Sprite(spriteSystem, szAssetName, v3Position, colour, false);


            CalculateBoundingRectangle(m_sprite);
        }
コード例 #18
0
ファイル: GUIBase.cs プロジェクト: sam-j-mair/Xeno-Engine
        public GUIObject(List <IScriptUpdateable <Button> > buttonScripts)
        {
            Input inputSytem = EngineServices.GetSystem <IGameSystems>().InputSystem;

            m_buttonScripts     = new Dictionary <string, IScriptUpdateable <GUIObject> >(4);
            m_treeNode          = new GUINode();
            m_treeNode.UserData = this;
            m_currentState      = GUIInteractStates.Idle;

            m_mouseObserver = inputSytem.GetMouseObserver();

            InitialiseScripts(buttonScripts);
            ConnectedEvents(inputSytem);

            EngineServices.GetSystem <IGameSystems>().Components.Add(this);
            Enabled = true;
        }
コード例 #19
0
ファイル: Button.cs プロジェクト: sam-j-mair/Xeno-Engine
        //----------------------------------------------------------------------------
        /// <summary>
        /// C/TOR
        /// </summary>
        /// <param name="szAssetName">name of the asset</param>
        /// <param name="szFontName">font name if there is one.</param>
        /// <param name="v3Position">initial position.</param>
        /// <param name="colour">initial colour</param>
        /// <param name="streamChunk">the streamChunk it belong to.</param>
        /// <param name="buttonScripts">any scripts for the buttons.</param>
        //----------------------------------------------------------------------------
        public Button(string szAssetName,
                      string szFontName,
                      Vector3 v3Position,
                      Color colour,
                      StreamChunk streamChunk,
                      List <IScriptUpdateable <Button> > buttonScripts)
            : base(buttonScripts)
        {
            IRenderLayer <SpriteInfo> spriteSystem = EngineServices.GetSystem <IGameSystems>().SpriteSystem;

            m_sprite      = new Sprite(spriteSystem, szAssetName, streamChunk, v3Position, colour, false);
            m_szFontName  = szFontName;
            m_bSelected   = false;
            m_streamChunk = streamChunk;

            CalculateBoundingRectangle(m_sprite);
        }
コード例 #20
0
ファイル: SpriteBase.cs プロジェクト: sam-j-mair/Xeno-Engine
        public SpriteBase(string szAssetName, StreamChunk streamChunk, Vector3 v3Position, Color colour)
        {
#warning these need to be switched to stream loading.
            m_spriteInfo = new SpriteInfo();

            if (streamChunk != null)
            {
                m_spriteInfo.m_texture2D = streamChunk.GetAssetObjectByName <Texture2D>(szAssetName);
            }
            else
            {
                m_spriteInfo.m_texture2D = EngineServices.GetSystem <IGameSystems>().Content.Load <Texture2D>(szAssetName);
            }

            InitialiseSprite(ref v3Position, colour);

            //m_animDirection = AnimationDirection
        }
コード例 #21
0
ファイル: TextBox.cs プロジェクト: sam-j-mair/Xeno-Engine
        //----------------------------------------------------------------------------
        //----------------------------------------------------------------------------
        public TextBox(Vector2 v2Position,
                       Color eColor,
                       string szAssetNameBackground = null,
                       string szAssetNameCursor     = null,
                       string szFontName            = null)
            : base(null)
        {
            m_backGround = new Sprite(
                EngineServices.GetSystem <IGameSystems>().SpriteSystem,
                szAssetNameBackground != null ? szAssetNameBackground : "DefaultTextBox",
                new Vector3(v2Position, 0),
                eColor,
                false);

            m_backGround.ScaleFactor = new Vector2(1, 0.3f);

            m_textSprite = new TextSprite(
                EngineServices.GetSystem <IGameSystems>().FontSystem,
                szFontName != null ? szFontName : "DefaultFont",
                null,
                "",
                new Vector3(v2Position.X, v2Position.Y, 0.2f),
                Color.White,
                false);

            m_cursor = new Sprite(
                EngineServices.GetSystem <IGameSystems>().SpriteSystem,
                szAssetNameCursor != null ? szAssetNameCursor : "DefaultCursor",
                new Vector3(v2Position.X, v2Position.Y, 0.1f),
                Color.Red,
                false);

            OnClick += OnClickEvent;


            CalculateBoundingRectangle(m_backGround);

            //debug code.
            m_bAcceptingText  = true;
            m_InputDelayTimer = new TimeSpan(0, 0, 0, 0, 100);
            m_accumulator     = TimeSpan.Zero;
            m_szBuilder       = new StringBuilder();
        }
コード例 #22
0
        public Menu()
        {
            Input inputSystem = EngineServices.GetSystem <IGameSystems>().InputSystem;

            m_mouseObserver    = inputSystem.GetMouseObserver();
            m_states           = new Dictionary <String, State <Menu> >(5);
            m_buttonDictionary = new Dictionary <String, Button>(50);

            m_states.Add("Idle", new StateIdle());
            m_states.Add("Activating", new StateActivating());
            m_states.Add("Active", new StateActive());
            m_states.Add("Deactivating", new StateDeactivating());

            m_stateMachine  = new StateMachine <Menu>(m_states["Idle"], this);
            m_node          = new TreeNode <Menu>();
            m_node.UserData = this;
            m_bIsActive     = false;

            EngineServices.GetSystem <IGameSystems>().Components.Add(this);
        }
コード例 #23
0
        //-------------------------------------------------------------------------------
        //-------------------------------------------------------------------------------
        public static void PreLoadTemplates()
        {
            string szTemplateDirectory = EngineServices.GetSystem <IGameSystems>().WorkingDirectory + @"\Templates";
            //string szTypeName = GetType().FullName;
            XDocument template = null;
            //Type runtimeType = GetType();
            Assembly assembly = Assembly.GetEntryAssembly();

            foreach (Type type in assembly.GetTypes())
            {
                if (Directory.Exists(szTemplateDirectory))
                {
                    if (File.Exists(szTemplateDirectory + @"\" + type.FullName + ".xml"))
                    {
                        FileStream fStream = File.OpenRead(szTemplateDirectory + @"\" + type.FullName + ".xml");
                        template = XDocument.Load(fStream);
                        LoadTemplate(type, template);
                    }
                }
            }
        }
コード例 #24
0
        //----------------------------------------------------------------------------
        //----------------------------------------------------------------------------
        public void Dispose(bool bDisposing)
        {
            if (bDisposing)
            {
                bool bFlag = false;
                try
                {
                    Monitor.Enter(this, ref bFlag);
                    m_freeParticleList.Clear();

                    foreach (IParticle particle in m_Particles)
                    {
                        particle.Dispose();
                    }

                    m_Particles.Clear();
                    m_RenderLayer = null;

                    if (EngineServices.GetSystem <IGameSystems>() != null)
                    {
                        EngineServices.GetSystem <IGameSystems>().Components.Remove(this);
                    }

                    if (Disposed != null)
                    {
                        Disposed(this, EventArgs.Empty);
                    }
                }
                finally
                {
                    if (bFlag)
                    {
                        Monitor.Exit(this);
                    }
                }
            }
        }
コード例 #25
0
ファイル: GUIBase.cs プロジェクト: sam-j-mair/Xeno-Engine
        //----------------------------------------------------------------------------
        //----------------------------------------------------------------------------
        public virtual void Dispose(bool bDisposing)
        {
            if (bDisposing)
            {
                bool bFlag = false;
                try
                {
                    Monitor.Enter(this, ref bFlag);

                    m_treeNode.RemoveNode(true);
                    m_treeNode.Dispose();
                    m_treeNode      = null;
                    m_currentScript = null;
                    m_currentState  = GUIInteractStates.Idle;
                    m_buttonScripts.Clear();
                    m_buttonScripts = null;
                    m_mouseObserver = null;
                    OnClick        -= OnClickEvent;
                    OnOff          -= OnOffEvent;
                    OnOver         -= OnOverEvent;
                    OnUnClick      -= OnUnClickEvent;
                    OnClickPolling -= OnClickEventPolling;

                    if (EngineServices.GetSystem <IGameSystems>() != null)
                    {
                        EngineServices.GetSystem <IGameSystems>().Components.Remove(this);
                    }
                }
                finally
                {
                    if (bFlag)
                    {
                        Monitor.Exit(this);
                    }
                }
            }
        }
コード例 #26
0
        //----------------------------------------------------------------------------
        /// <summary>
        /// C/TOR
        /// </summary>
        /// <param name="nMaxItems">max number of items.</param>
        /// <param name="settings">the settings for the particle layer.</param>
        //----------------------------------------------------------------------------
        public Particle3DRenderLayer(int nMaxItems, EffectSettings settings)
            : base(nMaxItems)
        {
            m_vertexBuffer = new DynamicVertexBuffer(EngineServices.GetSystem <IGameSystems>().GraphicsDevice,
                                                     ParticleVertex.VertexDeclaration,
                                                     nMaxItems * 4,
                                                     BufferUsage.WriteOnly);

            m_aVertices = new ParticleVertex[nMaxItems * 4];

            ushort[] indices = new ushort[nMaxItems * 6];

            for (int i = 0; i < nMaxItems; i++)
            {
                indices[i * 6 + 0] = (ushort)(i * 4 + 0);
                indices[i * 6 + 1] = (ushort)(i * 4 + 1);
                indices[i * 6 + 2] = (ushort)(i * 4 + 2);

                indices[i * 6 + 3] = (ushort)(i * 4 + 0);
                indices[i * 6 + 4] = (ushort)(i * 4 + 2);
                indices[i * 6 + 5] = (ushort)(i * 4 + 3);
            }

            m_indexBuffer = new IndexBuffer(EngineServices.GetSystem <IGameSystems>().GraphicsDevice, typeof(ushort), indices.Length, BufferUsage.WriteOnly);
            m_indexBuffer.SetData(indices);

            if (settings != null)
            {
                EffectSettings = settings;
            }
            else
            {
                InitialiseEffect(settings);
            }

            m_fCurrentTime = 0;
        }
コード例 #27
0
        //----------------------------------------------------------------------------
        /// <summary>
        /// Draws particles to the screen.
        /// </summary>
        /// <param name="deltaTime"></param>
        //----------------------------------------------------------------------------
        public override void Draw(DeltaTime deltaTime)
        {
            CallRequestInfo(deltaTime);
            m_fCurrentTime += (float)deltaTime.ElapsedGameTime.TotalSeconds;

            if (m_RenderInfoList.Count > 0)
            {
                //quick hack
                if (EngineServices.GetSystem <IGameSystems>().GraphicsDevice != null)
                {
                    GraphicsDevice device = EngineServices.GetSystem <IGameSystems>().GraphicsDevice;
                    ICamera        camera = EngineServices.GetSystem <IGameSystems>().Camera;
                    Debug.Assert(camera != null, "There is no camera defined in the services.");

                    device.BlendState        = BlendState;
                    device.DepthStencilState = DepthStencilState;

                    //we build up the vertices's from the submissions
                    BuildVertexBuffer();

                    if (EffectSettings.m_fpUpdate != null)
                    {
                        EffectSettings.m_fpUpdate(EffectSettings.m_effect, EffectSettings.m_effectSettings);
                    }
                    else
                    {
                        //NOTE:[SM] i want this stuff to be set inside the particle controller. maybe
                        // Set an effect parameter describing the view port size. This is
                        // needed to convert particle sizes into screen space point sizes.
                        m_effectViewportScaleParameter.SetValue(new Vector2(0.5f / device.Viewport.AspectRatio, -0.5f));

                        m_effectProjectionParameter.SetValue(camera.ProjectionMatrix);
                        m_effectViewParameter.SetValue(camera.ViewMatrix);

                        // Set an effect parameter describing the current time. All the vertex
                        // shader particle animation is keyed off this value.
                        m_effectTimeParameter.SetValue(m_fCurrentTime);
                    }

                    // Set the particle vertex and index buffer.
                    device.SetVertexBuffer(m_vertexBuffer);
                    device.Indices = m_indexBuffer;

                    // Activate the particle effect.
                    foreach (EffectPass pass in Effect.CurrentTechnique.Passes)
                    {
                        pass.Apply();

                        device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0,
                                                     0, m_aVertices.Length,
                                                     0, m_aVertices.Length / 4);
                    }

                    device.DepthStencilState = DepthStencilState.Default;

                    //we clear the vertex buffer because this is a static field.
                    Array.Clear(m_aVertices, 0, 200);
                }

                // Reset some of the render states that we changed,
                // so as not to mess up any other subsequent drawing.

                m_RenderInfoList.Clear();
            }

            base.Draw(deltaTime);
        }
コード例 #28
0
 public RenderEngine()
 {
     m_Renderables = new Dictionary <int, List <RenderData> >();
     Visible       = true;
     EngineServices.GetSystem <IGameSystems>().Components.Add(this);
 }
コード例 #29
0
 protected void OnSerializing(StreamingContext context)
 {
     EngineServices.GetSystem <IGameSystems>().Components.Remove((IGameComponent)this);
 }
コード例 #30
0
 //------------------------------------------------------
 //------------------------------------------------------
 protected void OnDeserialized(StreamingContext context)
 {
     EngineServices.GetSystem <IGameSystems>().Components.Add((IGameComponent)this);
 }