Thursday, 11 September 2008

Feature-creep

Okay, so version 1.0 is slowly taking shape. Here's a few snippets of the smaller parts that are being worked on in between a lot of the "big stuff".

Firstly, there's a couple of things that I've put in there for my own use. For instance, there's screenshot code now, although probably the only person that will use that is myself. It's BMP-only (converting to PNG using libpng just looks way too complex to bother with) and I use it to verify the drawing is correct, to build the new animated GIF's for advertising the game and things like that. Unfortunately, because it needs to be able to activate at any time, this is one of those features that can't be slowly moved into the menus like almost every other new feature and requires a dedicated key. I've put it on Stick-Click for now because most people never press it (and it doesn't even exist on later versions of the GP2X), so it won't get in people's way.

It highlights a big problem that I have - the GP2X doesn't have enough keys! Unbelievable, I know! Excluding the basic up-down-left-right (whether as a "mouse" or "cursor keys") that are common to all the games, and the key-combinations I have for "safety" (e.g. L+R to quit back to the menu etc.) the "keys" required after moving almost everything into the Pause menu are:

Left-click (required in every game)
Right-click (required in a lot of games and sometimes essential to completion / player comfort)
Middle-click (only used in a handful of the games, and not essential to puzzle completion, but convenient)
Pause / Enter Menu
Decrease Digit
Increase Digit (the only way I could make unequal, solo, filling, etc. playable without a keyboard, but still not perfect).
Enter Digit
Undo
Redo

And the buttons I have are: A, B, X, Y, L, R, Select, Start. 8 buttons for 9 functions. So before release I'll be re-jigging all the keys. I don't want to move Undo/Redo into the menus but it's an option. I also don't want to shift a common key into a "combination" (e.g. at the moment I have L+VolDown for Undo and L+VolUp for Redo). I'd also like a key to switch between input systems eventually, so that for some games where it makes more sense to use a "cursor-control" system instead of a mouse-emulation one (such as fifteen and sokoban), the user can change between them at the press of a button.

Some "hidden" combinations need to be present to. Because the user can save their favourite configuration for each game as a preset, and that preset loads by default whenever they start that game, there needs to be a way to cope with two scenarios: The config save file gets corrupted, the config describes a game which takes an inordinately long time to generate. Imagine accidentally saving a config for Net, for example, that takes an hour to generate a game. You'd have to leave your GP2X on for all that time before you'd be able to change the options and play Net normally again. In fact, the easy solution is a little hidden feature - press L or R when loading a game from the main menu and it will completely ignore your preset. You can then get into the game ultra-quickly, change the options and re-save your preset if you need to.

At the moment, the options in the Pause menu are so numerous that they are now sub-categorised:

New Game
Restart Game
Solve Game
Configure Game
- View Presets
- Load "My Preset"
- {Load Preset X}
- {Configuration Option X}
- Save As "My Preset"
Help
- General help (Keys, etc.)
- {Game X} Instructions
- {Game X} Tips and Tricks
Global Options
- Music
- Track List
- Volume (including On/Off)
- Auto-Save Game on Exit
- Screenshots
- Include cursor in screenshot.
- Include status text in screenshot.
Credits & Licenses
- Puzzle Collection
- Third-party Games
- GP2X Port
- Music
Quit to Main Menu (the list of games).

I have decided on the background music I want and got permission of the artist - by strange coincidence, they own a GP2X so they'll be able to play the game with their own music. I've gone for some plinky-plonky ambient music - gentle, relaxing, simple. I'll also retain the ability for the users to replace or remove the music if they so wish - it'll just be 10 OGG files in a music folder. If they aren't there, nothing plays. If they are, they appear on a track list that the user can edit - so even if they don't like my choices, they can choose their favourite tracks to play while they puzzle. And, of course, there's the all important "Music Off" option.

General Updates:

The main menu shows the revision of STPPC that they are based on. This is so that people can see how old the collection is and whether it needs updating to support feature X of a certain game, or indeed any new games that come about. (There's a new, much more configurable, version of Loopy in SVN and it's already in my private version of 1.0 and working perfectly.)

The main menu is now complete and allows loading any of the 30 fully-working games (yes, 30, because Mines works now). It lets you go into and come out of the games as many time as you like without quitting back to the menu and is super-fast. I tried it on my GP2X for a laugh and after 200 entries and exits from particular games without quitting back to the main menu, I was suitably satisifed that I wasn't leaking too much RAM or risking a crash by playing that many games - this test included music, games with saved presets, full games, partial games, games with timers, loading/saving games, etc. A fairly accurate measurement of memory usage says that (with music off) the games rarely go about 5Mb of allocated RAM in their default configurations, although obviously most of them can be allowed to grow to silly sizes if you play with their config options. Without going too mad, I was able to generate "virtually impossible to solve within the GP2X's battery life" puzzles in all the games and didn't once get an out-of-memory error or crash. Although some of them nearly took forever to generate puzzles of that size!

