XNA 4.0 / Windows Phone 7 Port Status

Developer
Mar 22, 2010 at 3:21 AM
Edited Mar 22, 2010 at 11:22 AM

I have a fully working version of Farseer Physics 2.1.3 with Simple Samples and Advanced Samples running using XNA 4.0 and on Windows Phone 7 Emulator.

Download

NOTES-

  • XNA 4.0 seems to be very picky about Content Projects. It seems you must have only one Content project for the Phone applications or they simply won't deploy. Also Content References don't seem to work. I can get everything to reference a single Content Project, but then I can't get it to build. This is why all the Projects are split into their own Solutions.
  • When you create your own Project you must add "XNA" to the Conditional compilation symbols in the Build tab of the projects Properties. If you don't do this you will get like 600 errors. Make sure you do this for both Debug and Release Configurations.
  • The phone only runs at 30 fps. Farseer is designed to run at 100 fps. I have not looked into this yet, but it makes it seem like slow motion to me a little.
  • In all the SpriteBatch code the default is AlphaBlend using premultiplied values. To achieve the same visual results as the XNA 3.1 version I had to change this to NonPremultiplied. Just keep this in mind.
  • I haven't updated the input code to support touch based input. Click the emulator to focus it and then use the keyboard.
  • DebugView works but must be manually turned on until the input code is updated as the emulator overrides F1.
  • Escape doesn't Pause. It quits the app because the emulator overrides Esc. Just click the Back button and run the app again to start a new Demo.
  • If you want to use StopWatch in your own Project for the phone include Microsoft.Devices.Dll. Make sure you choose the XNA version for XNA. (check the path)
  • THIS IS AN UNSUPPORTED RELEASE - DON'T EXPECT ANY REGULAR UPDATES OR TWEAKS. Use the your brains to tweak the demos to fit the screen.
  • POST ANY PROBLEMS TO THIS THREAD.
Mar 22, 2010 at 6:51 PM
Edited Mar 22, 2010 at 6:57 PM

I don't know if this will help but I agree the new Content project setup in VS 2010 has been mind numbingly difficult and I still don't entirely know what's going on.

I started a thread over at the Creator's Club XNA website regarding the Content sharing issues.  There are several replies from a few of the MS XNA employees.

http://forums.xna.com/forums/t/49984.aspx

He indicates that nothing has changed from XNA 2.0 to 4.0 in regards to Content but he did lead me down a path that helped me at least.

I wanted to allow for seperate content folders since Phone graphics will have to be very different from Windows and 360 graphics.  But I also wanted to have a shared folder.  Since I could never figure out how to have both shared and exclusive, I finally just decided to go with exclusive Content projects to the Phone and Windows/360.

This required that I have a Conditional compiler check for my Root Content Directory.  I had assumed that by adding a reference of the Content Project to a given Project that would direct that project towards that content project.  As far as I can tell it doesn't do anything.  I had to set the following code in my main game1.cs in order to direct a given project to use a given content project's content.  By default in Game1.cs with a blank game template the Root Directoy is set to "Content" in the Game1.cs constructor.  This command seems to take precedence over anything you do with Content Project references if you are sharing code between projects.

Thanks for doing this and here is the code I use to alter the Content Root Directory depending on the project being executed.

#if WINDOWS || XBOX
            Content.RootDirectory = "WindowsXboxContent";
#else
            Content.RootDirectory = "Content";
#endif

 

 

 

 

Mar 23, 2010 at 2:54 AM

Matt,

I noticed that when you load the Simple and Advanced Demo solutions for both phone and Windows, there is no SweepAndPruneCollider.cs class in the Farseer collisions folder.

Yet SweepAndPruneCollider.cs does exist in the collision folders of FarseerPhysics_XNA_4.0 and FarseerPhysics_XNA_4.0_Phone. 

