Просмотр исходного кода

Comment out shader calls. Fix Join Session crash.

Dominique Louis 3 недель назад
Родитель
Сommit
52b26332ba

+ 1 - 3
NetRumble/Core/BloomPostprocess/BloomComponent.cs

@@ -178,10 +178,8 @@ namespace NetRumble
 
             GraphicsDevice.Textures[1] = sceneRenderTarget;
 
-            Viewport viewport = GraphicsDevice.Viewport;
-
             DrawFullscreenQuad(renderTarget1,
-                               viewport.Width, viewport.Height,
+                               ScreenManager.BASE_BUFFER_WIDTH, ScreenManager.BASE_BUFFER_HEIGHT,
                                bloomCombineEffect,
                                IntermediateBuffer.FinalResult);
 //            DrawFullscreenQuad(sceneRenderTarget,

+ 12 - 12
NetRumble/Core/Content/Content.mgcb

@@ -15,24 +15,24 @@
 #---------------------------------- Content ---------------------------------#
 
 #begin Effects/BloomCombine.fx
-/importer:EffectImporter
-/processor:EffectProcessor
-/build:Effects/BloomCombine.fx
+#/importer:EffectImporter
+#/processor:EffectProcessor
+#/build:Effects/BloomCombine.fx
 
 #begin Effects/BloomExtract.fx
-/importer:EffectImporter
-/processor:EffectProcessor
-/build:Effects/BloomExtract.fx
+#/importer:EffectImporter
+#/processor:EffectProcessor
+#/build:Effects/BloomExtract.fx
 
 #begin Effects/GaussianBlur.fx
-/importer:EffectImporter
-/processor:EffectProcessor
-/build:Effects/GaussianBlur.fx
+#/importer:EffectImporter
+#/processor:EffectProcessor
+#/build:Effects/GaussianBlur.fx
 
 #begin Effects/Clouds.fx
-/importer:EffectImporter
-/processor:EffectProcessor
-/build:Effects/Clouds.fx
+#/importer:EffectImporter
+#/processor:EffectProcessor
+#/build:Effects/Clouds.fx
 
 #begin Textures/blank.png
 /importer:TextureImporter

+ 7 - 6
NetRumble/Core/Gameplay/World.cs

@@ -478,7 +478,7 @@ namespace NetRumble
                     // initialize the asteroid and it's starting position
                     asteroids[i].Initialize();
                     asteroids[i].Position =
