//This method call updates the sprite effect. //Note, it does this by waiting for the sprite update task to finish, //copying the sprite positions, then starting the sprite update again. //The sprite update runs while the drawing/app loop is running public void UpdateEffect(IState state) { //wait for the previous frame update to finish (it may still be running)... updateTask.WaitForCompletion(); //Note: at this point, the thread task is *not* active, so it is safe to //read/write the data used by the thread. Doing so before WaitForCompletion //would potentially be unsafe. //store the inputPosition into the buffer, so the task can access it. inputPositionBuffer = inputPosition; //copy out the updated position data... //note, the update task isn't active when this is called //otherwise the data may be still being written to by the thread task //(The thread task writes directly to 'spritePosition') this.spriteElement.SetSpritePositions(spritePosition); this.windowSize = new Vector2(state.Application.WindowWidth, state.Application.WindowHeight); //now, start the process up again. //being a new update task... //(this task could be split up, to help the xbox out even more) if (!runSingleThreaded) { //make sure the WaitCallback is assigned! updateTask = state.Application.ThreadPool.QueueTask(this, null); //now, at some point, the PerformAction method below will be called, //usually from another thread. //It's quite possible that the method has already been called and //has finished already by this point. } else { UpdateSprites(); //single thread update } }
//This method call updates the sprite effect. //Note, it does this by waiting for the sprite update task to finish, //copying the sprite positions, then starting the sprite update again. //The sprite update runs while the drawing/app loop is running public void UpdateEffect(IState state) { //wait for the previous frame update to finish (it may still be running)... updateTask.WaitForCompletion(); //Note: at this point, the thread task is *not* active, so it is safe to //read/write the data used by the thread. Doing so before WaitForCompletion //would potentially be unsafe. //store the inputPosition into the buffer, so the task can access it. inputPositionBuffer = inputPosition; //copy out the updated position data... //note, the update task isn't active when this is called //otherwise the data may be still being written to by the thread task //(The thread task writes directly to 'spritePosition') this.spriteElement.SetSpritePositions(spritePosition); this.windowSize = new Vector2(state.Application.WindowWidth, state.Application.WindowHeight); //now, start the process up again. //being a new update task... //(this task could be split up, to help the xbox out even more) if (!runSingleThreaded) { //make sure the WaitCallback is assigned! updateTask = state.Application.ThreadPool.QueueTask(this, null); //now, at some point, the PerformAction method below will be called, //usually from another thread. //It's quite possible that the method has already been called and //has finished already by this point. } else UpdateSprites(); //single thread update }