Music works but may stutter on very difficult puzzle generation. There's not much I can do about this without increasing the size of the sound buffer - at the moment puzzle generation is an inherently single-threaded process and it tends to swamp the CPU and all other threads running. When interruptible generation is implemented (a BIG task), then it will hopefully solve itself because in the same place that I put code to check if the user wants to stop, I can refresh the music buffer.

I also know that Blackbox has a configuration option that can take values of the form "4-10" meaning "anything from 4 to 10". That's totally impossible to enter in the options menu in the current state (although you can happily use a Preset or hand-edited config file to play it!), but I may well hack on the Blackbox code to convert this to two configuration options: Min and Max. If you set them to the same number N, it's the same as just "N" in the config box, and if you set them to, say, X and Y respectively, it's the same as entering "X-Y" in the config box. I'll also be on the lookout for other similar options that allow such things.

Config-options are one of those things that are really finicky to convert to a non-keyboard device because they are expecting textual input all the time - the current GP2X code has always had a special "Kludge" switch that allows entry of floating-point numbers in, for example, "Barrier Probability" in net because otherwise you'd only have barriers everywhere or none at all. At the moment, such options are hard-coded in the GP2X code but I'm trying to find a nice way for the puzzles to support telling the so-called "frontend" whether a configuration option should be floating-point or not. It looks like I might have Simon Tatham's ear on that particular issue, however.

There's been a massive reorganisation of the files that the program uses. The folder structure is currently similar to:

Configurations/ (holds the game-specific INI files)
Documentation/ (holds various information about the collection such as licenses etc.)
Help/ (holds the various help textfiles)
Images/ (holds splashscreens and "game previews" that show in the menu)
Images/Screenshots/ (holds any generated .BMP screenshots)
Music/ (hold, erm, the music?)
Saves/ (holds all the savegames)
STPPC2x.gpe

So hopefully, there will be no more hundreds-of-files-in-one-folder and even the above folders should be as empty as they can be.

Finally (for this update at least), I'm looking at making a new game to go into the collection. It won't make it into the official collection, I'm sure, but I'm looking at the possibility of a simple overhead 2D maze game - I have some code that I can use for various "types" of mazes and solvers for them and I'm hoping they'll translate well to the small screen of the GP2X. That will be probably be a post-1.0 thing, though, because believe it or not, programming for that side of the collection is new to me!

Monday, 8 September 2008

STPPC2X - "Mines" is now working!

Ah-ha!

Right, FINALLY. I got you, you mines-bast**d. FIXED. FIXED. FIXED. Version 1.0 will have working "mines"! Guaranteed.



Okay, for some reason, the particular version of gcc on ARM that the Open2x development environment uses does not treat an relatively-undocumented (and technically "broken") use of memset on the ARM platform the same as it does on x86. I think it's the alignment of ARM but I can't be bothered to check the exact technical details know that I have found it.

void * memset ( void * ptr, int value, size_t num);
Sets the first num bytes of the block of memory pointed by ptr to the specified value (interpreted as an unsigned char).


Notice the "unsigned char" bit. So when you do what mines.c was doing: memset(a pointer, -2, a number) it works perfectly on x86 (and all the other supported platforms, including MacOS, Palm, etc.) but does this on ARM:

"-1 -2 -2 -2 -1 -2 -2 -2 -1 -2 -2 -2"


Which buggers up mines! The fix is not to use memset but to fill the array manually - you get the proper result and mines no longer crashes but "just works". There were three places, only in mines.c, that do similar things. It seems to work fine for the other uses which are mostly -1's.

This fix was found by the following method:

1) Write original author of mines.c a long begging letter with lots of technical details on the problem
2) Recieve reply with basically says "No idea, can you print out the contents of X at line Y for me to look at?"
3) Edit code to print out contents of X at line Y on both PC and GP2X.
4) Gather debug logs from both platforms and compare.
5) Draft another long begging letter which says "This is what I got".
6) Just before hitting Send with large debug logs attached, notice that there is a pattern to the what-should-be-empty array.
7) On a hunch, gradually keep shifting the debug check higher and higher in the code, eventually placing it immediately after a memset.
8) Spot the problem (memset arrays aren't actually uniformly memset)
9) Google the definition of memset which includes the "unsigned char" line.
10) BELLS RING.
11) Search for all memsets with negative parameters and replace with for() loops.
12) Test on PC and GP2X.
13) Rewrite email to Simon Tatham, including a patch and problem description and press Send.
14) Kick self repeatedly and hard.