-                        CollisionManager.FindSpawnPoint(asteroids[i], 
+                        CollisionManager.FindSpawnPoint(asteroids[i],
                         asteroids[i].Radius);
                     // write the starting position and velocity
                     packetWriter.Write(asteroids[i].Position);
@@ -612,7 +612,7 @@ namespace NetRumble
                         {
                             packetWriter.Write((int)PacketTypes.GameWon);
                             packetWriter.Write(highScoreIndex);
-                            localGamer.SendData(packetWriter, 
+                            localGamer.SendData(packetWriter,
                                 SendDataOptions.ReliableInOrder);
                         }
 
@@ -647,7 +647,7 @@ namespace NetRumble
                                 packetWriter.Write(RandomMath.Random.Next(3));
                                 packetWriter.Write(CollisionManager.FindSpawnPoint(null,
                                     PowerUp.PowerUpRadius * 3f));
-                                localGamer.SendData(packetWriter, 
+                                localGamer.SendData(packetWriter,
                                     SendDataOptions.ReliableInOrder);
                             }
                         }
@@ -1012,7 +1012,7 @@ namespace NetRumble
         /// <param name="sender">The sender of the packet.</param>
         private void UpdatePlayerData(NetworkGamer sender)
         {
-            if ((networkSession != null) && (networkSession.LocalGamers.Count > 0) && 
+            if ((networkSession != null) && (networkSession.LocalGamers.Count > 0) &&
                 (sender != null))
             {
                 PlayerData playerData = sender.Tag as PlayerData;
@@ -1026,7 +1026,7 @@ namespace NetRumble
                     {
                         PlayerData localPlayerData =
                             localNetworkGamer.Tag as PlayerData;
-                        if ((localPlayerData != null) && 
+                        if ((localPlayerData != null) &&
                             !Ship.HasUniqueColorIndex(localNetworkGamer,
                                networkSession))
                         {
@@ -1034,7 +1034,8 @@ namespace NetRumble
                                 localPlayerData.ShipColor, networkSession);
                             packetWriter.Write((int)World.PacketTypes.PlayerData);
                             localPlayerData.Serialize(packetWriter);
-                            networkSession.LocalGamers[0].SendData(packetWriter, 
+
+                            networkSession.LocalGamers[0].SendData(packetWriter,
                                 SendDataOptions.ReliableInOrder);
                         }
                     }

+ 2 - 2
NetRumble/Core/NetRumbleGame.cs

@@ -63,8 +63,8 @@ namespace NetRumble
             // initialize the graphics device manager
             graphicsDeviceManager = new GraphicsDeviceManager(this);
 
-            graphicsDeviceManager.PreferredBackBufferWidth = 1280;
-            graphicsDeviceManager.PreferredBackBufferHeight = 720;
+            graphicsDeviceManager.PreferredBackBufferWidth = ScreenManager.BASE_BUFFER_WIDTH;
+            graphicsDeviceManager.PreferredBackBufferHeight = ScreenManager.BASE_BUFFER_HEIGHT;
 
             if (UIUtility.IsMobile)
             {

+ 20 - 17
NetRumble/Core/Rendering/Starfield.cs

@@ -112,12 +112,12 @@ namespace NetRumble
         /// <summary>
         /// The effect used to draw the clouds.
         /// </summary>
-        // TODO private Effect cloudEffect;
+        private Effect cloudEffect;
 
         /// <summary>
         /// The parameter on the cloud effect that receives the current position
         /// </summary>
-        // TODO private EffectParameter cloudEffectPosition;
+        private EffectParameter cloudEffectPosition;
 
         /// <summary>
         /// Create a new Starfield object.
@@ -174,8 +174,8 @@ namespace NetRumble
         public void UnloadContent()
         {
             cloudTexture = null;
-            // TODO cloudEffect = null;
-            // TODO cloudEffectPosition = null;
+            cloudEffect = null;
+            cloudEffectPosition = null;
 
             if (starTexture != null)
             {
@@ -197,8 +197,8 @@ namespace NetRumble
         public void Reset(Vector2 position)
         {
             // recreate the stars
-            int viewportWidth = graphicsDevice.Viewport.Width;
-            int viewportHeight = graphicsDevice.Viewport.Height;
+            int viewportWidth = ScreenManager.BASE_BUFFER_WIDTH;
+            int viewportHeight = ScreenManager.BASE_BUFFER_HEIGHT;
             for (int i = 0; i < stars.Length; ++i)
             {
                 stars[i] = new Vector2(RandomMath.Random.Next(0, viewportWidth),
@@ -229,7 +229,7 @@ namespace NetRumble
             Vector2 movement = -1.0f * (position - lastPosition);
 
             // create a rectangle representing the screen dimensions of the starfield
-            Rectangle starfieldRectangle = new Rectangle(0, 0, graphicsDevice.Viewport.Width, graphicsDevice.Viewport.Height);
+            Rectangle starfieldRectangle = new Rectangle(0, 0, ScreenManager.BASE_BUFFER_WIDTH, ScreenManager.BASE_BUFFER_HEIGHT);
 
             // draw a background color for the starfield
             spriteBatch.Begin();
@@ -237,18 +237,21 @@ namespace NetRumble
             spriteBatch.End();
 
             // draw the cloud texture
-            /* TODO cloudEffectPosition.SetValue(this.position);
-            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, null, null, null, cloudEffect);
-            spriteBatch.Draw(cloudTexture, starfieldRectangle, null, Color.White, 0.0f, Vector2.Zero, SpriteEffects.None, 1.0f);
-            spriteBatch.End();*/
-
-            // if we've moved too far, then reset, as the stars will be moving too fast
-            if (movement.Length() > maximumMovementPerUpdate)
+            if (cloudEffect != null)
             {
-                Reset(position);
-                return;
+                cloudEffectPosition.SetValue(this.position);
+                spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, null, null, null, cloudEffect);
+                spriteBatch.Draw(cloudTexture, starfieldRectangle, null, Color.White, 0.0f, Vector2.Zero, SpriteEffects.None, 1.0f);
+                spriteBatch.End();
             }
 
+            // if we've moved too far, then reset, as the stars will be moving too fast
+                if (movement.Length() > maximumMovementPerUpdate)
+                {
+                    Reset(position);
+                    return;
+                }
+
             // draw all of the stars
             spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied);
             for (int i = 0; i < stars.Length; i++)
@@ -277,7 +280,7 @@ namespace NetRumble
                     stars[i].Y = starfieldRectangle.Y + starfieldRectangle.Height;
                 }
                 if (stars[i].Y >
-                    (starfieldRectangle.Y + graphicsDevice.Viewport.Height))
+                    (starfieldRectangle.Y + ScreenManager.BASE_BUFFER_HEIGHT))
                 {
                     stars[i].X = starfieldRectangle.X +
                         RandomMath.Random.Next(starfieldRectangle.Width);

+ 14 - 22
NetRumble/Core/ScreenManager/GameScreen.cs

@@ -159,25 +159,19 @@ namespace NetRumble
 
         ScreenManager screenManager;
 
-
-
-
-
         /// <summary>
         /// Load graphics content for the screen.
         /// </summary>
-        public virtual void LoadContent() { }
-
+        public virtual void LoadContent()
+        {
+            ScreenManager.ScalePresentationArea();
+        }
 
         /// <summary>
         /// Unload content for the screen.
         /// </summary>
         public virtual void UnloadContent() { }
 
-
-
-
-
         /// <summary>
         /// Allows the screen to run logic, such as updating the transition position.
         /// Unlike HandleInput, this method is called regardless of whether the screen
@@ -229,8 +223,15 @@ namespace NetRumble
                     screenState = ScreenState.Active;
                 }
             }
-        }
 
+            // Check if the back buffer size has changed (e.g., window resize).
+            if (ScreenManager.BackbufferHeight != ScreenManager.GraphicsDevice.PresentationParameters.BackBufferHeight
+                || ScreenManager.BackbufferWidth != ScreenManager.GraphicsDevice.PresentationParameters.BackBufferWidth)
+            {
+                // Adjust the presentation area to match the new back buffer size.
+                ScreenManager.ScalePresentationArea();
+            }
+        }
 
         /// <summary>
         /// Helper for updating the screen transition position.
@@ -255,12 +256,11 @@ namespace NetRumble
                 transitionPosition = MathHelper.Clamp(transitionPosition, 0, 1);
                 return false;
             }
-            
+
             // Otherwise we are still busy transitioning.
             return true;
         }
 
-
         /// <summary>
         /// Allows the screen to handle user input. Unlike Update, this method
         /// is only called when the screen is active, and not when some other
@@ -268,22 +268,16 @@ namespace NetRumble
         /// </summary>
         public virtual void HandleInput(InputState input) { }
 
-
         /// <summary>
         /// Screen-specific update to gamer rich presence.
         /// </summary>
         public virtual void UpdatePresence() { }
 
-
         /// <summary>
         /// This is called when the screen should draw itself.
         /// </summary>
         public abstract void Draw(GameTime gameTime);
 
-
-
-
-
         /// <summary>
         /// Tells the screen to go away. Unlike ScreenManager.RemoveScreen, which
         /// instantly kills the screen, this method respects the transition timings
@@ -302,7 +296,5 @@ namespace NetRumble
                 isExiting = true;
             }
         }
-
-
     }
-}
+}

+ 25 - 23
NetRumble/Core/ScreenManager/InputState.cs

