Friday, August 31, 2018

Simpsons Trivia Windows Port

In the previous post, we introduced Simpsons Trivia: a simple quiz game for the Sega Master System. Here we outlined tasks to port game to XNA 4.0. Now we will port to MonoGame for Windows as a new baseline.

The motivation here assumes a point where it is difficult / impossible to install XNA 4.0 plus required Visual Studio 2010 pre-requisite onto Windows PC. Especially if / when Windows 7 is deprecated for Windows 10. [In fact, currently you may be prompted to install GFWL for Windows 10 compatibility.] Let's check it out!

Setup
Follow all instructions from this post to setup MonoGame, Visual Studio and, if necessary, Xamarin Studio.

Outline
Similar to previous post, write all game code in an external library to be consumed by multiple thin clients. Configure SVN Externals as previous post but library and test projects now driven from Windows solution!

WIN Game Server
Launch Visual Studio 2015. Create blank solution. Add the following 4x new C#/.NET projects to solution:
 Project  Type  Description
 SimpsonsTrivia.WIN  MonoGame 3.6 Windows  Entry point + game built content
 SimpsonsTrivia.WIN.Library  MonoGame 3.6 Windows  Generic game library for all clients
 SimpsonsTrivia.WIN.SystemTests  Windows Class Library  Uses for game library system tests
 SimpsonsTrivia.WIN.UnitTests  Windows Class Library  Uses for game library unit tests
Download code sample here.

Note: as there is not a corresponding XNA Library project template for MonoGame, create 2x MonoGame Windows projects but set the second project output type for SimpsonsTrivia.WIN.Library to Class Library:

Checklist
Here is a quick checklist of tasks to complete first including Delete the default C#/.NET file, Update project properties profile to use "Reach" and Rename the default namepsace to WindowsGame. Add the packages:

packages
  • log4net.2.0.8
  • Ninject.3.3.4
  • NUnit.3.2.1
  • RhinoMocks.3.6.1
SimpsonsTrivia.WIN
  • Add Data folder for all text file data
  • Add SimpsonsTrivia.WIN.Library ref
  • Update EXE binary output path
  • Replace all initial game icons
SimpsonsTrivia.WIN.Library
  • Add Common folder for all game code logic
  • Add Master folder for all game engine code
  • Add log4net reference
  • Add Ninject reference
SimpsonsTrivia.WIN.SystemTests
  • Remove DataSetExtensions reference
  • Add SimpsonsTrivia.WIN.Library ref
  • Add nunit framework reference
  • Add nunit GUI test runner
SimpsonsTrivia.WIN.UnitTests
  • Remove DataSetExtensions reference
  • Add SimpsonsTrivia.WIN.Library ref
  • Add nunit framework reference
  • Add Rhino Mocks reference
  • Add nunit GUI test runner

IMPORTANT
Create directory symbolic link using mklink to WIN Content folder to run system tests [and on build server]

Start | run | cmd
mklink /D C:\SimpsonsTrivia.WIN.Content 
C:\SVN\SimpsonsTrivia\SimpsonsTrivia.WIN\SimpsonsTrivia.WIN\bin\x86\Debug\

// BaseSsytemTests.cs
protected const String CONTENT_ROOT = @"C:\SimpsonsTrivia.WIN.Content\";

Warnings
Manually edit system and unit test projects in Notepad and add following XML to mitigate MSIL warning:
<PropertyGroup>
  <ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>None</ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>
</PropertyGroup>

Re-install NuGet packages as necessary to mitigate against warning using a different target framework:
Tools | NuGet Package Manager | Package Manager Console. Type update-package -reinstall

Finally, action the following if conflicts found between different versions of the same dependent assemblies:
Open SimpsonsTrivia.WIN.csproj in Notepad++ Add XML following <OutputType>WinExe</OutputType>
  <OutputType>WinExe</OutputType>
  <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>

NUnit
Don't forget to setup the *.nunit files to open with NUnit (x86) version by default. Right click SystemTests or UnitTests nunit file | Open With... | Add as "C:\Program Files (x86)\NUnit 2.5.7\bin\net-2.0\nunit-x86.exe"
 Key  Value
 Program:  "C:\Program Files (x86)\NUnit 2.5.7\bin\net-2.0\nunit-x86.exe"
 Arguments:  
 Friendly name:  NUnit (x86)


Audio
The original music used for Simpsons Trivia was in VGM format for title and game over and PSG format for the sound effects. Therefore, these must be converted to MP3 + WAV format respectively for Windows PC.

Music
Download Audio Overload application and extract. Launch aowin64.exe. Dag VGM file into application. Save clip as WAV file and click Play button. Play song to end. Once finished will save. Convert WAV to MP3 online.

Note: Audacity can also be used to convert WAV files to MP3. Open WAV file. Choose File | Export Audio and Save as MP3. However, it may be required to download Lame to complete export! Download Lame from here.

Sound
First write sample program to play PSG files in Sega Master System program. These will recorded manually:
#include "..\lib\SMSlib.h"
#include "..\lib\PSGlib.h"
#include "gfx.h"
#include "psg.h"

#define SFX_RIGHT_PSG sfx_right_psg
#define SFX_WRONG_PSG sfx_wrong_psg
#define SFX_CHEAT_PSG sfx_cheat_psg

void main (void)
{
 PSGSFXPlay( SFX_RIGHT_PSG, SFX_CHANNEL2 );
 SMS_displayOn();
 for (;;)
 {
  SMS_waitForVBlank();
  PSGSFXFrame();
 }
}
SMS_EMBED_SEGA_ROM_HEADER( 9999, 0 );
SMS_EMBED_SDSC_HEADER( 1, 2, 2018, 3, 27, "StevePro Studios", "Simpsons Trivia", "Simpsons Trivia game for the SMS Power! 2018 Competition" );