Anyway... it's fixed. Mines works. Finally. Can't believe it was something so stupid. Multiple human error, because obviously nobody who's touched the mines code had ever noticed the error before and only a compile on an ARM-based device showed it up. Patch winging its way to Simon Tatham for inclusion in the main code. Sigh of relief. Celebration game of mines.

Now, who's got the champagne?

Saturday, 6 September 2008

More work on STPPC2x

I've fixed some quite important bugs in STPPC2x today.

First, I've been doing Valgrind runs on the code, which has picked up on quite a few little bugs here and there - I didn't free this memory, I lost the thing a pointer was pointing too, I extended outside the boundaries of this allocated memory etc. It's only a game for a handheld, so it's not security-critical but it's always nice to fix something that shouldn't happen, even if it only happens rarely, or it has zero actual impact on the code.

At least one of those bugs left a few hundred thousands bytes of bitmap or fonts in RAM. Not a big deal, because the libc clears up enough after the game is quit, but (in theory) if you were to run enough games inside STPPC2x one after the other, you'd run out of RAM. That's still possible but extremely unlikely now because the only memory leaks left are in SDL libraries and the like and so will affect all GP2X software. They are on the order of 20-30 bytes of lost memory each time, so it'd take months of constant playing without quitting, batteries running out, power going off, etc. to make a difference.

I also fixed two long-standing display bugs. Many people noticed that Solo (the Sudoku puzzle in the collection) wasn't drawing properly. And, if you look carefully, you might notice that several puzzles were drawing a bit awry. There was an off-by-one in the drawing of any rectangles (which are used is virtually all games, even if they are just the "background" for a circular or triangular object) which meant that everything looked slightly off and the Solo's cells "overlapped". That's now fixed. I must have misread or miscontrued the documentation for the puzzles and SDL_gfx because I was sure that I had looked at this several times and it was coded as it was supposed to be.

The other bug was a bug in drawing circles for which the puzzle only wanted the outline (i.e. no "fill" colour). This showed itself most in "Inertia" where the stop-points were dark-red pie-slices when they should have been mere one-pixels arcs. By sheer stupidity, the fill colour for a "empty" circle used colours plucked out of a random location of memory because of a signed overflow in the function. A short, one-line check and I fixed it.

In previous versions, none of the GP2X puzzles looked like their screenshots, if people looked carefully. That's because the screenshots were taken from GTK versions. Now, they are pixel-perfect (I hope) and the same as the GTK screenshots or, indeed, the screenshots of any other version of STPPC.

I also fixed a possible palette-crash that I think I may have introduced myself quite recently. Always check your array boundaries! This was caught by Valgrind, again, and I'm quickly finding Valgrind an invaluable tool when debugging. GDB can get you to the line where a problem occurs, with a small backtrace. Valgrind tells you why the thing crashed and where the relevant parts of the code are - only for memory, overrun and similar errors but it's damn helpful. Valgrind has also found multi-threaded locking problems in the latest version and numerous other bugs.

I also did a quick Valgrind "Heapcheck" run on the code. This checks how much memory it *actually* allocates, rather than trying to guess from what's left over in memory. STPPC2x uses very little memory, a lot less than I supposed. A single session that played over 50 games of various types never went much past 5Mb heap usage with the default config options. Although I consider that quite a large amount of memory for a basic game to use, I was quite impressed - that means that on default settings it uses less than 1/7th of the standard memory available on the GP2X.

I played with a few bits to enable background music. Unfortunately, the GP2X is a little underpowered and stutters on the difficult game generations, or if a move is particularly graphically-intensive. I'm sure there are ways around it with larger buffers, seperate threads etc. but for now I've put it on a backburner - it works, but it's not good enough yet.

The code loading game presets (i.e. difficulty levels) is working really well now - I haven't had a big problem in that code yet. As part of that, I've added a "special" preset which is an extension of the "save config" functionality of the older versions. Basically, you can save *your* favourite difficulty as a preset and have it load up every time you run that game by default. This did present a small logical problem though - what if you accidentally set it to a difficulty so hard that it takes the computer forever to generate the puzzle? You can't get into the game to change the option until it's generated the puzzle!

Fortunately, I've put in a little facility for that - pressing L&R on the list of games will delete your custom settings so that you can run the game with it's (safe) defaults. The keys and mechanism for this might change over time (for instance, I may have it so that if you start a game while holding down a certain button, it just ignores your config instead of removing it).

On the subject of correcting mistakes, I've also put in "Undo" and "Redo" buttons. These work fantastically and let you roll back and forth in the history of the game you're playing. It's something I never use in these games and nobody had asked for it, but the facility is there so it was only sensible to use it.

The new in-game menus are coming along nicely now - there are one or two layout quirks but nothing that can't be fixed and a few places where I really need to ask the user "are you sure?", but it's working well.

All in all, things are coming along smoothly and it's gradually looking more and more like a v1.0 release. I have a lot more "big" items on the agenda before that point but I'm very pleased with how much better it's looking now that I've had another spate of programming on the project.

Friday, 29 August 2008

STPPC2x v1.0 (Work in Progress Information Only)

It's been a while since I posted any updates here and in that time a lot of important things have happened within the GP2X community.

Most importantly, the GP2X has been discontinued (if you didn't know this by now, it was even on Slashdot's frontpage for a while!). This came as a great shame, but hardly a shock, to myself. However, I will be (and have been) continuing development as normal. I don't have an F-200, I don't have a Pandora (an "unofficial" GP2X successor-in-spirit), I don't have a Wiz (an official succesor). I can't afford any of them anyway. Until that situation changes, I'll be programming for the GP2X F-100 (with F-200 compatibility where I can manage it) and will keep programming. The GP2X rekindled my love of programming and I'll be both playing and coding on it until the day my personal unit dies. In fact, just lately I've been seriously looking at the prospect of buying another cheap F-100 second-hand if one comes up.

If I do suddenly manage to get any of those whizzy new machines, though, then I'll still be programming for the GP2X anyway - I prefer the challenge of programming for the lowest denominator. There is little fun in programming on a machine which just laughs at everything you throw at it (however, *playing* on it is another matter entirely!), and a set of 2D puzzles will never really stretch a powerful machine in practical use. So, I'll probably be leaving any Pandora/Wiz conversion of STPPC2x to someone else (to be honest, people would probably just use the official GTK versions on Pandora anyway, or their new Java ports).

That said, development slowed a little this month and last month but this was for completely unrelated reasons. What with a holiday and some end-of-term work at the school I work at, all programming activities took a back-seat. However, when I did get some programming time, I put aside my GP2X for a moment and attempted to update the Palm port of Simon Tatham's Portable Puzzle Collection, the code for which seems to have stagnated a little. However, this proved frustrating and, in the end, fruitless.

My wife has a Palm TX and we found that although the "official" Palm port of the puzzle collection works fantastically on a Palm Tungsten E2, the TX somehow ran the same executable differently. Most importantly, it often saw right-clicks instead of left-clicks all the time, no matter what options were set. This, obviously, made affected games absolutely unplayable. What was odd was that it only occurred in about 50% of the games and there was no way around it short of actually diving into the code and seeing what happened. Additionally, the Palm port doesn't include several of the games in STPPC2x and it would have been nice to get them working on Palm too, not to mention the various bug-fixes and new options that have been added since.

My attempts to recompile a test version of the Palm port proved much more difficult than I ever imagined. First, finding an appropriate build environment was nothing short of a nightmare - the SDK's are hidden away under obscure names that have changed since the README for the Palm port was written, contained only on websites that require arcane registration. After several hours (and some creative hacking), I was able to get a full suite of headers and compilers working. This is when the second and most damning problem showed up.

For some reason, the Palm has a very, very rigid memory structure and programs are written in segments of code that need to be of a certain size. No problem, the original Palm port took care of that with some ever-so-fancy scripting which tags functions so that they end up in seperate modules. With some creative tagging, all the modules are below the required size and they can all "talk" to each other - with nothing more than adding a function name to a script's datafile. However, because of the problems of getting the exact build environment that the original porter used, a straight compile no longer generates the same size code. Thus, a lot of the programs now need to be split into not just two but three or more segments, which greatly increases the complexity of compiling, linking and the various supporting scripts. In short, it's an absolute nightmare.

What started off as "I'll just compile this and see if I can find out what went wrong for Palm TX" turned out to be hours of frustrated downloading, hacking, patching, compiling of compilers followed by more hours of changing headers and filenames, editing scripts and lots of other fannying about just to get the original source code to compile once more in a useable fashion. After deciding to just speed things along and get the simple things running and work on the complex stuff later, I did get a working executable in the end, but without 40% of the games present in it because of the various code size changes and other problems. In short, it really wasn't worth the effort and was certainly useless for anything but a developer.