@@ -22,15 +22,20 @@ namespace NetRumble
     /// </remarks>
     public class InputState
     {
-
         public KeyboardState CurrentKeyboardState;
         public GamePadState CurrentGamePadState;
 
         public KeyboardState LastKeyboardState;
         public GamePadState LastGamePadState;
 
-
-
+        /// <summary>
+        /// Helper for checking if a key was newly pressed during this update.
+        /// </summary>
+        public bool IsNewKeyPress(Keys key)
+        {
+            return (CurrentKeyboardState.IsKeyDown(key) &&
+                    LastKeyboardState.IsKeyUp(key));
+        }
 
         /// <summary>
         /// Checks for a "menu up" input action (on either keyboard or gamepad).
@@ -47,7 +52,6 @@ namespace NetRumble
             }
         }
 
-
         /// <summary>
         /// Checks for a "menu down" input action (on either keyboard or gamepad).
         /// </summary>
@@ -63,7 +67,6 @@ namespace NetRumble
             }
         }
 
-
         /// <summary>
         /// Checks for a "menu select" input action (on either keyboard or gamepad).
         /// </summary>
@@ -80,7 +83,6 @@ namespace NetRumble
             }
         }
 
-
         /// <summary>
         /// Checks for a "menu cancel" input action (on either keyboard or gamepad).
         /// </summary>
@@ -96,7 +98,6 @@ namespace NetRumble
             }
         }
 
-
         /// <summary>
         /// Checks for a "pause the game" input action (on either keyboard or gamepad).
         /// </summary>
@@ -112,7 +113,6 @@ namespace NetRumble
             }
         }
 
-
         /// <summary>
         /// Checks for a positive "ship color change" input action
         /// </summary>
@@ -126,7 +126,6 @@ namespace NetRumble
             }
         }
 
-
         /// <summary>
         /// Checks for a negative "ship color change" input action.
         /// </summary>
@@ -140,8 +139,6 @@ namespace NetRumble
             }
         }
 
-
-
         /// <summary>
         /// Checks for a positive "ship model change" input action.
         /// </summary>
@@ -155,7 +152,6 @@ namespace NetRumble
             }
         }
 
-
         /// <summary>
         /// Checks for a negative "ship model change" input action.
         /// </summary>
@@ -169,7 +165,6 @@ namespace NetRumble
             }
         }
 
-
         /// <summary>
         /// Checks for a "mark ready" input action (on either keyboard or gamepad).
         /// </summary>
@@ -183,9 +178,19 @@ namespace NetRumble
             }
         }
 
+        Matrix inputTransformation;
+        readonly float baseBufferWidth;
+        readonly float baseBufferHeight;
 
-
-
+        /// <summary>
+        /// Constructs a new input state.
+        /// </summary>
+        public InputState(float baseBufferWidth, float baseBufferHeight)
+        {
+            this.baseBufferWidth = baseBufferWidth;
+            this.baseBufferHeight = baseBufferHeight;
+            // Initialize the input state with the base buffer dimensions
+        }
 
         /// <summary>
         /// Reads the latest state of the keyboard and gamepad.
@@ -199,16 +204,13 @@ namespace NetRumble
             CurrentGamePadState = GamePad.GetState(PlayerIndex.One);
         }
 
-
         /// <summary>
-        /// Helper for checking if a key was newly pressed during this update.
+        /// Updates the matrix used to transform input coordinates.
         /// </summary>
-        public bool IsNewKeyPress(Keys key)
+        /// <param name="inputTransformation">The transformation matrix to apply.</param>
+        public void UpdateInputTransformation(Matrix inputTransformation)
         {
-            return (CurrentKeyboardState.IsKeyDown(key) &&
-                    LastKeyboardState.IsKeyUp(key));
+            this.inputTransformation = inputTransformation;
         }
-
-
     }
-}
+}

+ 1 - 2
NetRumble/Core/ScreenManager/LoadingScreen.cs

@@ -118,8 +118,7 @@ namespace NetRumble
                 const string message = "Loading...";
 
                 // Center the text in the viewport.
-                Viewport viewport = ScreenManager.GraphicsDevice.Viewport;
-                Vector2 viewportSize = new Vector2(viewport.Width, viewport.Height);
+                Vector2 viewportSize = new Vector2(ScreenManager.BASE_BUFFER_WIDTH, ScreenManager.BASE_BUFFER_HEIGHT);
                 Vector2 textSize = ScreenManager.Font.MeasureString(message);
                 Vector2 textPosition = (viewportSize - textSize) / 2;
 

+ 1 - 2
NetRumble/Core/ScreenManager/MenuScreen.cs