I only noted this because when I tried to add the FarseerPhysics.csproj it came over with the SweepAndPruneCollider.cs class and I had errors related to the RemoveAll commands in that class.  For some reason, that class was not recognizing the extension method you added which worked for SelectiveSweepCollider.cs. 

Is the SweepAndPruneCollider class not needed?

Allan

 

Developer
Mar 23, 2010 at 3:46 PM

@chaneya: I haven't finished that class yet. Once the final release of XNA 4.0 is released we will release an official upgrade to Farseer 2.1.3. I will try to finish the SweepAndPruneCollider before then but it is not necessary. In fact I think I would recommend the SpatialHashCollider under almost all circumstances.

Apr 2, 2010 at 10:35 PM
Edited Apr 2, 2010 at 10:59 PM

Ive been working on converting the demos to use the touch input code. Here is my inputstate class conversion. Sorry if its sloppy.

http://www.youtube.com/watch?v=IHfv-j_YVes

Basically when you press the top of the screen it is the menu up, or ive been using it to replace the W key, the bottom is the menu down and S key, etc.

    public class InputState
    {
        TouchCollection currentTouchCollection;
        TouchCollection lastTouchCollection;

        /// <summary>
        /// Checks for a "menu up" input action (on either keyboard or gamepad).
        /// </summary>
        public bool MenuUp { get; set; }

        /// <summary>
        /// Checks for a "menu down" input action (on either keyboard or gamepad).
        /// </summary>
        public bool MenuDown { get; set; }

        /// <summary>
        /// Checks for a "menu select" input action (on either keyboard or gamepad).
        /// </summary>
        public bool MenuSelect { get; set; }

        /// <summary>
        /// Checks for a "menu cancel" input action (on either keyboard or gamepad).
        /// </summary>
        public bool MenuCancel { get; set; }


        /// <summary>
        /// Checks for a "pause the game" input action (on either keyboard or gamepad).
        /// </summary>
        public bool PauseGame { get; set; }

        /// <summary>
        /// Reads the latest state of the keyboard and gamepad.
        /// </summary>
        public void Update()
        {
            if (MenuUp)
                MenuUp = false;
            if (MenuDown)
                MenuDown = false;
            if (MenuSelect)
                MenuSelect = false;

            lastTouchCollection = currentTouchCollection;
            currentTouchCollection = TouchPanel.GetState();

            if (IsNewTouchTopPress())
                MenuUp = true;
            if (IsNewTouchBottomPress())
                MenuDown = true;

            if (IsNewTouchPress())
            {
                if (currentTouchCollection[0].Position.Y > 200 && currentTouchCollection[0].Position.Y < 600)
                {
                    MenuSelect = true;
                }
            }
            else
            {
                MenuUp = false;
            }
        }

        public bool IsNewTouchPress()
        {
            bool result = false;

            foreach (TouchLocation location in currentTouchCollection)
            {
                if (lastTouchCollection.Contains(location))
                {
                    if (lastTouchCollection[lastTouchCollection.IndexOf(location)].State == TouchLocationState.Released && location.State == TouchLocationState.Pressed)
                    {
                        result = true;
                    }
                }
                else
                {
                    if (location.State == TouchLocationState.Pressed)
                        result = true;
                    else
                        result = false;
                }
            }

            return result;
        }

        public bool IsNewTouchTopPress()
        {
            bool result = false;

            foreach (TouchLocation location in currentTouchCollection)
            {
                if (lastTouchCollection.Contains(location))
                {
                    if (lastTouchCollection[lastTouchCollection.IndexOf(location)].State == TouchLocationState.Released && location.State == TouchLocationState.Pressed)
                    {
                        if (location.Position.Y < 200)
                            result = true;
                        else
                            result = false;
                    }
                }
                else
                {
                    if (location.State == TouchLocationState.Pressed)
                        if (location.Position.Y < 200)
                            result = true;
                        else
                            result = false;
                    else
                        result = false;
                }
            }

            return result;
        }

        public bool IsNewTouchBottomPress()
        {
            bool result = false;

            foreach (TouchLocation location in currentTouchCollection)
            {
                if (lastTouchCollection.Contains(location))
                {
                    if (lastTouchCollection[lastTouchCollection.IndexOf(location)].State == TouchLocationState.Released && location.State == TouchLocationState.Pressed)
                    {
                        if (location.Position.Y > 600)
                            result = true;
                        else
                            result = false;
                    }
                }
                else
                {
                    if (location.State == TouchLocationState.Pressed)
                        if (location.Position.Y > 600)
                            result = true;
                        else
                            result = false;
                    else
                        result = false;
                }
            }

            return result;
        }

        public bool IsTouchTopPress()
        {
            bool result = false;

            foreach (TouchLocation location in currentTouchCollection)
            {
                if (location.State == TouchLocationState.Pressed)
                {
                    if (location.Position.Y < 200)
                        result = true;
                }
            }

            return result;
        }

        public bool IsTouchBottomPress()
        {
            bool result = false;

            foreach (TouchLocation location in currentTouchCollection)
            {
                if (location.State == TouchLocationState.Pressed)
                {
                    if (location.Position.Y > 600)
                        result = true;
                }
            }

            return result;
        }

        public bool IsTouchLeftPress()
        {
            bool result = false;

            foreach (TouchLocation location in currentTouchCollection)
            {
                if (location.State == TouchLocationState.Pressed)
                {
                    if (location.Position.X < 100)
                        result = true;
                }
            }

            return result;
        }

        public bool IsTouchRightPress()
        {
            bool result = false;

            foreach (TouchLocation location in currentTouchCollection)
            {
                if (location.State == TouchLocationState.Pressed)
                {
                    if (location.Position.X > 300)
                        result = true;
                }
            }

            return result;
        }
    }