The frustration was so intense having fought to get to that point that I'd completely forgotten the original point of doing it all and in the end, never even got to looking at the relevant lines of code or whether a simple updated header could fix the problem. I would have spent 5% of the time fixing my problem and the rest just trying to get the original games back into a working state, let alone what would happen once I started introducing the new updates, games, etc. into the Palm collection. In the end, I left it for another day (month, year) and just kept hold of what I had downloaded/patched to get things working that much.

That meant that I was pretty sick of the Puzzle code for a while, although it was hardly the Puzzles' code that was at fault as much as the design of the Palm and/or the gcc compilers/linkers for Palm. Why all that can't be done automatically is beyond me but I'm sure there's a good reason, even if it's just "nobody got around to doing that". I tried other compilers and I tried searching for help but the answer was always the same "There's nothing we can do, split your code into smaller modules".

So, getting back to the GP2X (once I'd mustered some programming enthusiasm again) was an absolutely joy. Compile for x86. Link. Run on laptop. Compile for ARM. Link. Transfer to GP2X. Run. Rinse and repeat. Programming for the GP2X is a cinch in comparison and, more importantly, is intuitive and standardised. If something goes wrong, it's obvious and never anything to do with the compiler/linker being used. I ballsed up a Makefile once, so that things compiled oddly for ARM but okay for x86, but that's hardly anybody's fault but my own.

Unfortunately, my TODO list for the next (and probably "definitive") version of STPPC2x, with which I'm going to tempt fate and call v1.0, is very long but I am working steadily through it, even if I'm not putting out BETA's every month like I used to. A lot of the new stuff involves major infrastructure changes. The dodgy menu code that was thrown in with the intention of having some way to restart a game, and then changed to an actual menu to have some way to pause the game, and then changed to have some way to display the current options (in some of the most horrible code you'll ever see), and then repeatedly altered, bug-fixed and torn apart to fix some interface issues - well, let's just say that it's not going to be practical to extend it again and add the new options that I want to (such as using difficulty presets, etc.).

I've had a design for a new menu for a while and it'll look and work much better than the current one. We're talking a proper menu on the Pause button. With actual sub-menus. And actual proper changeable options. And an actual list of save-games. And an actual list of presets (including custom ones) that can be selected. And all without having to remember fifty keys or cramming it all into one screen.

It does involve touching some code that even I'm not sure I can remember how it works (I made a point of documenting the configuration-option stuff very heavily at the time, because I knew it would become a problem) so it's a big change to make that'll impact on a lot of things. However, all the "big stuff" is already in the code and it's just a matter of making it work in an intuitive way, in the right order, without bugs.

I need to factor out a lot of things to make the changes to the menu and thus there probably won't be many "preview" versions of the new code until it's finished: e.g. at the moment, you are "in the menu" or not, and the helpfile display "sub-menu" is a massive bodge. I need to change that so that you are "in menu number X" etc. so that the game only plays when you're not in a menu and options on sub-menus inherit from their parents etc. correctly and the key-press changes differ depending on the menu you're in etc.

It's a big job but I'm aiming for the magic 1.0 and I'm hoping to get it all working so that the program has that "professional" air to it, rather than the rather hackish backend hidden behind a nice PNG and some bash scripts that the user gets at the moment.

As a first step, I have integrated the "select a game" menu supplied by juanvvc into the main code. This is now just seen as "another type of menu" by the game, so it works much more closely and was a good way to see what sort of functions I need to have. This meant almost a complete re-write of that code but it now uses all the in-game functions to do its job rather than being a tagged-on executable that runs a script, that runs an executable to actually play the game. You won't notice, except that there are some tiny cosmetic changes such as the menu now showing the version number and being "part of" the main program.

Now one program is distributed and run, and the switch in and out of games is nigh-on instantaneous (However, it was pretty damn impressive before!). The Palm port was always the inspiration for this - it uses a so-called "Combined" executable (as does the MacOS port) that has all the games in it. That's now how the GP2X one works, too (after a massive migration from single-game-per-executable to monolithic-executable-that-can-only-run-one-game-at-a-time to the current "proper" combined monolithic executable). Additionally, it means that the "join" between the menu and the games is seamless - so, for instance, a music track could play across both without needing a jolt in between.

It does add a lot of complexities, though. For instance, it does mean that I have to check carefully for memory bugs because they will now accumulate if a player plays a long session of several games without quitting out of the thing entirely. I've already caught quite a few bugs that wouldn't have bitten people on the old menu but bite the second you change in and out of different the games themselves. There are also games which require a resolution change mid-flight if you run them - no matter how you play with them, some games run better in 320x240 and some in 640x480, so the menu has to know about them and switch between them. Fortunately, that's already done and dusted (although for some reason my PC has problems doing that same thing - I must update my SDL libraries!).