@@ -112,8 +112,7 @@ namespace NetRumble
         /// </summary>
         public override void Draw(GameTime gameTime)
         {
-            Viewport viewport = ScreenManager.GraphicsDevice.Viewport;
-            Vector2 viewportSize = new Vector2(viewport.Width, viewport.Height);
+            Vector2 viewportSize = new Vector2(ScreenManager.BASE_BUFFER_WIDTH, ScreenManager.BASE_BUFFER_HEIGHT);
 
             Vector2 position = new Vector2(0f, viewportSize.Y * 0.65f);
 

+ 1 - 2
NetRumble/Core/ScreenManager/MessageBoxScreen.cs

@@ -113,8 +113,7 @@ namespace NetRumble
             ScreenManager.FadeBackBufferToBlack(TransitionAlpha * 2 / 3);
 
             // Center the message text in the viewport.
-            Viewport viewport = ScreenManager.GraphicsDevice.Viewport;
-            Vector2 viewportSize = new Vector2(viewport.Width, viewport.Height);
+            Vector2 viewportSize = new Vector2(ScreenManager.BASE_BUFFER_WIDTH, ScreenManager.BASE_BUFFER_HEIGHT);
             Vector2 textSize = ScreenManager.Font.MeasureString(message);
             Vector2 textPosition = (viewportSize - textSize) / 2;
             Vector2 usageTextSize = smallFont.MeasureString(usageText);

+ 88 - 19
NetRumble/Core/ScreenManager/ScreenManager.cs

@@ -31,7 +31,8 @@ namespace NetRumble
         List<GameScreen> screensToUpdate = new List<GameScreen>();
         List<GameScreen> screensToDraw = new List<GameScreen>();
 
-        InputState input = new InputState();
+        InputState inputState = new InputState(BASE_BUFFER_WIDTH, BASE_BUFFER_HEIGHT);
+        public InputState InputState => inputState;
 
         IGraphicsDeviceService graphicsDeviceService;
         public SignedInGamer invited;
@@ -44,8 +45,24 @@ namespace NetRumble
 
         bool traceEnabled;
 
+        internal const int BASE_BUFFER_WIDTH = 1280;
+        internal const int BASE_BUFFER_HEIGHT = 720;
 
+        private int backbufferWidth;
+        /// <summary>Gets or sets the current backbuffer width.</summary>
+        public int BackbufferWidth { get => backbufferWidth; set => backbufferWidth = value; }
 
+        private int backbufferHeight;
+        /// <summary>Gets or sets the current backbuffer height.</summary>
+        public int BackbufferHeight { get => backbufferHeight; set => backbufferHeight = value; }
+
+        private Vector2 baseScreenSize = new Vector2(BASE_BUFFER_WIDTH, BASE_BUFFER_HEIGHT);
+        /// <summary>Gets or sets the base screen size used for scaling calculations.</summary>
+        public Vector2 BaseScreenSize { get => baseScreenSize; set => baseScreenSize = value; }
+
+        private Matrix globalTransformation;
+        /// <summary>Gets or sets the global transformation matrix for scaling and positioning.</summary>
+        public Matrix GlobalTransformation { get => globalTransformation; set => globalTransformation = value; }
 
         /// <summary>
         /// Expose access to our Game instance (this is protected in the
@@ -66,7 +83,7 @@ namespace NetRumble
             get { return base.GraphicsDevice; }
         }
 
-        
+
         /// <summary>
         /// A content manager used to load data that is shared between multiple
         /// screens. This is never unloaded, so if a screen requires a large amount
@@ -159,12 +176,10 @@ namespace NetRumble
 
             // update the title-safe area
             titleSafeArea = new Rectangle(
-                (int)Math.Floor(GraphicsDevice.Viewport.X + 
-                   GraphicsDevice.Viewport.Width * 0.05f),
-                (int)Math.Floor(GraphicsDevice.Viewport.Y + 
-                   GraphicsDevice.Viewport.Height * 0.05f), 
-                (int)Math.Floor(GraphicsDevice.Viewport.Width * 0.9f), 
-                (int)Math.Floor(GraphicsDevice.Viewport.Height * 0.9f));
+                (int)Math.Floor(ScreenManager.BASE_BUFFER_WIDTH * 0.05f),
+                (int)Math.Floor(ScreenManager.BASE_BUFFER_HEIGHT * 0.05f),
+                (int)Math.Floor(ScreenManager.BASE_BUFFER_WIDTH * 0.9f),
+                (int)Math.Floor(ScreenManager.BASE_BUFFER_HEIGHT * 0.9f));
         }
 
 
@@ -194,7 +209,7 @@ namespace NetRumble
         public override void Update(GameTime gameTime)
         {
             // Read the keyboard and gamepad.
-            input.Update();
+            inputState.Update();
 
             // Make a copy of the master screen list, to avoid confusion if
             // the process of updating one screen adds or removes others
@@ -225,7 +240,7 @@ namespace NetRumble
                     // give it a chance to handle input and update presence.
                     if (!otherScreenHasFocus)
                     {
-                        screen.HandleInput(input);
+                        screen.HandleInput(inputState);
 
                         screen.UpdatePresence(); // presence support
 
@@ -276,7 +291,7 @@ namespace NetRumble
             {
                 if (screen.ScreenState == ScreenState.Hidden)
                     continue;
-             
+
                 screen.Draw(gameTime);
             }
         }
@@ -289,8 +304,8 @@ namespace NetRumble
         public void DrawRectangle(Rectangle rectangle, Color color)
         {
             //SpriteBatch.Begin();
-			// We changed this to be Opaque
-			spriteBatch.Begin(0,BlendState.Opaque, null, null, null);
+            // We changed this to be Opaque
+            spriteBatch.Begin(0, BlendState.Opaque, null, null, null);
             SpriteBatch.Draw(blankTexture, rectangle, color);
             SpriteBatch.End();
         }
@@ -313,7 +328,7 @@ namespace NetRumble
             {
                 screen.LoadContent();
             }
-            
+
             screens.Add(screen);
         }
 
@@ -332,7 +347,7 @@ namespace NetRumble
             {
                 screen.UnloadContent();
             }
-            
+
             screens.Remove(screen);
             screensToUpdate.Remove(screen);
         }
@@ -355,17 +370,71 @@ namespace NetRumble
         /// </summary>
         public void FadeBackBufferToBlack(int alpha)
         {
-            Viewport viewport = GraphicsDevice.Viewport;
-
             spriteBatch.Begin();
 
             spriteBatch.Draw(blankTexture,
-                             new Rectangle(0, 0, viewport.Width, viewport.Height),
+                             new Rectangle(0, 0, BASE_BUFFER_WIDTH, BASE_BUFFER_HEIGHT),
                              new Color((byte)0, (byte)0, (byte)0, (byte)alpha));
-            
+
             spriteBatch.End();
         }
