Linux port of DSB

This forum is for the Lua scriptable clone of DM/CSB called Dungeon Strikes Back by Sophia. Use DSB to build your own highly customised games.

Moderator: Sophia

Forum rules
Please read the Forum rules and policies before posting.
Post Reply
marek_tempe
Neophyte
Posts: 7
Joined: Sun Feb 03, 2019 10:08 am

Linux port of DSB

Post by marek_tempe »

Hi, I discovered DSB just a few weeks ago. I think it's a great project and having a Lua-scriptable DM clone is a fantastic idea. Thanks Sophia!

Since I'm not a Windows user and since DSB sources are available (Thanks Sophia!), I decided to try to port DSB to Linux. After few evenings I was able to build the engine and play the test dungeon.

I was not able to port everything in a couple of hours. I couldn't find matching Linux version of the FMOD library (and didn't want to use non open source library anyway) so I've just disabled all sound-related code. Other things that do not work at the moment are (1) resuming games (DSB crashes) and (2) semaphore-based timing (I'm not even sure what is this). Both things should not be hard to fix and (1) is critical so I plan to look into this maybe next week. On the other hand, sound implementation from scratch is a lot of work and I don't think I will ever have resources to do it.

The code for the Linux port, with building instructions that work on my machine, is here: https://github.com/marek-tempe/DSB/tree/linux
User avatar
Sophia
Concise and Honest
Posts: 4240
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Re: Linux port of DSB

Post by Sophia »

Hey, this is great! :mrgreen:

If you want sound, you won't necessarily have to implement stuff from scratch. Allegro includes its own sound code, which is generally not as good as FMOD (which is why I don't use it) but since you've got Allegro anyway, you could possibly use its sound functions instead. I'm actually not sure if it's going to work, since I'm not sure that Allegro supports everything I do in FMOD, but it might be worth looking into if you feel like it. There definitely isn't native Allegro support for 3d sound, but you could possibly do that quick and dirty by just messing with the volume based on the distance given.

Anyway, by semaphore-based timing, I mean that the main thread of DSB sits and waits for a semaphore, while a different input/timing/whatever thread that is managed by Allegro signals that semaphore at a nice consistent 35hz, so DSB runs at a consistent pace. It is the current preferred method of timing the Windows version of DSB, because I've found out the hard way that the old QueryPerformanceCounter-based method is not too great. However, if you've got something better on Linux, you might not need to bother with it.

There isn't really any non-portable code in resuming the game (as far as I know) so this may be a bug in my own code. If you can tell me what line of code it crashes on, I can maybe help.
marek_tempe
Neophyte
Posts: 7
Joined: Sun Feb 03, 2019 10:08 am

Re: Linux port of DSB

Post by marek_tempe »

Thanks for the tips! As for the sound, I will give Allegro a try but I can't promise anything.

As for the semaphore timing, it would be good to have it working also in Linux if only for the consistency with the Windows code (in case the main Windows version will rely on this more in future).

I've found out that the crash on resuming a game is caused by some code in function load_savefile() in file.c: the line

Code: Select all

 rdl(gd.dungeon_levels);
sets gd.dungeon_levels to -1. Then there's the call dsbcalloc(gd.dungeon_levels, sizeof(struct dungeon_level)) which results in a crash, since the first argument is interpreted as max int.
marek_tempe
Neophyte
Posts: 7
Joined: Sun Feb 03, 2019 10:08 am

Re: Linux port of DSB

Post by marek_tempe »

Looks like the savegame files are corrupted, I cannot list their contents with the 'dat' command distributed with allegro (data files that come with DSB can be examined with 'dat' without problems). I will investigate this.

Oh, and I forgot to mention that only DSB is ported, not the editor.
User avatar
Sophia
Concise and Honest
Posts: 4240
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Re: Linux port of DSB

Post by Sophia »

DSB savegames use the Allegro packfile format because they're compressed (they were kind of big by 2007 standards) but they're not actually proper Allegro data files.

I think looking into corrupt save files is a worthwhile thing to do, anyway, though-- if it thinks that there are -1 dungeon levels, then it's probably just reading a -1 from the file and that means something is going very wrong. What is pretty interesting to me is that there are several consistency checks before it gets to this line, and it will quit (via the somewhat colorfully named poop_out function) if any of them are failed.

I figured the editor wasn't ported. It contains a lot of Windows API calls (since it's much more of a proper Windows app than DSB) so porting it would be much more difficult. :mrgreen:

EDIT: I think I've got a good lead on where the problem is. When saving a game, it runs this code:

Code: Select all

    write_all_sounddata(pf);
    
    W_CHARS(255, 255, 255, 255);   
    wrl(gd.dungeon_levels);
Loading a game mirrors this structure:

Code: Select all

    read_all_sounddata(pf);
           
    rdl(v);
       
    rdl(gd.dungeon_levels);
So, immediately before gd.dungeon_levels is stored, it stores what will be read as a -1 if it is loaded as a 32-bit int... and that is what is getting read! And immediately before that it is writing out the sound data. So my best guess is that in your removal of FMOD you broke either write_all_sounddata or read_all_sounddata.
marek_tempe
Neophyte
Posts: 7
Joined: Sun Feb 03, 2019 10:08 am

Re: Linux port of DSB

Post by marek_tempe »

Good guess! I've ifndef-ed out the code in read_current_music_info since it contained some FMOD references, but not in write_current_music_info. This is now fixed and loading works.

So the savefiles are not compatible at the moment between Windows and Linux versions, since the latter are missing the music info (and probably for other reasons that I don't know yet). This will be the next thing to fix.
marek_tempe
Neophyte
Posts: 7
Joined: Sun Feb 03, 2019 10:08 am

Re: Linux port of DSB

Post by marek_tempe »

Hi, I've reimplemented some sound routines using the SDL Mixer 2.0 library. I couldn't play sound samples correctly with Allegro 4 in my system, the output was terrible, the sampling rate plainly incorrect. Allegro 5 handled the samples well but instead of using Allegro 5 for sound and Allegro 4 for everything else I've decided to go with SDL Mixer which is more popular and probably simpler than Allegro 5.

Some sound functions are not implemented yet, in particular freezing/unfreezing sound when ESC is pressed and reading/writing sound data when saving/resuming game.
User avatar
Sophia
Concise and Honest
Posts: 4240
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Re: Linux port of DSB

Post by Sophia »

I've just released DSB 0.74, and updated the DSB git repo accordingly.

(The old repo was a bit out of date, because nobody had actually done anything with the DSB source code before you made your Linux port, so I was kind of unmotivated to keep up with it. This change actually contains all the changes from DSB 0.71 to DSB 0.74. Everything's up to date now, though!)
marek_tempe
Neophyte
Posts: 7
Joined: Sun Feb 03, 2019 10:08 am

Re: Linux port of DSB

Post by marek_tempe »

Thanks Sophia, the linux port is now up to date with DSB 0.74.
Post Reply