After more than 2.5 years I'm back. I'm going to try hard to get back into spending regular time on my game and actually get it published. So far I've spent about 15 hours just getting it back to the point it was when I last left it. A lot has changed since then, which is why it took so long to just get it working at all. Here're a few things that have changed and some details about what I've had to do to fix them.
- I've changed my home computer. I used to have a tower Windows PC and a Macbook Air for doing the iOS-specific development portions. I now have just a Macbook Pro Retina, which I run VMWare Fusion and Windows 8. I made this migration a while ago, but finally getting my development environment working well took some work.
- OpenTK seems to have made some changes, which I don't fully understand since their release date is 2010-10-06 and should have been before I took a hiatus. See more details below.
- In the interim 2.5 years both XCode and Xamarin MonoDevelop have evolved and new versions have been released that required more updates. Xamarin's product has been renamed to Xamarin Studio and now has some interesting integration with Visual Studio, which hopefully will make development a bit easier. See more detail below.
OpenTK Issues
When I tried to run my game on Windows using OpenTK I got a PInvokeStackImbalance
exception saying: This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.
Since I was running against the release build of OpenTK, which doesn't contain debug symbols this error occurred in my GLView
class' constructor. It is an implementation of OpenTK's GameWindow
. After compiling a debug build of OpenTK, I eventually traced this to the function GetProcAddress
in Egl.cs
, which is a PInvoke call.
The problem is the EntryPoint should be eglGetProcAddress
, not eglCopyBuffers
. After changing this and rebuilding OpenTK it worked fine. Doing some searching on the net shows this has been fixed in GitHub, but no new official build containing the fix has been released. It was an easy fix, but a bit disappointing that OpenTK's current official release has such a basic bug in it.
Beyond this, it seems that the latest official OpenTK release differs from what is released with MonoTouch. I'm still not sure of the extend of these differences, but I may write more on this later once I get a better understanding.
Xamarin and Visual Studio
As I discussed in a previous post, I've been using Visual Studio as my primary development environment and only switching to MonoDevelop Xamarin Studio when I wanted to actually deploy my code to my iPhone. Apparently others also are interested in doing this because Xamarin has integrated their product with Visual Studio; you can read more about this on their site. Because they're now providing .NET DLLs that can be used in Visual Studio to compile iOS .NET apps, it means I can simplify one of the issues I had with maintaining and building my code.
I have my game broken into 4 projects, each of which builds into a separate binary. One of these, which I call "Launcher", is the most device dependent, and references device specific libraries. This project can't actually be shared across platforms because the code is too different, so I have both a Launcher.iOS project and a Launcher.PC (in the future I hope to add Launcher.Android and Launcher.WinPhone). For the other three projects I also need separate project files, but 100% of the code is shared. This leaves me with this folder hierarchy:
- Zoing
- Launcher.iOS
- Launcher.iOS.csproj (project file that references iOS specific libraries)
- ...iOS specific code files...
- Launcher.PC
- Launcher.PC.csproj (project file that references PC specific libraries)
- ...PC specific code files...
- MediaFramework
- MediaFramework.iOS.csproj (project files that references MonoTouch .NET libraries)
- MediaFramework.PC.csproj (project files that reference Windows .NET libraries)
- ...device independent C# files included in both project files...
- OpenTKConnector
- OpenTKConnector.iOS.csproj (project files that references MonoTouch .NET libraries)
- OpenTKConnector.PC.csproj (project files that reference Windows .NET libraries)
- ...device independent C# files included in both project files...
- Zoing
- Zoing.iOS.csproj (project files that references MonoTouch .NET libraries)
- Zoing.PC.csproj (project files that reference Windows .NET libraries)
- ...device independent C# files included in both project files...
MediaFramework is a set of device and framework independent classes that define the building blocks for my game. This includes things like: Audio/AudioSample
, Device/Orientation
, Graphics/Texture
, Graphics/TextureArea
, Graphics/MutableShape
, Graphics/Shape
, Graphics/Size
, etc.
OpenTKConnector is a concrete implementation of the MediaFramework abstract classes using OpenTK (OpenAL and OpenGL). For example there is OpenGLES11/OpenGLES11Texture
and OpenGLES20/OpenGLES20Texture
, both of which implement MediaFramework/Graphics/Texture
. Similarly there is OpenAL/OpenALAudioSample
, which implements MediaFramework/Audio/AudioSample
.
The benefit of having this separation is that my Zoing game just needs to know about the abstract classes in MediaFramework and complete ignores the platform details. For example, AudioSample has a Play
method, which plays the sample. That is common for any platforms I will eventually support.
Anyway, restructuring my solution to have the project files arranged as above took a bit of time. I had to recreate the iOS project files to reference the MonoTouch library properly. I also had to move these files around, which is made a little more difficult with version control. Some of this meant examining and tweaking the project files' XML by hand.
This reminds me of one small bug in Visual Studio 2010 that caused me some confusion until I understood it. When you unload a project, then edit the project's .csproj
XML file, then reload the project, it seems that Visual Studio doesn't recognize the manual changes you made. To fix this simple unload it again, then reload it again. This is a bit annoying, but once you know about it the workaround is simple.
Next: OpenGL and OpenTK Fun