cxong / cdogs-sdl

Classic overhead run-and-gun game
https://cxong.github.io/cdogs-sdl/
GNU General Public License v2.0
891 stars 114 forks source link

Support for custom/system data dir #402

Closed akien-mga closed 7 years ago

akien-mga commented 8 years ago

Hi there,

I package cdogs for Mageia but I'm having trouble packaging recent versions (currently Mageia still ships 0.5.7). I've managed to unbundle libenet and yajl relatively easily, but there does not seem to be support for loading data at the system-wide level, e.g. installed in /usr/share/games/cdogs-sdl/, it always looks for data in ../data.

Two questions:

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

cxong commented 8 years ago

I think you can set CDOGS_DATA_DIR in cmake i.e. cmake -DCDOGS_DATA_DIR=/path/to/dir ..., see https://github.com/cxong/cdogs-sdl/blob/master/CMakeLists.txt#L116-L123

I don't use this option myself though, haven't really tested it. Please try it out and let me know if it's broken.

akien-mga commented 8 years ago

Oh, thanks, somehow I missed it. I'll try and report back.

akien-mga commented 8 years ago

It seems not to work out of the box, the C code must be prefixing the pwd somewhere:

internal error: cannot create temp file /home/akien/Mageia/Checkout/cdogs-sdl//usr/share/games/cdogs-sdl/data/gamecontrollerdb.txt
Internal error: cannot delete temp file /home/akien/Mageia/Checkout/cdogs-sdl//usr/share/games/cdogs-sdl/data/gamecontrollerdb.txt
Cannot resolve relative path /home/akien/Mageia/Checkout/cdogs-sdl//usr/share/games/cdogs-sdl/data/gamecontrollerdb.txt: No such file or directory

I defined -DCDOGS_DATA_DIR=/usr/share/games/cdogs-sdl/

akien-mga commented 8 years ago

Indeed, it's done here: https://github.com/cxong/cdogs-sdl/blob/master/src/cdogs/utils.c#L360

akien-mga commented 8 years ago

I hacked away the $cwd/ from the path and now the game starts up fine. I'm still getting many warnings which hint that the current C-Dogs might not be designed to work with a read-only data directory:

internal error: cannot create temp file missions/AntiHukkanen/trilogy/CORPS.CPN
Internal error: cannot delete temp file missions/AntiHukkanen/trilogy/CORPS.CPN
Cannot resolve relative path missions/AntiHukkanen/trilogy/CORPS.CPN: No such file or directory
internal error: cannot create temp file missions/AntiHukkanen/trilogy/GANGS.CPN
Internal error: cannot delete temp file missions/AntiHukkanen/trilogy/GANGS.CPN
Cannot resolve relative path missions/AntiHukkanen/trilogy/GANGS.CPN: No such file or directory

and so on for all missions and dogfights.

The fact that it tries to create temp file is a bit surprising, but is it just a fallback of the way you're trying to open files (I'm not so familiar with C)? I can see that e.g. /usr/share/games/cdogs-sdl/missions/AntiHukkanen/trilogy/GANGS.CPN is a file which is properly installed, so:

cxong commented 8 years ago

Please try again with the latest master revision. The data files can be read-only.

akien-mga commented 8 years ago

Thanks, it's working great :) I've now updated my Mageia package to a current snapshot of the master branch: http://svnweb.mageia.org/packages/cauldron/cdogs-sdl/current/SPECS/cdogs-sdl.spec?view=markup&pathrev=1003133

I'm using a couple patches to have make install behave as I wanted, as well as unbundle enet and yajl, but I need to find some time to make them less intrusive if I want to push them as a PR (especially for enet and yajl, I should ask CMake instructions to look for the system-wide package before decide to use the bundled version or not):

carstene1ns commented 8 years ago

Thanks, this also allows me to update my Arch Linux package! :+1: