Cinema 4D woes and problem solving

Early on in Containments development I wrote a very basic exporter for Cinema 4D. All it exported was polygon outlines and triangle data but I needed to extend it to export texture UV coordinates and normals. This is when the pain started. The documentation to Cinema 4D’s scripting language is terse to say the least and there appears to be very little in the way of support so getting at this most basic of data was not easy. At one point I was on the phone to Newtek to see how much it would cost me to upgrade my old version of Lightwave instead. As per usual though the solution to this little problem came to me at about 3am and it took a lot of will power to remain in bed and not get up immediately to code the solution.

It’s always the way with me. If I get hung up on a solution to a problem I have to walk away from it and let it stir away at the back of my mind and eventually a solution will pop out all gift wrapped and waiting under the tree. At the discovery of a problem though it is difficult to remember this process and not just hammer away at the issue until you get at the same solution which usually takes longer and not as elegant. It has been a while since I had an issue that I couldn’t solve this way and just like California and it’s Earth-quakes I am due the big one.

iPhone 3D, maps and frustums in Containment

Last night I added a very basic map capability to Containment so I can now create a very crude world to wander around in. I am just using cubes for walls at the moment and and another 3D shape as eye candy but the system is more than capable of handling more complex objects. You can see it in action here:

I made some slight changes to the navigation in that I reversed the swipe gestures for left and right rotation and sped up the rotate to make it more responsive.

One problem I encountered early on is the need for scene culling. The map is cell based. Each square you see in the video is one cell so all I needed to do do a sphere check for each square to see if its in the Frustum or not and of course cull it if it isn’t. I will have to go one further than this though since it can still draw a lot of redundant data. My sphere test returns the distance from the cell to the camera so I am going to make use of that data to produce a list of near to far objects and then do a sort of ray cast to work out occlusion so that if a wall is nearer then there is no point processing anything behind that wall. This may seem like overkill but the iPhone has not got a massively powerful CPU and GPU to be able to process the entire world.

Before the ray casting goes in I am putting in environment collision detection so that you can’t walk through walls or objects :)

iPhone 3D navigation in Containment

Containment is coming along quite well now. Since it is a 3D world on the iPhone I struggled long and hard on finding the best way to navigate through it. I considered lots of options among them were:

 

  • Buttons on the edges of the screen that you press to move forward, backwards and rotate left and right.
  • Tilt the iPhone to rotate left and right and also to move forward and Backwards.
Both of the above ideas sucked though and in a flash of inspiration last night I thought about using swipe gestures so I knocked up some quick code to read swipes and integrated it into the prototype game and the results are:

The controls are:

  • Swipe down the screen to move forwards.
  • Swipe up the screen to move backwards.
  • Swipe left to rotate left.
  • Swipe right to rotate right.
It’s still a work in progress so there is a lot of tweaking to - for instance getting the speed right for the left and right swipes which is a bit fiddly at the moment.
Coding swipe based systems is incredibly easy on the iPhone - Apple got that part of the SDK correct and I must admit I am impressed with how simple it was. The most complicated part was differentiating between a vertical swipe and a horizontal one and not getting the two mixed - a Dot product solved that little puzzle though.

iPhone Engine - XGDK

In all of my game development projects I use a variation of the XGDK which stands for Xiotex Game Development Kit. It’s essentially a framework upon which games can be developed. I have one for SDL based games on Windows/OSX and I have also had one for DirectX based development - however that particular project has been left behind since I no longer use DirectX. Whenever I want to use the XGDK in the past I have had to add it as a static library to the main project which I create using either Visual studio or XCode but that has all changed now. I discovered how to make my own custom project templates in XCode and I have created a XGDK template so when I want to go and make an iPhone game everything I need is already setup for me. This has simplified the whole process incredibly. I have still got a reliance on two of the Apple supplied files so far but I am sure I can get rid of those too.

Using iPhone SDK to get contents of web page

I was toying with making use of a PHP based server as a kind of quasi-multiplayer server for my next iPhone game. It doesn’t need to be real-time on the screen multiplayer so PHP will suffice. Once you get past that conceptual hurdle comes the crunch: How to actually get at a web page using the iPhone SDK and more to the point - how do you get data back from it? I must admit I was prepared for much pain when attempting to do this and I must have spent hours tonight researching the subject. I am still being a little bit off-limits when it comes to Cocoa and Objective-C but when I saw the answer to my problem I must admit I am rapidly warming to this language and framework. So, to contact a webpage and get some data from it all you need to do is:

NSURL *url =[NSURL URLWithString: @"http://www.xiotexstudios.com"];
NSString *webpage = [NSString stringWithContentsOfURL:url];

And that’s it. Obviously this is the most basic usage and to be useful I am going to have to thread this access in order to keep the OpenGL update responsive but I just can’t get past the fact that it’s just 2 lines of code to do it!