Setup computer as follows:
Unplug speaker cable from audio jack. Plug black cable from microphone into headphone jack. Launch Voice Recorder. Start recorder. Play Sega Master System program. Stop recorder. Save as, or convert to, WAV file.


Content
MonoGame Windows project templates add a "Content" folder as the default location for all Content. Right click the "Content" folder | Add New Folder. Simpsons Trivia uses the 4x following subfolders (listed below):

Data
Contains flat TXT + XML data files to be consumed by the game. Do not need to be built as XNB files!
Right click each data file | Properties | Build action: None | Copy to output directory: Copy if newer

Fonts
Font XNB files may need to be rebuilt for Windows using the MonoGame Pipeline; instructions below:
Right click each font file | Properties | Build action: Content | Copy to output directory: Copy if newer

Sound
Sound effect XNB files may need to be rebuilt for Windows using the MonoGame Pipeline; see below:
Right click sound effect | Properties | Build action: Content | Copy to output directory: Copy if newer

Song XNB files may also be rebuilt along with corresponding WMA files to be included in the project:
Right click music files | Properties | Build action: Content | Copy to output directory: Copy if newer

Textures
Here texture XNB files may need to be rebuilt for Windows using the MonoGame Pipeline; see below:
Right click sound effect | Properties | Build action: Content | Copy to output directory: Copy if newer


MonoGame Pipeline
The MonoGame Pipeline Tool is used to manage MonoGame content and generate corresponding XNB files. Follow this documentation on how to use the MonoGame Pipeline Tool. Create Simpsons Trivia WIN project:

Start | run | MonoGame Pipeline. File | New. File name: WindowsProject.mgcb | Save content pipeline file. Select top level "WindowsProject" node. In the Properties window choose Platform; in this case Windows. Import all content from original game such as Fonts, Sound [music + sound FX] and Textures [images]. Right click on top level node and choose Rebuild. The converted XNB files will be generated in bin folder.

MAC Game Server
In the previous post, it was assumed to use Cross Platform Desktop project template for MAC. However, this seems more Linux-based. Instead, on the Mac, launch Xamarin Studio. Create Xamarin Mac Classic project: Unfortunately, as this is an experimental build, it was not currently possible to integrate music and sound FX. Open Info.plist and choose minimum deployment target available. At this time the minimum version is 10.7.

Finally, set up SVN Externals manually similar to this post:
cd ~/SVN/SimpsonsTrivia/SimpsonsTrivia.MAC/SimpsonsTrivia.MAC/Content
svn propset svn:externals 'Data http://build/svn/SimpsonsTrivia/SimpsonsTrivia.WIN/SimpsonsTrivia.WIN/Content/Data' .

cd ~/SVN/SimpsonsTrivia/SimpsonsTrivia.MAC/SimpsonsTrivia.MAC
svn propset svn:externals 'Common http://build/svn/SimpsonsTrivia/SimpsonsTrivia.WIN/SimpsonsTrivia.WIN.Library/Common' .
svn propset svn:externals 'Master http://build/svn/SimpsonsTrivia/SimpsonsTrivia.WIN/SimpsonsTrivia.WIN.Library/Master' .

svn status
cd ~/SVN/SimpsonsTrivia/SimpsonsTrivia.MAC/SimpsonsTrivia.MAC
svn commit -m "Add SVN Externals"
svn update

WP7 Game Server
Previously, WinPhone7 [WP7] was used as a destination client intermediary between Windows PC and mobile device deployment + testing on Windows 7. However, WP7 projects may fail to build in Visual Studio 2010 as FilterItemsBySupportedCultures task failed unexpectedly.

If this error occurs then close Visual Studio 2010. Update the binding redirect in the devenv.exe.config file:
Edit devenv.exe.config found as here C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\
<runtime>
  <UseSmallInternalThreadStacks enabled="true"/>
  <dependentAssembly xmlns="urn:schemas-microsoft-com:asm.v1"><Tag ...
    <dependentAssembly>
      <assemblyIdentity name="Microsoft.Build.Framework" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
      <bindingRedirect oldVersion="12.0.0.0-14.0.0.0" newVersion="4.0.0.0"/>
    </dependentAssembly>
However, this may not be required with the upgrade of Windows 10 as WP7 may now not be compatible!


WP8 Game Server
The successor to WP7 is WP8. Therefore, it makes sense to look for an experimental client to replace WP7. While it's possible to get corresponding build, there may be Hyper V Manager issues on some Windows PCs: Follow instructions here but refer to 8.1 parent folder in C:\Program Files (x86)\Microsoft XDE\8.1\xde.exe. Start | run | Hyper V Manager lists WP8 emulators available to connect ignoring the Virtual Switch Manager.

Right click C:\ Program Files (x86)\Microsoft SDKs\Windows Phone\v8.1\Emulation\Images and disable file compression. Right click %USERPROFILE%\AppData\Local\Microsoft\XDE and disable file compression also.


Summary
To summarize, the transition from XNA 4.0 + Visual Studio 2010 + Windows 7 to MonoGame 3.6 + Visual Studio 2015 + Windows 10 was very smooth. Plus, was an opportunity for additional experimental builds.

This included, an exploration of WP7 to WP8 for mobile device deployment + testing from the Windows PC. Finally, in order to complete mobile device deployment, the next posts will include ports to Android + iOS!

1 comment:

RobertNelson said...

Thanks a lot for sharing this amazing knowledge with us. This site is fantastic. I always find great knowledge from it. Apple Developer Enterprise Account

Post a Comment