Apr 27, 2010 at 3:58 AM

The phone can run faster than 30fps.  It is the display that will not go faster than 30fps.  If you set the Game.TargetElapsedTime to TimeSpan.FromSeconds(1.0f / 100.0f) and Game.IsFixedFrameRate to true.  This will run the update at 100fps and the draw will remain at 30.  Not the ideal solution (probably better off getting Farseer to run normally at 60 and do two updates per draw) but it will get you further.

I'm new to Farseer and I got the library running in XNA 4.0 by simply editing the XnaFramework version number in the .csproj and loading it through the Project Upgrade Wizard in VS2010.  I'm running it as a Windows project (phone emulator doesn't run on my home machine), but I'm having troubles getting any collisions to happen.  I've added bodies, geoms and nothing is colliding with each other.  I'll do some more testing to see if it was the upgrade that broke something.

chaneya, you can have shared content between multiple content projects by adding files as a link (click the drop-down arrow on the Add button in the Add File dialog box).  This is what I have done for a project that is required to support XNA 3.1 and XNA 4.0.

Jun 29, 2010 at 5:18 AM
Hi mattbettcher, do you have any objections if your code is used for non-commercial or commercial purposes? We would like to use your code but it is not distributed under the official downloads and therefore does not have a defined license.
Developer
Jun 29, 2010 at 3:23 PM
The Windows Phone 7 part of the code is public domain. The Farseer part falls under it's own license. So feel free to use it!
Oct 6, 2010 at 2:39 PM
Edited Nov 17, 2010 at 2:10 PM

Ive been working on converting the demos to use the touch input code. Here is my inputstate class conversion. Sorry if its sloppy.

http://www.youtube.com/watch?v=IHfv-j_YVesvoip  Long Distance

Basically when you press the top of the screen it is the menu up, or ive been using it to replace the W key, the bottom is the menu down and S key, etc.

_____________________________________________________________________

 

Cool job...I'm starting my class soon so this is helpful!

 

Nov 11, 2010 at 3:29 PM
mattbettcher wrote:

I have a fully working version of Farseer Physics 2.1.3 with Simple Samples and Advanced Samples running using XNA 4.0 and on Windows Phone 7 Emulator.

Download

NOTES-

  • XNA 4.0 seems to be very picky about Content Projects. It seems you must have only one Content project for the Phone applications or they simply won't deploy. Also Content References don't seem to work. I can get everything to reference a single Content Project, but then I can't get it to build. This is why all the Projects are split into their own Solutions.
  • When you create your own Project you must add "XNA" to the Conditional compilation symbols in the Build tab of the projects Properties. If you don't do this you will get like 600 errors. Make sure you do this for both Debug and Release Configurations.
  • The phone only runs at 30 fps. Farseer is designed to run at 100 fps. I have not looked into this yet, but it makes it seem like slow motion to me a little.
  • In all the SpriteBatch code the default is AlphaBlend using premultiplied values. To achieve the same visual results as the XNA 3.1 version I had to change this to NonPremultiplied. Just keep this in mind.
  • I haven't updated the input code to support touch based input. Click the emulator to focus it and then use the keyboard.
  • DebugView works but must be manually turned on until the input code is updated as the emulator overrides F1.
  • Escape doesn't Pause. It quits the app because the emulator overrides Esc. Just click the Back button and run the app again to start a new Demo.
  • If you want to use StopWatch in your own Project for the phone include Microsoft.Devices.Dll. Make sure you choose the XNA version for XNA. (check the path)
  • THIS IS AN UNSUPPORTED RELEASE - DON'T EXPECT ANY REGULAR UPDATES OR TWEAKS. Use the your brains to tweak the demos to fit the screen.
  • POST ANY PROBLEMS TO THIS THREAD.

 Matt,

How does the DemoBasePhone project know to access SimpleSamplesPhoneContent(Content) for it's content?  It's not a reference.  Where is that information provided.

I have this all running in the Windows phone emulator in VS2010 except DemoBasePhone can't access the fonts it needs.
I keep getting file not found on the fonts once I copied everything over to my own project.  If I comment out font requests in PhysicsSimulatorView.cs, everything runs fine.
But I get a File Not found error when DemoBasePhone attempts to load those fonts from the Content area I created for my game.  How do I redirect DemoBasePhone to get those fonts from my game's Content directory.
Adding a Content Reference to DemoBasePhone does not work.  I just get a ton of errors saying it can't copy files from one location to another. 

There must be somewhere where you tell DemoBAsePhone where to go to get it's content but I can't find it.

Thanks for any help.

Allan

Nov 11, 2010 at 5:09 PM

@chaneya

Try prefixing your path with "@Content/"

 

Nov 11, 2010 at 7:45 PM

Thanks for Replying oranjoose.

I'm using the same path that already existed in DemoBasePhone, PhysicSimulatorView.cs in the SimpleSamplesXNA4.0Phone.

_spriteFont = content.Load<SpriteFont>(@"Content\Fonts\diagnosticFont");

 

 

The only thing I did was rename the Content folder from SimpleSamplesPhone Content(Content) to MagmaContent(Content).

For some reason, DemoBasePhone can't see the Fonts folder or the fonts in my MagmaContent(Content) folder.

Allan

 
Nov 18, 2010 at 6:57 PM

I'm having trouble getting this release to run at all.  I've added the dll as a reference in my project (Adding the project resulted in errors about the stopwatch and despite all my searching I could not find a Microsoft.Devices.dll, just a Microsoft.Devices.Sensors.dll).  I added a body and a PhysicsSimulator to make a simple HelloWorld program and the app doesn't start, it simply returns to my Start screen after a few seconds.  There is no build error or runtime exception.  I slowly commented out the code until I found that simply declaring a PhysicsSimulator object was causing the problem.  Just declaring it was the problem, even if I never used it the problem still occurred.  Has anyone else had this problem?  Any workarounds?

 

Thanks,

Austin

Nov 19, 2010 at 1:41 AM

I got home and started playing with this.  It seems like Microsoft.Devices.dll is now Microsft.Phone.  I had to remove the reference to the FarseerPhysics DLL, added the FarseerPhysics project to the solution, removed the reference to Microsoft.Devices and then add one to Microsoft.Phone and that project built fine.  Once I added that project as a reference to my game project everything seem to work fine in my HelloWorld app.  Hope this helps anybody running into the same issues as I did.

 

Austin

Nov 24, 2010 at 2:11 PM

I just spent an hour or so getting the latest Farseer 3.1 release and SimpleSamples running on the WP7 emulator.  It now fully supports touch input on menu items and touch to drag the physics objects around, and properly fits the 800x480 screen size.  I also fixed the use of Color so it works with the new pre-multiplied alpha.  It also properly supports the Back button.

There were not a lot of changes to be made.  I've made the whole package available here if anyone is interested.

Coordinator
Nov 24, 2010 at 5:41 PM

Cool, I will load this on my wp7 phone this weekend and see how it runs. Would be nice to put some polish on the demos, make sure they all run good on a real phone, then submit them as an app to the app store.  Could even put a list of wp7 games (with marketplace links) using the engine in the app and update it periodically.  Would be great free advertising for the engine and the wp7 games that use it.  (of course this is somewhat self serving as my game Krashlander is one of the game that would be in the list. :-))