All these changes mean, however, that a lot of extraneous files and code can disappear and also that a lot of in-game facilities can make it back out to the menu. I'm hoping to eventually ship just one executable and the associated PNG's, helpfile TXT's and a single menu datafile. If I can manage it, I'd like to put everything but the executable into a single file (probably a ZIP or something) purely so that I can ship the minimum amount of files necessary.

The other thing that I'm working on as and when my mood changes is to have game "persistence". This was one of the things that working on the Palm port brought home to me - if you quit out of the game, you really should be able to go straight back to where you were just by running the program again. It's a bit like an "auto-save" whenever you leave one game and start another, or quit the game entirely.

It'll only work if you specifically leave a game, though, because otherwise it would involve writing to the SD card all the time which is something I want to avoid. Avoiding writes also means doing things like checking whether you've actually done anything to the game or whether you just hit the wrong game on the menu and then quit out straight away. If you didn't press a button, then there's no need to auto-save, which would save one "write" from hitting the disk. It also means that I have to be careful - what if that auto-save is corrupted, or what if it takes hours to load/redraw because it's a massive game? There has to be a facility for the user to ignore it. That means more menu options... All this adds extra code, simple though it may be, which needs careful positioning, checking and re-writing, so it all adds up. Like any big change, it'll be a option for people to turn off - for instance if they want to play on a write-protected card.

I also have some "bigger" items on the TODO list. One of them is to be able to stop a game halfway through generation. Unfortunately, this is quite a tricky one because the games are inherently designed to be single-threaded and non-interruptible while in generation (all the official ports suffer from this and the Palm port suffers especially badly). However, there are a few tweaks to the code that can be made to make them interruptible (even if it takes a few seconds for the interrupt to be "seen" by the program). It means adding code to each and every game, unfortunately, but I think it's a sensible thing to do because hitting a large Bridges game by accident could leave the user with no option but to kill the whole GP2X (or at very least telnet in and kill the process). That's an ugly way to play a game. And now that we have a nice integrated menu to fall back to, there's no reason it can't be done in a nice way.

I'm also pretty certain that the games just aren't drawing themselves properly, even though it's damn close. Other ports show clean lines on all resolutions but the GP2X has some overlap issues. This has been there since the start but I was always of the "it's playable" mindset before so I left it well alone. Unfortunately, without single-stepping the code or sitting down with some graph paper and manually following along, it's rather difficult to see where the problem lays. I'm guessing that there is an off-by-one error somewhere but there are so many "definitions" of the various graphics routines involved that it's hard to track down - does setting a clip rectangle of 10x10 at 5,8 mean that it extends from 5,8 to 15,18 or from 6,9 to 15,18 or from 5,8 to 14,17 or what? It looks likely that I misread something and made a small error between the translation of the puzzles concept of "clipping", "blitting", or "drawing" and SDL's concept of the same. This would fix such things as Solo's missing lines.

One of the other things I have added is massive amounts of debugging code, turned on by compiler options, which should be able to resolve such discrepancies once and for all. It's just a matter of running a debug-compiled version on the PC, capturing the megabytes of debug logs and then manually replicating them on graph paper to see what goes wrong and where.

Then, I have a few extra bits of "polish". I'm considering a musical background noise. I wouldn't normally bother but it's v1.0 and it's a very simple thing to implement. The games seem to have more than enough spare capacity to play music too (the Palm port is noticeably slower on similar-MHz models) and I've found a couple of relaxing background tunes on a Creative Commons site, so when I get bored of the dreary work, I'll plug in some code for that. I've also considered short sound effects for such things as entering a game, pausing it, pressing a menu, clicking within the game etc. None of these things will affect anything if the player doesn't want them - they will be easily turned on and off and may even be off by default.

There is also supposed to be a way to "write down" the definition of a puzzle, so that you can pass it to friends. This is implemented as "Copy" in the desktop versions of these games but I consider it a bit pointless in the modern age. If the GP2X could do Bluetooth or something easily then I would use it as a basis for a "Beam game" option similar to that present on many Palm games. As it is, I might implement it as a menu option purely because it's so simple to do (call one function, get the "answer" as plain text, display it on the screen) but I don't see anybody using it. With the new menus, it can be put there without getting in the way.

The puzzles also have "print" options, but I'm deciding to leave those out entirely because I very much doubt anybody would bother to print them off, and adding the whole Postscript-creation routines into the puzzles is a bit overkill for a function nobody will use and nobody can use easily anyway. You would have to "print" the puzzle to a PS, or possibly PDF, file on the SD card, take it to a desktop machine (which has its own port of STPPC which understands the same savefile format and can print direct) and then send it to a printer. Because it's achievable in an identical amount of time, with an identical process, just by moving a savefile over to the PC version, I'm leaving it out.

