Thursday, 28 April 2016

A custom launcher

I know that lots of emulator front-ends already exist, but designing my own was part of the fun of the project :-) My aims were to :
  • Have a nice-looking, pixel-based, GUI
  • Be able to filter games by number of players / type of game / machine
  • Have a simple database, with no need for a network connection for updates
  • Discover the SDL library


Once again, I did not intend to share it at the beginning of this project, but I do it nonetheless for the few curious ones. I made a few modifications for sharing (made some parameters easier to change from within a .h header rather than hard-coded), but this is far from being the level of quality of an actual product (few comments, some stuff is still hard-coded, and lots of other things).

Anyway, I am quite happy with the final look and feel.

You can get the source code on my github account.

Here are some details for those who wish to adapt the code for their own use:
  • Compile with Modifying it should be straightforward if you have already compiled something with gcc.
  • I have exposed a few macros in defines.h that you may want to adapt:
    • PIXBOX_WIDTH and PIXBOX_HEIGHT define the screen size. Set it to your own resolution (mine in 1280x720, adapted to TVs, and much faster than 1920x1080)
    • NUM_GAMES is the maximum number of games exposed at once
    • RESOURCE_PATH is the path to the files containing the resources used by the GUI: list of games ("database"), pictures, sounds.
    • TEXT_*: the texts to display. Mine are in French, but you can easily change them
  • You can adapt the positions of the elements, the colors etc in GraphicElements.cpp, in GraphicElements::Private::Private().
  • You can adapt the keys used in the GUI by editing PixBox.cpp (void PixBox::mainLoop()), check all the "case SDLK_*". Yes, you'll see mentions to a third player, but that's another project :-)
  • It also compiles and runs nicely on Windows. This could come in handy, I used it for most of the development.

Games database

As for the database, this is quite simple, actually. It is a csv file (comma-separated values), each column being one kind of info. To make things simpler, I also introduced a system of macros, to make things easier to read.
A sample is provided in the resources folder on the GUI repository.
The file is read line by line
  • If the line starts with PREPARE, this is a command to run at startup. e.g.
    • PREPARE;cp /media/BBB/pixbox/config/config2.cfg /root/.picodrive/;
  • If the line starts with MACRO, this is a macro, a replacement for another string. e.g.
    • MACRO;<GG>;advmess gamegear -cart
    • When calling "<GG>", the command "advmess gamegear -cart" will be executed. The macros are concatenated, don't forget to add space characters where needed!
  • If the line starts with "#", this is a comment, the line is ignored
  • Otherwise, the lines are read field by field as follows:
    • Field 1: Full game name
    • Field 2: Short game name (for display in the games list)
    • Field 3: Sorting key. This may be different from the title (e.g. you may want to display "Ultimate Mortal Kombat 3" next to "Mortal Kombat 3", just give them keys such as "mortal-kombat-3" and "mortal-kombat-3-u")
    • Field 4: Type of game. Any string, that will be used to sort the game in the "type" area of the GUI
    • Field 5: Machine. Any string,  that will be used to sort the game in the "machine" area of the GUI
    • Field 6: Max number of players: 1, 2, 3
    • Field 7: Game family. Any string, that will be used to sort the game in the "family" area of the GUI (think "Batman", "Disney", "Shinobi", etc.)
    • Field 8: Artwork: Path to an image to display, if any. There may be glitches if no artwork provided (wrong artwork displayed)
    • Field 9: Command line to start the game

Finally, the "database" must be in Unix text format, with lines ending with "\n", and NOT "\r\n" (see wikipedia for more info on this matter). If you edit your file on Windows, think of passing it to dos2unix (available on cygwin or MobaXterm) before sending it to your BeagleBone Black.

No comments:

Post a Comment