+        
+        /// <summary>
+        /// Scales the game presentation area to match the screen's aspect ratio.
+        /// </summary>
+        public void ScalePresentationArea()
+        {
+            // Validate parameters before calculation
+            if (GraphicsDevice == null || baseScreenSize.X <= 0 || baseScreenSize.Y <= 0)
+            {
+                throw new InvalidOperationException("Invalid graphics configuration");
+            }
 
+            // Fetch screen dimensions
+            backbufferWidth = GraphicsDevice.PresentationParameters.BackBufferWidth;
+            backbufferHeight = GraphicsDevice.PresentationParameters.BackBufferHeight;
 
+            // Prevent division by zero
+            if (backbufferHeight == 0 || baseScreenSize.Y == 0)
+            {
+                return;
+            }
+
+            // Calculate aspect ratios
+            float baseAspectRatio = baseScreenSize.X / baseScreenSize.Y;
+            float screenAspectRatio = backbufferWidth / (float)backbufferHeight;
+
+            // Determine uniform scaling factor
+            float scalingFactor;
+            float horizontalOffset = 0;
+            float verticalOffset = 0;
+
+            if (screenAspectRatio > baseAspectRatio)
+            {
+                // Wider screen: scale by height
+                scalingFactor = backbufferHeight / baseScreenSize.Y;
+
+                // Centre things horizontally.
+                horizontalOffset = (backbufferWidth - baseScreenSize.X * scalingFactor) / 2;
+            }
+            else
+            {
+                // Taller screen: scale by width
+                scalingFactor = backbufferWidth / baseScreenSize.X;
+
+                // Centre things vertically.
+                verticalOffset = (backbufferHeight - baseScreenSize.Y * scalingFactor) / 2;
+            }
+
+            // Update the transformation matrix
+            globalTransformation = Matrix.CreateScale(scalingFactor) *
+                                   Matrix.CreateTranslation(horizontalOffset, verticalOffset, 0);
+
+            // Update the inputTransformation with the Inverted globalTransformation
+            inputState.UpdateInputTransformation(Matrix.Invert(globalTransformation));
+
+            // Debug info
+            Debug.WriteLine($"Screen Size - Width[{backbufferWidth}] Height[{backbufferHeight}] ScalingFactor[{scalingFactor}]");
+        }
     }
 }

+ 18 - 22
NetRumble/Core/Screens/GameplayScreen.cs

@@ -130,11 +130,11 @@ namespace NetRumble
         public override void LoadContent()
         {
             // create and add the bloom effect
-            bloomComponent = new BloomComponent(ScreenManager.Game);
+            /* TODO bloomComponent = new BloomComponent(ScreenManager.Game);
             bloomComponent.Settings = BloomSettings.PresetSettings[0];
             ScreenManager.Game.Components.Add(bloomComponent);
             bloomComponent.Initialize();
-            bloomComponent.Visible = false; // we want to control when bloom component is drawn
+            bloomComponent.Visible = false; // we want to control when bloom component is drawn*/
 
             // create the starfield
             starfield = new Starfield(Vector2.Zero, ScreenManager.GraphicsDevice,
@@ -213,11 +213,9 @@ namespace NetRumble
                         Vector2 winnerStringSize =
                             world.PlayerFont.MeasureString(winnerString);
                         winnerStringPosition = new Vector2(
-                            ScreenManager.GraphicsDevice.Viewport.X +
-                                ScreenManager.GraphicsDevice.Viewport.Width / 2 -
+                                ScreenManager.BASE_BUFFER_WIDTH / 2 -
                                 (float)Math.Floor(winnerStringSize.X / 2),
-                            ScreenManager.GraphicsDevice.Viewport.Y +
-                                ScreenManager.GraphicsDevice.Viewport.Height / 2 -
+                            ScreenManager.BASE_BUFFER_HEIGHT / 2 -
                                 (float)Math.Floor(winnerStringSize.Y / 2));
                     }
                 }
@@ -368,10 +366,8 @@ namespace NetRumble
                 if ((world != null) && (localShip != null) && !IsExiting)
                 {
                     Vector2 center = new Vector2(
-                        localShip.Position.X + ScreenManager.GraphicsDevice.Viewport.X -
-                           ScreenManager.GraphicsDevice.Viewport.Width / 2,
-                        localShip.Position.Y + ScreenManager.GraphicsDevice.Viewport.Y -
-                           ScreenManager.GraphicsDevice.Viewport.Height / 2);
+                        localShip.Position.X + ScreenManager.BASE_BUFFER_WIDTH / 2,
+                        localShip.Position.Y + ScreenManager.BASE_BUFFER_HEIGHT / 2);
                     starfield.Draw(center);
                     world.Draw(elapsedTime, center);
 
@@ -401,43 +397,43 @@ namespace NetRumble
                 ScreenManager.SpriteBatch.Begin();
                 // draw players 0 - 3 at the top of the screen
                 Vector2 position = new Vector2(
-                    ScreenManager.GraphicsDevice.Viewport.Width * 0.2f,
-                    ScreenManager.GraphicsDevice.Viewport.Height * 0.1f);
+                    ScreenManager.BASE_BUFFER_WIDTH * 0.2f,
+                    ScreenManager.BASE_BUFFER_HEIGHT * 0.1f);
                 for (int i = 0; i < Math.Min(4, networkSession.AllGamers.Count); i++)
                 {
                     world.DrawPlayerData(totalTime, networkSession.AllGamers[i],
                         position, ScreenManager.SpriteBatch, false);
-                    position.X += ScreenManager.GraphicsDevice.Viewport.Width * 0.2f;
+                    position.X += ScreenManager.BASE_BUFFER_WIDTH * 0.2f;
                 }
                 // draw players 4 - 7 at the bottom of the screen
                 position = new Vector2(
-                    ScreenManager.GraphicsDevice.Viewport.Width * 0.2f,
-                    ScreenManager.GraphicsDevice.Viewport.Height * 0.9f);
+                    ScreenManager.BASE_BUFFER_WIDTH * 0.2f,
+                    ScreenManager.BASE_BUFFER_HEIGHT * 0.9f);
                 for (int i = 4; i < Math.Min(8, networkSession.AllGamers.Count); i++)
                 {
                     world.DrawPlayerData(totalTime, networkSession.AllGamers[i],
                         position, ScreenManager.SpriteBatch, false);
-                    position.X += ScreenManager.GraphicsDevice.Viewport.Width * 0.2f;
+                    position.X += ScreenManager.BASE_BUFFER_WIDTH * 0.2f;
                 }
                 // draw players 8 - 11 at the left of the screen
                 position = new Vector2(
-                    ScreenManager.GraphicsDevice.Viewport.Width * 0.13f,
-                    ScreenManager.GraphicsDevice.Viewport.Height * 0.2f);
+                    ScreenManager.BASE_BUFFER_WIDTH * 0.13f,
+                    ScreenManager.BASE_BUFFER_HEIGHT * 0.2f);
                 for (int i = 8; i < Math.Min(12, networkSession.AllGamers.Count); i++)
                 {
                     world.DrawPlayerData(totalTime, networkSession.AllGamers[i],
                         position, ScreenManager.SpriteBatch, false);
-                    position.Y += ScreenManager.GraphicsDevice.Viewport.Height * 0.2f;
+                    position.Y += ScreenManager.BASE_BUFFER_HEIGHT * 0.2f;
                 }
                 // draw players 12 - 15 at the right of the screen
                 position = new Vector2(
-                    ScreenManager.GraphicsDevice.Viewport.Width * 0.9f,
-                    ScreenManager.GraphicsDevice.Viewport.Height * 0.2f);
+                    ScreenManager.BASE_BUFFER_WIDTH * 0.9f,
+                    ScreenManager.BASE_BUFFER_HEIGHT * 0.2f);
                 for (int i = 12; i < Math.Min(16, networkSession.AllGamers.Count); i++)
                 {
                     world.DrawPlayerData(totalTime, networkSession.AllGamers[i],
                         position, ScreenManager.SpriteBatch, false);
-                    position.Y += ScreenManager.GraphicsDevice.Viewport.Height * 0.2f;
+                    position.Y += ScreenManager.BASE_BUFFER_HEIGHT * 0.2f;
                 }
                 // if the game is over, draw the winner text
                 if (world.GameWon && !String.IsNullOrEmpty(winnerString))

