SDL1 key mapping

I’m trying to port BlockOut2


using the source tarball and patches debian provides.
The game finally builds fine with minimal fixes and I can even play a game, but SDL key mapping for cursor keys (up, down, left, right) doesn’t match my keyboard (keypad keys work OK) and this prevents me from using any menus (no options, no start level, …).

In details:
into /boot/system/develop/headers/SDL/SDL_keysim.h I see cursor keys are mapped to codes 273, 274, 275, 276, instead from my keyboard the game receives codes 28, 29, 30, 31 (stuffed code with lots of printf to see this).

Is my keyboard not working properly? I’m building and testing the game into a VM.

Edit: keypad keys only work when in digit mode (NumLock enabled) because they have mismatched codes as well.

7 Likes

SDL1 exposes “native” keycodes that some apps and games use. These are platform-specific, but Linux and Windows port of SDL agree. So a lot of games are hardcoded to that. You will have to patch them for Haiku in that case.

2 Likes

I fixed the bug, adding a custom key handling when compiled in haiku, so now the game is fully enjoyable.

Now, is there a native meld in haikudepot?

4 Likes

You can try Ponpoko Diff but it’s not as complete as meld. It should be possible to get meld working now that we have GTK?

I was working on a port of the game as well for packaging into HaikuPorts, but ran into the keymap issue too. Could you submit a PR to HaikuPorts?

I’m going to :wink:

I’ve this first recipe for blockout2:

SUMMARY="3D falling blocks game"
DESCRIPTION="BlockOut II is an OpenbGL adaptation of the original BlockOut DOS \
game edited by California Dreams in 1989. BlockOut II has the same features \
than the original game with few graphic improvements. Score calculation is also \
nearly similar to the original Game. BlockOut II has been designed by an \
addicted player for addicted players."
HOMEPAGE="http://www.blockout.net/blockout2/"
COPYRIGHT="2007-2014 Jean-Luc Pons"
LICENSE="GNU GPL v2"
REVISION="1"

SOURCE_URI="https://salsa.debian.org/games-team/blockout2/-/archive/master/blockout2-master.tar.bz2"
CHECKSUM_SHA256="08b677be01c02e6695559ccc65df1cafcac0793b7864ba7e2285059babf57349"
SOURCE_DIR="blockout2-master/"

ADDITIONAL_FILES="
	fix_png_header.patch
	fix_and_optimize_makefile.patch
	keycodes_handling.patch
	locate_data_path.patch
	"

ARCHITECTURES="all !x86_gcc2"
SECONDARY_ARCHITECTURES="x86"

PROVIDES="
	blockout2$secondaryArchSuffix = $portVersion
	app:blockout2$secondaryArchSuffix
	"

REQUIRES="
	haiku$secondaryArchSuffix
	lib:libsdl$secondaryArchSuffix
	lib:libsdl_mixer$secondaryArchSuffix
	lib:libGL$secondaryArchSuffix
	lib:libglu$secondaryArchSuffix
	lib:libpng$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libsdl$secondaryArchSuffix
	devel:libsdl_mixer$secondaryArchSuffix
	devel:libglu$secondaryArchSuffix
	devel:libpng$secondaryArchSuffix
	"

BUILD_PREREQUIRES="
	cmd:gcc$secondaryArchSuffix
	cmd:find
	cmd:make
	cmd:patch
	"

PATCH()
{
	patch -i debian/patches/blockout2-2.4-alt-x86_64.patch -p1
	patch -i debian/patches/debian-kfreebsd.ftbfs.patch -p1
	patch -i debian/patches/debian_multimedia_paths.patch -p1
	patch -i debian/patches/fixed_all_gcc_warnings.patch -p1
	patch -i debian/patches/remove_unnecessary_libdeps.patch -p1
	patch -i debian/patches/ubuntu_fix_invalid_conversion.patch -p1
	patch -i debian/patches/ftbfs-with-libpng15.patch -p1
	patch -i debian/patches/spelling.patch -p1

}

BUILD()
{
	patch -i "$portDir/additional-files/fix_png_header.patch" -p1
	patch -i "$portDir/additional-files/fix_and_optimize_makefile.patch" -p1
	patch -i "$portDir/additional-files/keycodes_handling.patch" -p1
	patch -i "$portDir/additional-files/locate_data_path.patch" -p1

	make $jobArgs -f debian/Makefile
}

INSTALL()
{
	mkdir -p $appsDir/Blockout2
	cp -rf BlockOut/images BlockOut/sounds $appsDir/Blockout2
	cp obj/blockout2 $appsDir/Blockout2/Blockout2
}

It takes the source code from debian repository, applies debian patches and then applies mine - then builds and installs the stuff.
Now, everything works
BUT
I really don’t like patching the source from within the “BUILD” block - indeed, I found it is the only block where the script can detect my additional 4 patches. Is there a way more elegant than this?

1 Like

The PATCH() function you used is generally meant for patching manually using cmd’s like sed and the like, you should instead create a subdir named patches and put all your patches inside it, then create a section in the recipe named PATCHES under the SOURCE_DIR section and list all those patches in it without the patch -i cmd, haikuporter will then apply them for you.

There’s a page in the HaikuPorts wiki on patching with HaikuPorter:

The workflow is usually something like this:

  1. Apply patches to work directory
  2. git add .
  3. git commit -m "put patchset message here"
  4. Go back to recipe directory
  5. haikuporter -e pkgname-version
  6. Add PATCHES="pkgname-$portVersion.patchset to the recipe near ADDITIONAL_FILES

Change libsdl to libSDL_1.2, libsdl_image to libSDL_image_1.2

Issue for this is at: libSDL* recipes needs cleanup for lib:libSDL*_* · Issue #3878 · haikuports/haikuports · GitHub

1 Like

Fixed, thanks.

The issue with the PATCHES block is the execution order: when I tried using my patches into that block, haikuporter takes them BEFORE debian patches, when they should be applied over debian’s
And into PATCHES I cannot point to a patch inside the tarball, as blockout2-master/debian/patches/patch1.patch

On first run, put the debian patches only in PATCHES, run haikuporter -b option (extracts, patches but doesn’t build).
Make the needed changes from your patches, save the files (deppending if you want seperate commits)
Run git diff in the sourcetree, it should show the changes made only by you, git commit -a to add a commit message to it, and to end, haikuporter -e (extracts the patchset for you in PATHES with the ones you already did from debian, so in the end you should end up with 1 patchset).

Hope this is clear enough :wink:

2 Likes

Done.

4 Likes