-Jeff

Developer
Nov 24, 2010 at 7:51 PM

My Samsung Focus chokes on the Stacked Shapes demo. I haven't taken a look at why exactly it chokes, but it does lol.

Coordinator
Nov 27, 2010 at 3:41 PM

slygamer: Would you be interested in adding this to FPE 3.2?

crashlander: Agree, the demos need some polish. I've setup everything so we can use the old DrawingHelper to create some textures instead of just simple debug mode. We could even add some nice looking textures to rectangles and circles instead of plain ones. I will work a little on the screen system for FPE 3.2 to make it fade properly and support stuff like the pause screen. I'm aiming FPE 3.2 to have a greater "uhhhhh shiny!"-factor ;)

I will put up an ad asking for help with the graphics in the samples.

Nov 29, 2010 at 12:33 AM

I'll submit a patch for the changes when I get home tonight.

Nov 29, 2010 at 5:49 PM

Great idea Jeff! And if we want to add our games to the list, we first have to buy Krashlander :) I'm working on my first WP7 game with Farseer now and performance is even better than on my Xbox360 :) Looking forward to post here my first screenshots to the community :)

-Stefan 

Coordinator
Nov 29, 2010 at 6:31 PM

@Northwind877.  ha,ha.. sounds good to me. :-)

Nov 30, 2010 at 10:25 AM

Creating this patch is more difficult than I thought because I did the changes from the released zip distribution rather than from a SVN working copy.  I've got a SVN working copy now, so I'll do the changes again in that.  I see you've made some of the changes already.

Nov 30, 2010 at 1:25 PM

Patch posted for WP7 support, built against latest head revision.

Coordinator
Nov 30, 2010 at 4:34 PM

Nice work. I'll take a look.

Dec 3, 2010 at 5:17 PM

slygamer, the following files are missing from your patch:

Branches\XNA\Farseer Physics XNA WP7.csproj
DebugViews\DebugViewXNA\DebugView XNA WP7.csproj

There's also a conflict in Island.cs with the changes made after you created your patch. 

Coordinator
Dec 3, 2010 at 9:56 PM

I've added the patch to the latest changeset (81119). To use it on WP7 you will have to generate WP7 projects from the XNA project and add references to Windows.Phone and Microsoft.XNA.Framework.Input.Touch

Dec 4, 2010 at 1:57 AM

Works great, thanks to all involved.

Dec 6, 2010 at 12:08 AM

So it's all sorted?  Sweet!