+ 29 - 77
NetRumble/Core/Screens/LobbyScreen.cs

@@ -18,29 +18,17 @@ namespace NetRumble
     /// </summary>
     public class LobbyScreen : MenuScreen, IDisposable
     {
-
-
         /// <summary>
         /// The instructions shown to the player at the bottom of the lobby screen.
         /// </summary>
-        const string instructions = 
+        const string instructions =
             "Press X to mark/unmark ready, LB/RB to toggle color, LT/RT to toggle ship";
 
-
-
-
-
-
         /// <summary>
         /// The primary object for this game.
         /// </summary>
         private World world;
 
-
-
-
-
-
         /// <summary>
         /// The network session for this game.
         /// </summary>
@@ -50,7 +38,7 @@ namespace NetRumble
         /// The packet writer used to send data from this screen.
         /// </summary>
         private PacketWriter packetWriter = new PacketWriter();
-        
+
         /// <summary>
         /// Event handler for the session-ended event.
         /// </summary>
@@ -66,11 +54,6 @@ namespace NetRumble
         /// </summary>
         EventHandler<GamerJoinedEventArgs> gamerJoinedHandler;
 
-
-
-
-
-
         /// <summary>
         /// Constructs a new LobbyScreen object.
         /// </summary>
@@ -100,7 +83,6 @@ namespace NetRumble
                 networkSession_SessionEnded);
         }
 
-
         /// <summary>
         /// Load graphics content for the game.
         /// </summary>
@@ -109,7 +91,7 @@ namespace NetRumble
             base.LoadContent();
 
             // create the world object
-            world = new World(ScreenManager.GraphicsDevice, ScreenManager.Content, 
+            world = new World(ScreenManager.GraphicsDevice, ScreenManager.Content,
                 networkSession);
 
             // set the networking events
@@ -118,11 +100,6 @@ namespace NetRumble
             networkSession.SessionEnded += sessionEndedHandler;
         }
 
-
-
-
-
-
         /// <summary>
         /// Updates the lobby. This method checks the GameScreen.IsActive
         /// property, so the game will stop updating when the pause menu is active,
@@ -201,7 +178,7 @@ namespace NetRumble
             // update the menu entry text
             if (otherScreenHasFocus == false)
             {
-                if ((networkSession.LocalGamers.Count > 0) && 
+                if ((networkSession.LocalGamers.Count > 0) &&
                     (networkSession.SessionState == NetworkSessionState.Lobby))
                 {
                     if (!networkSession.LocalGamers[0].IsReady)
@@ -227,10 +204,10 @@ namespace NetRumble
                     MenuEntries[0] = "Game starting...";
                 }
                 // if the game is playing and the world is initialized, then start up
-                if ((networkSession.SessionState == NetworkSessionState.Playing) && 
+                if ((networkSession.SessionState == NetworkSessionState.Playing) &&
                     (world != null) && world.Initialized)
                 {
-                    GameplayScreen gameplayScreen = 
+                    GameplayScreen gameplayScreen =
                         new GameplayScreen(networkSession, world);
                     gameplayScreen.ScreenManager = this.ScreenManager;
                     ScreenManager.AddScreen(gameplayScreen);
@@ -240,7 +217,6 @@ namespace NetRumble
             base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
         }
 
-
         /// <summary>
         /// Lets the game respond to player input. Unlike the Update method,
         /// this will only be called when the gameplay screen is active.
@@ -258,7 +234,7 @@ namespace NetRumble
                 // update the ready state
                 if (input.MarkReady)
                 {
-                    networkSession.LocalGamers[0].IsReady = 
+                    networkSession.LocalGamers[0].IsReady =
                         !networkSession.LocalGamers[0].IsReady;
                 }
 
@@ -281,7 +257,7 @@ namespace NetRumble
                     }
                     if (input.ShipModelChangeUp)
                     {
-                        playerData.ShipVariation = 
+                        playerData.ShipVariation =
                             (byte)((playerData.ShipVariation + 1) % 4);
                         playerDataChanged = true;
                     }
@@ -302,7 +278,8 @@ namespace NetRumble
                     {
                         packetWriter.Write((int)World.PacketTypes.PlayerData);
                         playerData.Serialize(packetWriter);
-                        networkSession.LocalGamers[0].SendData(packetWriter, 
+
+                        networkSession.LocalGamers[0].SendData(packetWriter,
                             SendDataOptions.ReliableInOrder);
                     }
                 }
@@ -311,13 +288,11 @@ namespace NetRumble
             base.HandleInput(input);
         }
 
-
         /// <summary>
         /// Responds to user menu selections.
         /// </summary>
         protected override void OnSelectEntry(int entryIndex) { }
 
-
         /// <summary>
         /// Force the end of a network session so that a new one can be joined.
         /// </summary>
@@ -330,7 +305,6 @@ namespace NetRumble
             }
         }
 
