/// <summary> /// Needs to be called before any of the usage methods are called. /// </summary> /// <param name="content">GameObjects will load into this conent manager.</param> /// <param name="graphics">Used for rendering.</param> public void Initialize(ContentManager content, GraphicsDeviceManager graphics) { mContent = content; mGraphics = graphics; mSpriteRasterState = new RasterizerState(); mSpriteSamplerState = new SamplerState(); // Prevent the edge of the sprite showing garabage. mSpriteRasterState.MultiSampleAntiAlias = false; // Keep the sprites looking Crisp. mSpriteSamplerState.Filter = TextureFilter.Point; mMultiply = new BlendState(); mMultiply.ColorSourceBlend = Blend.Zero; mMultiply.ColorDestinationBlend = Blend.SourceColor; // For now just hard code it. Eventually this should be driven by the Game side. mDefaultEffect = content.Load <Effect>("Shaders\\Default"); mCurrentUpdatePass = BehaviourDefinition.Passes.DEFAULT; // Just an arbitrary choice. mCellSize = 100; mCurrentUpdateState = UpdatePhase.None; }
/// <summary> /// Increment the number of frames passed. This should be called once a frame for /// most cases. If this StopWatch was created through the manager then this will be /// called automatically. /// </summary> /// <param name="numFrames"></param> public void AdvanceFrames(Single numFrames = 1) { if (!pIsPaused) { BehaviourDefinition.Passes curPass = GameObjectManager.pInstance.pCurUpdatePass; if (0 == mUpdatePasses.Count || mUpdatePasses.Contains(curPass)) { mNumFramesPassed += numFrames; } } }
/// <summary> /// Called once render cycle by the game object manager. /// </summary> /// <param name="batch">The sprite batch to render to.</param> /// <param name="effect">The currently set shader.</param> public virtual void Render(SpriteBatch batch, Effect effect) { BehaviourDefinition.Passes curPass = GameObjectManager.pInstance.pCurUpdatePass; for (int i = 0; i < mBehaviours.Count; i++) { if (mBehaviours[i].pIsEnabled && (null == mBehaviours[i].pRenderPassExclusions || !(mBehaviours[i].pRenderPassExclusions.Contains(curPass)))) { mBehaviours[i].Render(batch, effect); } } }
/// <summary> /// Called once per frame by the game object manager. /// </summary> /// <param name="gameTime">The amount of time that has passed this frame.</param> public virtual void Update(GameTime gameTime) { BehaviourDefinition.Passes curPass = GameObjectManager.pInstance.pCurUpdatePass; for (int i = 0; i < mBehaviours.Count; i++) { if (mBehaviours[i].pIsEnabled && (0 == mBehaviours[i].pUpdatePasses.Count || mBehaviours[i].pUpdatePasses.Contains(curPass))) { mBehaviours[i].Update(gameTime); } } }
/// <summary> /// Called once per frame after the Update function. Is called after all objects have /// caled Update. /// </summary> /// <param name="gameTime">The amount of time that has passed this frame.</param> public virtual void PostUpdate(GameTime gameTime) { BehaviourDefinition.Passes curPass = GameObjectManager.pInstance.pCurUpdatePass; for (int i = 0; i < mBehaviours.Count; i++) { if (mBehaviours[i].pIsEnabled && (0 == mBehaviours[i].pUpdatePasses.Count || mBehaviours[i].pUpdatePasses.Contains(curPass))) { mBehaviours[i].PostUpdate(gameTime); } } // With all behaviours done updating, it should be safe to // now update and draw the collision volume for this object. UpdateBounds(); mPrevPosition = mPosition; }
/// <summary> /// Sets which update passes are required to be active for this StopWatch to be updated. /// If not set it will be updated on every pass. /// </summary> /// <param name="pass">The pass on which this StopWatch should be updated.</param> public void SetUpdatePass(BehaviourDefinition.Passes pass) { mUpdatePasses.Add(pass); }