Welcome to my Programming Blog...

I am currently working on a couple of projects: An original game called "Implosion" which I am porting from Flash to the iPad, and a remake of Q*bert in Python (pygame), as part of the class I am teaching. Please feel free to use the "Labels" (at right) to follow a specific project or theme. If you are one of my Python students, I recommend that you check out the Python thread.

Monday, July 26, 2010

Memory problems...

I have been having a frustrating time with implosion. I had to take a week off for a conference, but even then, I've been avoiding it a little, in the hopes that something would come to me. And because I am frustrated.

As soon as my program starts, I get a memory warning, level 1. Soon thereafter, I get a level 2 warning, and the game crashes.

I finally got Instruments to show my memory leaks - it didn't find any. But it did show some large allocations at the beginning of the program. I found some code to tell me the remaining memory (http://adeem.me/blog/2009/04/01/get-the-amount-of-free-memory-available) and inserted into my startup routines.

Pretty quickly, I found that loading my main logo image, which was 1024 x1024 pixels, took up 5MB of my available 28MB. A bit steep-the file size was about a quarter of that, but I suppose it was compressed. So I reduced the file to 512x512, which reduced the memory used.

But I still got a memory warning.

A little investigation revealed that the memory warning was coming the second time the menu rendered. I soon found out that the first time the logo and buttons were drawn on the screen, it ate another 5MB, and the second time it ate an additional 5MB. But not the third. (I am guessing that this is a result of double-buffeting?)

So a quick loss of 15MB over a few seconds on a system where I start with only 28MB? No wonder the iPad was freaking out.

But there are two things bothering me at the moment.
1) something must be wrong with my numbers - the iPad I have is supposed to be 32GB, not MB. -- oops. I'm confusing storage space with RAM. It's pretty late as I write this.
2) when I take out the code that draws my logo and buttons, it still takes 5MB of RAM each time, even though it is not drawing anything! I am starting to think this is not my fault...

So I will have to research this online. Perhaps there is a fix for this, perhaps I can find a workaround, or perhaps... I don't know.

As I said, I am frustrated.
- Posted using BlogPress from my iPad

Saturday, July 10, 2010

Progress, progress, progress!

I got some great stuff done the last day or so...

1) Menus - There is now a starting menu with the logo I showed off in the previous post. It also has a "Play" button and a button for instructions. Clicking the play button starts the game and the instructions button shows a page with rules of the game (a tap on the screen returns to the menu).

2) Pause - based on the same "sio2 widget" technology, there is now a pause feature. During the game, if you flip the ipad to face downwards (or accelerate it downwards at 2g) it will go into pause mode - the clock will stop, but there is a graphic covering up the game board. A single tap resumes.

3) Game over - when the player runs out of time, the selector disappears, all the doors open, and the chips start to fall towards the center. They make a tiny ball, which then explodes outwards. It is very satisfying in the OpenGL 3-d world! It reminds me of the original Tron and (spoiler!) what happens to the MCP at the end.

4) The game moves between the modes pretty fluidly, and you can restart the game.

Along the way, I was getting some distressing messages from the debugger. I use the "NSLog" command quite a bit, so I suspect these have been getting lost in the clutter - they were memory warnings. Somehow, I was running out of RAM space. Mostly, they were just level 1 errors, but I actually got a level 2 one tonight. This didn't seem likely, since my chips are of a finite number, and there just aren't that many polygons and variables in this game, compared to most 3d fare...

So I wondered if I had too many graphics loaded in memory at one time. I rewrote the menus and buttons (widgets) code so they loaded when needed and unloaded when they were done. It was a bit of a pain, and I worry a little bit about the speed at which they will load now. That didn't fix it.

I stumbled upon the answer when a memory warning showed up between two closely spaced NSLogs - in fact the only thing I did between them was move a Chip! It turns out that every time I moved one of the chips, I created a new 3d vector to represent the displacement of the Chip on that animation interval - and I never relinquished the memory. Multiply that by 100 chips and multiply it again by the number of animation steps during the game - it became a pretty big leak! So with one line, I patched that one... I wonder how many more I have missed.

What's left?

  • Reworking the timing of the Ring chips
  • Adding in the strange shaped selectors
  • Redoing the sound at the end of the game to match up with the animation
  • Possibly changing the single-click behavior to a double-click one.
  • Auditing for memory leaks
  • Figuring out how to get this thing into the store!
Dare I say I'm in the home stretch?

Monday, July 5, 2010

Fix it, yourself

Ah, the Internet. You can usually find the answer there (if you know what to search for). Elsewhere in the discussion board, I found the answer - it was a cheat of sorts. You need to invert the y-component in the portion of the code that calculates where you touched. This fixed the widget button problem perfectly, but it meant that I had to invert the way I handled the y-coordinate in the rest of my code. As it turns out, this was a small thing - I had already inverted it to compensate months ago, so now I just needed to change three lines to undo my previous inversions. That's working much better now.

But now, as I test my program, I have found a bug. Sometimes, the chips aren't sliding all the way in, or are just disappearing so that there is a blank spot in the grid - which never goes away - the user is in a bind. I need to figure out what is going on! (I wonder if this has to do with the timed pieces I just added recently- I'll start there.)

Presuming I get that fixed, coming up are (in no particular order):

  • an instruction screen
  • a pause menu
  • animation on the title screen
  • in-game instructions
  • a second green ring in the timer
  • improved timer chip placement
  • a game over animation
  • scores on the title screen
  • additional selectors for higher levels
... and I think I can post the game! W00t!

Sunday, July 4, 2010

Weirdness

Ok, so I have the logo from the last post (or something resembling that) show up in my program. And I have an sio2 "widget" with a graphic that says "play" set up to be a button. But now things get weird.

You see, you can't click on the button. But you can click on the button's reflection. The button appears 200 pixels from the bottom of the screen, but it only responds if you click on a point near 200 pixels from the top of the screen. Since I'm not the one who wrote the button code, I am a bit stymied. I can work around it by playing with the same touchscreen code that I used for the rest of the game, but I'd rather not. Alternatively, I could just center the button, but this isn't the only button I plan to use!

I've put in a request at the sio2 forum, and I hope to hear back on what to do about this....

Thursday, July 1, 2010

Logo

I've been on a trip for business lately, so I haven't been able to do much for the last week. To sort of get myself back in the mood, I played around in LineForm to make a logo:
(Yes, there's a reason I don't do graphic design for a living....) 

I will probably try to use this graphic in a title page for now, and then I'll see about updating it with something better later. I need to sleep on the graphic a bit.