-
         /// <summary>
         /// Exit this screen.
         /// </summary>
@@ -345,7 +319,6 @@ namespace NetRumble
             base.ExitScreen();
         }
 
-
         /// <summary>
         /// Screen-specific update to gamer rich presence.
         /// </summary>
@@ -371,10 +344,6 @@ namespace NetRumble
             }
         }
 
-
-
-
-
         /// <summary>
         /// Draw the lobby screen.
         /// </summary>
@@ -384,17 +353,17 @@ namespace NetRumble
             // draw in four columns
             Vector2[] columnPositions = new Vector2[4];
             columnPositions[0] = new Vector2(
-                ScreenManager.GraphicsDevice.Viewport.Width * 0.2f, 
-                ScreenManager.GraphicsDevice.Viewport.Height * 0.70f);
+                ScreenManager.BASE_BUFFER_WIDTH * 0.2f,
+                ScreenManager.BASE_BUFFER_HEIGHT * 0.70f);
             columnPositions[1] = new Vector2(
-                ScreenManager.GraphicsDevice.Viewport.Width * 0.4f, 
-                ScreenManager.GraphicsDevice.Viewport.Height * 0.70f);
+                ScreenManager.BASE_BUFFER_WIDTH * 0.4f,
+                ScreenManager.BASE_BUFFER_HEIGHT * 0.70f);
             columnPositions[2] = new Vector2(
-                ScreenManager.GraphicsDevice.Viewport.Width * 0.6f,
-                ScreenManager.GraphicsDevice.Viewport.Height * 0.70f);
+                ScreenManager.BASE_BUFFER_WIDTH * 0.6f,
+                ScreenManager.BASE_BUFFER_HEIGHT * 0.70f);
             columnPositions[3] = new Vector2(
-                ScreenManager.GraphicsDevice.Viewport.Width * 0.8f, 
-                ScreenManager.GraphicsDevice.Viewport.Height * 0.70f);
+                ScreenManager.BASE_BUFFER_WIDTH * 0.8f,
+                ScreenManager.BASE_BUFFER_HEIGHT * 0.70f);
 
             ScreenManager.SpriteBatch.Begin();
 
@@ -403,18 +372,18 @@ namespace NetRumble
             {
                 for (int i = 0; i < networkSession.AllGamers.Count; i++)
                 {
-                    world.DrawPlayerData((float)gameTime.TotalGameTime.TotalSeconds, 
-                        networkSession.AllGamers[i], columnPositions[i % 4], 
+                    world.DrawPlayerData((float)gameTime.TotalGameTime.TotalSeconds,
+                        networkSession.AllGamers[i], columnPositions[i % 4],
                         ScreenManager.SpriteBatch, true);
-                    columnPositions[i % 4].Y += 
-                        ScreenManager.GraphicsDevice.Viewport.Height * 0.03f;
+                    columnPositions[i % 4].Y +=
+                        ScreenManager.BASE_BUFFER_HEIGHT * 0.03f;
                 }
             }
 
             // draw the instructions
-            ScreenManager.SpriteBatch.DrawString(ScreenManager.Font, instructions, 
-                new Vector2(ScreenManager.TitleSafeArea.X, 
-                ScreenManager.TitleSafeArea.Y + ScreenManager.TitleSafeArea.Height - 
+            ScreenManager.SpriteBatch.DrawString(ScreenManager.Font, instructions,
+                new Vector2(ScreenManager.TitleSafeArea.X,
+                ScreenManager.TitleSafeArea.Y + ScreenManager.TitleSafeArea.Height -
                 ScreenManager.Font.LineSpacing), Color.White);
 
             ScreenManager.SpriteBatch.End();
@@ -422,8 +391,6 @@ namespace NetRumble
             base.Draw(gameTime);
         }
 
-
-
         /// <summary>
         /// When the user cancels the main menu, ask if they want to exit the sample.
         /// </summary>
@@ -445,11 +412,6 @@ namespace NetRumble
             }
         }
 
-
-
-
-
-
         /// <summary>
         /// Handle the end of the network session.
         /// </summary>
@@ -471,7 +433,6 @@ namespace NetRumble
             }
         }
 
-
         /// <summary>
         /// Handle the start of the game session.
         /// </summary>
@@ -483,8 +444,7 @@ namespace NetRumble
                 world.GenerateWorld();
             }
         }
-        
-        
+
         /// <summary>
         /// Handle a new player joining the session.
         /// </summary>
@@ -510,17 +470,13 @@ namespace NetRumble
                 {
                     packetWriter.Write((int)World.PacketTypes.PlayerData);
                     playerData.Serialize(packetWriter);
-                    networkSession.LocalGamers[0].SendData(packetWriter, 
+
+                    networkSession.LocalGamers[0].SendData(packetWriter,
                         SendDataOptions.ReliableInOrder, e.Gamer);
                 }
             }
         }
 
-
-
-    
-
-
         /// <summary>
         /// Finalizes the LobbyScreen object, calls Dispose(false)
         /// </summary>
@@ -529,7 +485,6 @@ namespace NetRumble
             Dispose(false);
         }
 
-
         /// <summary>
         /// Disposes the LobbyScreen object.
         /// </summary>
@@ -539,7 +494,6 @@ namespace NetRumble
             GC.SuppressFinalize(this);
         }
 
-        
         /// <summary>
         /// Disposes this object.
         /// </summary>
@@ -565,7 +519,5 @@ namespace NetRumble
                 }
             }
         }
-
-
     }
-}
+}