As I have already said - I was resisting learning Objective-C mainly because the language looks ugly to me. Most languages have a certain visual elegance to them but Objective-C to me looks like an over-reliance of brackets to enforce a kind of hierarchical messaging system then is just plain ugly to read. I will have to read up on the history of the language but from what I can gather it was an attempt to add object-oriented features to place C (hence ‘Objective-C’) and perhaps with that context the brackets may be forgiven. However, given all of the research I am having to do into Objective-C and the Cocoa framework I am now giving into the necessity and reading a book on Objective-C.

‘Possible candidates are’

I have come across a lot of obscure error messages spat out by compilers and assemblers throughout my career as a coder but yesterday I met the best. XCode 3.1 decided to let me know that I had forgotten to flesh out a member function prototype by simply displaying the error message ‘Possible candidates are’ and then the name of the function. It didn’t take long to discover why I was getting this message and to correct it but that has to rank as one of the most obscure error messages. Kudos for almost solving the error but it would have been more useful to tell me there was an error and then post this message.

Forums

It’s very early days yet but I have decided to add a forum to this site. You can find it at http://www.xiotexstudios.com/Forums

At the moment it has one topic and that is iPhone game development. I am using phpBB3 with a existing template but I must admit I am finding this template confusing so it is likely to change.

iPhone game engine

My first iPhone game has resulted in an engine that I can use for other iPhone games. It’s pretty light-weight and 2D at the moment but a good starting point. I am also porting it to SDL so that it can run on PC and OSX (and Linux at a push - but I don’t have a Linux install so I can’t work on that personally) and it occurred to me that this small engine might be of use to other developers. As I say, at the moment it is pretty light-weight and to be honest just contains enough to do the game I have just submitted to Apple but as I begin to make more games the engine will be expanded to include new features. I personally think that the iPhone is more suited to 2D games rather than full 3D due to the nature of how and when games will be played on it (i.e. at the end of it all its a phone) but there is no reason why 3D will not make its way into it. In fact the next game will probably work within a 3D world but still remain 2D in essence (if that makes sense :|).

The question then rises, if I make this engine available do I make it free, donation supported or out-right charge for it? What are your views on this? Would an iPhone game engine be useful to you? If so what kind of licensing model would you prefer?

Writing games for the iPhone

My first game ‘Boxes’ is with Apple going through their submission process so while this is happening I would like to share with you my experience of developing a game for the iPhone.

My first game took me 2 weeks part time to develop. It’s not a massive game and it hasn’t got a huge amount of levels but given the app stores update facility I aim to expand upon as time goes by. The actual process of developing it however has been a roller-coaster ride. I would like to congratulate Apple on the installation process of all the tools and the instructions contained in the developer portal as getting the whole tool chain up and running to having an app running on the iPhone was painless. Where they fall down is the code support level. For instance, while testing your iPhone app will exit and give a status code upon exit. Now, apparently these numbers mean something but nowhere are these codes listed and emails to Apple don’t get you anywhere - but this may be because it is in Apple’s interest for you to take out an ADC subscription.

The approach I took in developing the game was a hybrid Objective-C and C++ route. So the Objective-C side takes care of the necessary parts of the iPhone setup and asset loading and the C++ side is the actual game. I must admit this approach works very well for me since I have no real desire to learn Objective-C. The XCode compiler makes the 2 languages merge very well and there were no major issues. I was very impressed with this.

The iPhone hardware is impressive. Reading the accelerometers and translating the information you get into something meaningful is a dream. I imagined it would be a lot harder than it was. The graphical power is something to behold as well. I was able to push around a lot of particles without any real slow down and I must confess that my first generation engine is the most inefficient engine you could write for OpenGLES.

Instruments is an application I fell in love with straight away. It does stats gathering on your application and it helped me locate bugs that were causing my frame rate to dive. I want this kind of app for all of my game development now - not just on iPhone! I know there are other tools out there that do a similar thing but Instruments does it so well.

The submission process. Apple have attempted to make this a seamless process and to the most part it is. Their documentation needs a little help though. An example, they want you to provide 2 icons. The first is the 57×57 one that appears on the iPhone and a 512×512 one that appears in the app store. Nowhere does it mention that these two have to be identical - in fact my first round submission failed because I used different images. The process of uploading your game is also flawed in that the second time you attempt it you get stuck in a ‘waiting for upload’ loop and their separate application loader exe is broken. Once you have your game uploaded it enters a ‘review’ stage and this is the part I hate the most because there is no indication of how long it will take and I find myself looking at the page every day to spot a change.

More later as I get more and more into the process.

Hiding the status bar

You can hide the main status bar by adding this following code to some point in your ‘applicationDidFinishLaunching’ function:

[application setStatusBarHidden:YES animated:NO];

Next Page »
 
The game goes here
The game goes here
The game goes here
The game goes here