GameDevelopment

This page contains useful tips on game development with 770 and also about SDL library in general.

MoinMoinWiki Macro: TableOfContents

Useful tips

Misc notes

  • Internet tablets use a touchscreen, which enables new ways to implement game-features, such as on-screen buttons, in-game drawing, moving character by tapping screen. etc.
  • Since the device does not have any buttons on right side, implement those in software!
  • Avoid using the 4 way rocker for fast and complex movements. It's not well suited for gaming.
  • When using screen's vertical orientation (as in tetris) think other use for esc button than exiting game. It's so close to the rocker that accidental presses will happen.

SDL specific notes

Things to remember: * The screen is natively 800x480. No resolution changes are supported. Maybe in the future we might have support for 400x240 res for faster graphics but this is quite unlikely. If trying to set fullscreen window smaller than the native screen size, you will just have black borders. * In windowed mode matchbox will force the window to certain size (you should look at the UI specifications to see the actual window size). This means that you will have those black borders if your requested window is smaller than the actual window. * Generally SDL windows (not fullscreen) look quite bad with the theme if nothing for the theme is done inside the SDL window, but it's up to you to decide. * Prefer not to do full screen updates. The screen is 80048016 and the hardware capabilities aren't so great (the video hardware cannot do anything). If you still have to do these for some reason, you should make the area smaller (eg having some statusbar or any GUI elements which doesn't need to be updated each time). Also do not use SDL_Flip(), since it will update whole screen. Use rect updating functions instead. Thank you. * 32 bit mode doesn't work. The reason was that there was a bug that caused SDL to segfault when you had 32 bit window and you recreated the window. Since the display is only 16 bit, there is no reason to support 32 bit mode, which would just give extra round of pixel conversion and therefore slow things down. Convert your images on loading to native 16-bit with SDL. * Mouse events. There is touchscreen, and you can't assume average end user Billy-Bob would hack the device to USB host mode and use the USB mouse. So use absolute coordinates as much as possible. One example where relative coordinates are used is scummvm. If you use keypad to move the cursor, and then use the touchscreen, the actuall cursor will be at offset from original touchpadpress. Think absolutely, not relatively ;)

Utilizing pixel doubling inside SDL

NOTE This currently only applies to the 770.

As there is support for pixel-doubled drawing to the screen inside the HW, there is implementations to utilize that up to X. So if you want to use it you have to do some xlib code, therefore it might be a good idea to put this small piece of code to switch pixel doubling mode to a separate file.

What is pixel doubling?

In brief the pixel doubling is something that is enabled or disabled. When it's enabled, all draws to the display (in particular with SDL SDL_Flip() and functions to update rects on screen) are doubled. This allows lower-quality graphics to be drawn partially on the screen (for example you can have high-res statusbar and low-res game area inside the game). The benefits? Speed. Doing full screen updates waste the memory bandwidth and are therefore slow. With doubling, you would need to transfer 4 times less image data.

In general, you should remember that don't update areas which would exceed doubled coordinates 400x240 and try to keep the doubling on as minimum as possible since if somedoby else draws something (like infoprints), thay can be quite "artistic". Please also note that when you have mouse (or touchscreen) cursor enabled, X will redraw something when you tap the screen (I suppose somebody could file a bug against this).

WARNING If your game suddenly crashes (or exits cleanly) while pixel doubling is still on, currently it will be left on until somebody switches it off. This means that you will have artistic desktop. Nothing is known about improving this as the pixel doubling is unofficial feature.

Please be aware that this feature was designed for scaling video-player videos (drawn by dsp, not X) and there will be no support for SDL. It is enough to cause a reboot that user presses homekey or powerbutton during the game since the UI is unusable after this. This can be avoided little bit by reacting to SDL active events, if somebody else gets active status, switch immediately doubling off.

Howto use it

There exists one X extension (Xsp), which can be used for that. Sample piece of code with SDL:

#include <X11/Xlib.h>
#include <X11/extensions/Xsp.h>

#include <SDL/SDL.h>
#include <SDL/SDL_syswm.h>


void set_doubling(unsigned char enable)
{
  SDL_SysWMinfo wminfo;
  SDL_VERSION(&wminfo.version);
  SDL_GetWMInfo(&wminfo);
  XSPSetPixelDoubling(wminfo.info.x11.display, 0, enable);
}

Note that when you compile it you have to include X include path and link this with libXsp (-lXsp).

Application name (for the Task Navigator)

Set the window title using

SDL_WM_SetCaption("title", NULL);

Maemo Task Navigator (list of open programs) identifies non-Maemo programs (like pure SDL apps) by matching StartupWMClass-variable in .desktop-file and the application "window manager class" name. By default all SDL apps have the name "SDL_App". This can be changed with environment variable SDL_VIDEO_X11_WMCLASS.

  • Alternative 1: Here's an example: app.bin is the binary executable. app is the startup script, printed here:
#!/bin/sh
BASENAME=`basename $0`
export SDL_VIDEO_X11_WMCLASS=${BASENAME}
exec ${0}.bin "$@" 

app.desktop is the desktop file:

[Desktop Entry]
Encoding=UTF-8
Version=1.0
Type=Application
Name=The Application
Exec=/var/lib/install/usr/bin/app
Icon=app
X-Window-Icon=tn-bookmarks-link
X-Osso-Type=application/x-executable
StartupWMClass=app
Terminal=false

Notice that StartupWMClass == SDL_VIDEO_X11_WMCLASS, and that Exec points to the script, not binary.

  • Alternative 2: An other possibility that doesn't need a script is the following. Put the line
putenv("SDL_VIDEO_X11_WMCLASS=appexename");

in your code. A good position is directly after the main() function. In this case your control file should directly point to the application name. So there's no need for a helper script.

Useful links

http://www.libsdl.org/

http://www.gamedev.net/

http://2dnow.zenzer.net/

Screenshots of 770 game projects

platform game engine

Simple 2D platform game engine containing tilemap and sprite-handling, bounding-box collision detection + other stuff. (Will have some simple light effects, which can be preblitted on top of tilemap/background picture.)

http://cs.joensuu.fi/fi/tpalli/lshot2.png> -------------------------------------- | -----------------------------------------

test program

INDT Game Ports & development Screenshots

Those are small ports & developments made for maemo. All of them will be available for download to serve as reference for game development. Dbus integration, SDL or GTK games, Multiplayer features using wifi and bluetooth, optimization techs and some documentation will be also available.

Doom Port(SDL BASED )

After fixing some bugs related to texture loading ( on Arm it fails ) and creating a custom GUI for pen based gaming it's ready. Playing it full screen is FAST! REALLY FAST. Sounds effects are fine, better with headphone.

http://www.marceloeduardo.com/blog/up/maemo_doom_final_small.jpg

Doom

Battle Gweled

Wifi multiplayer gweled game ( base on bejeweled classic ) User must do 3 or more stone sequences to increase powerbar, after some seconds idle a strike is done on the enemy.

http://www.marceloeduardo.com/blog/up/battlegweled.jpg

splash screen

http://www.marceloeduardo.com/blog/up/battlegweled2.jpg single Player screen

Crazy Parking

Based on the famous rushour game, you must move cars away to make the way out clear for you machine!

http://www.marceloeduardo.com/blog/up/crazyparking.jpg

Maemo Blocks

Classic blocks game, no explanations needed =). A must have for any platform.

http://www.marceloeduardo.com/blog/up/maemoblocks.jpg

you can play with the 4-way rocker or grabbing the pieces with the stylus

Maemo Sweeper

Ported from SDLMINE http://www.libsdl.org. another Classic!

http://www.marceloeduardo.com/blog/up/maemosweeper.jpg

http://www.marceloeduardo.com/blog/up/maemosweeper_startup.jpg

~- example of the game start up screen -~

Ice Breaker

Ported to maemo! http://www.libsdl.org. really fun to play with the stylus.

http://www.marceloeduardo.com/blog/up/icebreaker.jpg

em Português"