+ 4 - 7
NetRumble/Core/Screens/MainMenuScreen.cs

@@ -157,11 +157,11 @@ namespace NetRumble
                                 QuickMatchSession();
                                 break;
 
-                            case 1: // Create Xbox LIVE Session
+                            case 1: // Create Internet Session
                                 CreateSession(NetworkSessionType.PlayerMatch);
                                 break;
 
-                            case 2: // Join Xbox LIVE Session
+                            case 2: // Join Internet Session
                                 FindSession(NetworkSessionType.PlayerMatch);
                                 break;
 
@@ -378,11 +378,8 @@ namespace NetRumble
         /// <param name="sessionType">The type of session to look for.</param>
         void FindSession(NetworkSessionType sessionType)
         {
-            // create the new screen
-            SearchResultsScreen searchResultsScreen =
-               new SearchResultsScreen(sessionType);
-            searchResultsScreen.ScreenManager = this.ScreenManager;
-            ScreenManager.AddScreen(searchResultsScreen);
+            // create the Search screen
+            ScreenManager.AddScreen(new SearchResultsScreen(sessionType));
         }
 
         /// <summary>

+ 1 - 2
NetRumble/Core/Screens/NetworkBusyScreen.cs

@@ -104,8 +104,7 @@ namespace NetRumble
             const int vPad = 16;
 
             // Center the message text in the viewport.
-            Viewport viewport = ScreenManager.GraphicsDevice.Viewport;
-            Vector2 viewportSize = new Vector2(viewport.Width, viewport.Height);
+            Vector2 viewportSize = new Vector2(ScreenManager.BASE_BUFFER_WIDTH, ScreenManager.BASE_BUFFER_HEIGHT);
             Vector2 textSize = font.MeasureString(message);
 
             // Add enough room to spin a texture.

+ 10 - 40
NetRumble/Core/Screens/SearchResultsScreen.cs

@@ -19,34 +19,21 @@ namespace NetRumble
     /// </summary>
     public class SearchResultsScreen : MenuScreen
     {
-
-
         /// <summary>
         /// The maximum number of session results to display.
         /// </summary>
         const int maximumSessions = 8;
 
-
-
-
-
-
         /// <summary>
         /// The type of networking session that was requested.
         /// </summary>
         private NetworkSessionType sessionType;
 
-
         /// <summary>
         /// The collection of search results.
         /// </summary>
         private AvailableNetworkSessionCollection availableSessions = null;
 
-
-
-
-
-
         /// <summary>
         /// Constructor fills in the menu contents.
         /// </summary>
@@ -59,6 +46,11 @@ namespace NetRumble
             // set the transition times
             TransitionOnTime = TimeSpan.FromSeconds(1.0);
             TransitionOffTime = TimeSpan.FromSeconds(0.0);
+        }
+
+        public override void LoadContent()
+        {
+            base.LoadContent();
 
             // Start async session search immediately
             try
@@ -86,11 +78,6 @@ namespace NetRumble
             }
         }
 
-
-
-
-
-
         /// <summary>
         /// Updates the screen. This method checks the GameScreen.IsActive
         /// property, so the game will stop updating when the pause menu is active,
@@ -130,13 +117,12 @@ namespace NetRumble
             base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
         }
 
-
         /// <summary>
         /// Responds to user menu selections.
         /// </summary>
         protected override void OnSelectEntry(int entryIndex)
         {
-            if ((availableSessions != null) && (entryIndex >= 0) && 
+            if ((availableSessions != null) && (entryIndex >= 0) &&
                 (entryIndex < availableSessions.Count))
             {
                 try
@@ -161,7 +147,6 @@ namespace NetRumble
             }
         }
 
-
         /// <summary>
         /// When the user cancels the screen.
         /// </summary>
@@ -173,11 +158,6 @@ namespace NetRumble
             }
         }
 
-
-
-
-
-
         /// <summary>
         /// Draw the screen.
         /// </summary>
@@ -201,8 +181,7 @@ namespace NetRumble
             }
             else
             {
-                Viewport viewport = ScreenManager.GraphicsDevice.Viewport;
-                Vector2 viewportSize = new Vector2(viewport.Width, viewport.Height);
+                Vector2 viewportSize = new Vector2(ScreenManager.BASE_BUFFER_WIDTH, ScreenManager.BASE_BUFFER_HEIGHT);
 
                 Vector2 position = new Vector2(0f, viewportSize.Y * 0.65f);
 
@@ -222,8 +201,8 @@ namespace NetRumble
                 Vector2 origin = new Vector2(0, ScreenManager.Font.LineSpacing / 2);
                 Vector2 size = ScreenManager.Font.MeasureString(alternateString);
                 position.X = viewportSize.X / 2f - size.X / 2f;
-                ScreenManager.SpriteBatch.DrawString(ScreenManager.Font, 
-                                                     alternateString, position, 
+                ScreenManager.SpriteBatch.DrawString(ScreenManager.Font,
+                                                     alternateString, position,
                                                      Color.White, 0, origin, 1.0f,
                                                      SpriteEffects.None, 0);
 
@@ -231,11 +210,6 @@ namespace NetRumble
             }
         }
 
-
-
-
-
-
         /// <summary>
         /// Callback to receive the network-session search results (async/await style).
         /// </summary>
@@ -273,7 +247,6 @@ namespace NetRumble
             }
         }
 
-
         /// <summary>
         /// Callback to load the lobby screen with the new session.
         /// </summary>
@@ -298,7 +271,6 @@ namespace NetRumble
             ScreenManager.AddScreen(lobbyScreen);
         }
 
-
         /// <summary>
         /// Event handler for when the user selects ok on the "are you sure
         /// you want to exit" message box.
@@ -307,7 +279,5 @@ namespace NetRumble
         {
             ExitScreen();
         }
-
-
     }
-}
+}

+ 1 - 1
NetRumble/Platforms/Desktop/Program.cs

@@ -11,4 +11,4 @@ namespace NetRumble.DesktopGL
                 game.Run();
         }
     }
-}
+}