I'm looking at downclocking the GP2X when it's not being taxed (i.e. most of the time it's actually in-game or in the menus, but NOT during puzzle creation when the poor thing struggles along) but I've still to experiment and test this thoroughly (when testing, you want to get into the parts you know are buggy as quickly as possible!). There would be a problem if it decided to throttle itself back on a certain game which would actually benefit from going faster and so just frustrate the user for no reason. I don't know if and how it would affect battery life but I hope that running at a slower clock speed is actually better for power consumption that just idling at a higher clock speed. There is a lot of take account of, though, because the cursor-motion and input is tied to the speed of certain timers and it would be very bad if they started getting lagged or overwhelmed because of the number of events happening while it was running slower.

There are lots of other things that I want to do but they are either trivial, cosmetic, only affect the source code, or they really aren't worth mentioning. I don't know when v1.0 will be finished but it will be finished sometime - every time I find myself in a programming mood, I'm on the GP2X straight away. Every time I play the GP2X, I suddenly find myself hacking on the code.

All in all, STPPC2x has been great fun so far and it's only recently that I've actually figured out how to win all the games in it! I still don't succeed every time, and Tents and Blackbox are often the most surprising ones - you get to the end by applying what you think is perfect logic and then you just cannot fathom the answer. Sometimes you can get it by restarting that same game but sometimes you just have to reach for that Solve option and then you start kicking yourself!

I do want to get out a v1.0, something to say "this is a real port of the games", I want it to be polished, I want it to be complete and I want it to stick around with the GP2X. Probably nobody else will continue the port to other platforms based on this particular code (although a couple of people have borrowed the early SDL code that got the games to a playable state for things like PlayStation Portable ports etc.) because there's such an abundance of power in modern consoles to just run the original versions or simple modifications - there are even Java ports of the collection now. But to have hold of a classic games console, quite rare, quite unique, very open, and to have a copy of a polished port for it that I know I wrote - that's something I want to be able to do. I don't care if nobody ever downloads it or nobody else owns the hardware to run it, but I'd like to be able to show it to people and say "I did that".

In twenty years, I want to find my GP2X in a dusty old box somewhere and spot an SD card with "STPPC2x v1.0". I want to plug it in and show any kids I have: This is what I did. This is how we used to make computers work. This is the code and tools I used to do it. This is what a lot of companies "these days" try to make you think is done in a magic box at Microsoft. Look, despite it being 20 years ago, I can still load this stuff up, I can still know how it works, I can still fix it when it goes wrong. Let's have a quick game of it before I put it back.

Monday, 30 June 2008

STPPC2x Beta 5

The next step on my efforts to port Simon Tatham's Portable Puzzle Collection to the GP2X. This is now a set of 30 addictive logic and puzzle games (3 are new to this release!). Some are old favourites (like sudoku, sliding puzzles and minesweeper) and others you may not have seen before. An awful lot has changed in this release, not just some extra games, so make sure you read this whole thing!



You can download BETA 5 of STPPC2x immediately from the main website: http://www.ledow.org.uk/gp2x/ or from the GP2X archive (which may take a while to change from Beta4 to Beta5).

PLEASE NOTE: This release is a bit of a leap in how the collection operates. It is recommended that you create a new folder for this version - the directory structure has changed significantly. INI's and SAV's from previous versions are, of course, still compatible but may need a little renaming (same_game.ini to samegame.ini or rect0.sav to rectangles0.sav, etc.)

So, what's new? First, we have a fantastic menu drawn and programmed by juanvvc:



Many thanks to juanvvc for the great work on that, I think it really makes the collection look much neater and more professional. In fact, it works so well with the games that it is now the default menu, even on my own GP2X. Eventually, it'll get merged into the program itself so that there's just one piece of code for the whole thing.

The games are now just one program and one menu to run that program. If anybody still wants to be able to run each of the games individually as they did before, give me a shout, because I still test the games individually on my own machine. If there's demand, I can do two different releases - one with a single executable, one with an executable for each game.

There are also three new games: Slide, Sokoban and Maze 3D.

Slide is an "unfinished" game from the original collection that, as far as I can tell, is working perfectly but can be a bit slow to generate new games (if it takes a *long* while to startup or make a new game, don't worry - it hasn't crashed, it's just slow! I had to make a loading screen just so that this game doesn't make people think it's crashed!).

The object of the game is to slide the highlighted piece into the gated area by moving the blocks around. It sounds easy but it's not!



Sokoban is another "unfinished" game. I'm sure you have all seen this before - push each of the brown "crates" onto one of the circled areas. It is working perfectly but the levels it produces are randomly-generated and therefore usually very simple. But it plays well, so why not.



Maze3D is a third-party game from Eddy Macnaghten. You have to find your way through a 3D maze (2D if you change the options) to find the yellow sphere exit. It can be a little confusing at first. I recommend that you play mazes with "height" of 1 (i.e. a 2D maze) to get the hang of it, before trying smaller 3D mazes (e.g. 3 x 2 x 2, the smallest possible size). You can happily play up to 20x20x20 mazes (it's actually surprisingly fast to generate them), but you'll never find your way out of one that big without the help of the "solve" function, which puts a yellow thread on the screen which you have to follow to find your way out!



Maze3D isn't perfectly suited to the GP2X (it really needs a larger screen, and a better control system) but given that the code for it was last written in January 2006 and that I had to change one (trivial) line to get it to work on the GP2X, it's amazing it works at all! I also tweaked the code a bit more to allow me to put it neatly into the collection and to adjust the colours slightly.

I think Maze3D shows the power of these games as not just "a collection" but an entire puzzle game API that can be used to write lots of different games and get them ported to many platforms simultaneously, without having to write a single line of machine-dependent code. If anyone knows any other third-party games that use this puzzle engine, please shout. If anyone writes a new one that uses this engine (there is example code, documentation and I'll even give you a hand), shout louder!

STPPC2x has also been relicenced as GPLv2. This allows me to add in some useful code from various places. This was prompted by juanvvc thinking the collection was GPL and ended up with me deciding to change the license to GPL!

This beta now has 29 fully-working games, the only remaining one is completely unplayable on the GP2X - mines, a minesweeper clone. Don't run minesweeper - it'll crash. And yes, it's annoying the hell out of me as well that it doesn't work yet.

The full changelog from the previous Beta also includes items such as:

- A single monolithic executable for all the games.
This drastically reduces the size of the collection (from 17Mb to about 3Mb - mostly due to the fact that each game carried 0.5Mb of static SDL code with it). And eventually I'll be merging the menu with the games directly (at the moment, the menu spawns the games individually from the monolithic executable).

- A new "loading" screen because the new game Slide can take forever to load initially and people might think it has crashed.

- Several optimisations to try to reduce CPU use including: Faster and threaded events code, more compiler optimisations, making the main loop sleep a bit more, tricks like the loading screen to make people "think" it's faster, etc.

- Changed the background colour (well, I had to keep juanvvc happy after he made the menu for me!).
White lines are now more easy to see in Bridges, Inertia etc. The GP2X is just colour-inaccurate and the colour difference never showed up properly before (if you tilt the GP2X screen up on the older versions, you can see the white lines were always being drawn but showed as nearly the same colour as the background). I also had to change Maze3D's default colours because on a PC they look fine and on the GP2X, they all look white!

- Lots of tiny interface updates

Feedback is appreciated (especially from F-200 and USB mouse users) and full source code is available from:

http://www.ledow.org.uk/gp2x/

Note that this is an unofficial port - so please don't bother Simon Tatham with any problems, although he is aware of the project's existence.

There is also a "development blog", which will contain articles about developments to come etc. at http://stppc2x.blogspot.com

Monday, 2 June 2008

Beta 5 Sneak Preview Screenshots

Sneak previews of Beta5. Enjoy!







Sunday, 1 June 2008

Development update

I *am* still working on the collection!

In fact, there's a lot of exciting stuff going on, but I've been holding off on a release until they are ALL ready. I had a slight hindrance of a few hours work being lost but I've managed to recover or reproduce all of it without any problems (and even fixed a problem or two that I knew existed in the lost code, because I was able to start from scratch!).

Some sneaky news to keep people's interest:

New games. (!)
New menu for all the games.
New folder layout.
Better colours (so you can see elements clearer).
Interface cleanup - unsolveable games tell you so, games that can't enter numbers won't let you, made the first load of the in-game menu much quicker etc.

The current release-stopper is F-200 compatibility - I have an accurate way to reproduce all the issues seen with the F-200 touchscreen but it takes a lot of time to test each revision. Also, I'm holding back to see what's going on with the new model F-200's with regards to video/touchscreen co-ordinates being different. I still haven't fixed mines, either, and my patience is wearing out with it.

Anyway, I'm hoping to get a release out soon, even if it doesn't have F-200 touchscreen compatibility. So hang on. I'll get there.