nimPoP: a SDLPoP port in Nim

Open-source port of PoP that runs natively on Windows, Linux, etc.
Post Reply
BarrOff
Scholar Scribe
Scholar Scribe
Posts: 3
Joined: December 30th, 2020, 12:52 am

nimPoP: a SDLPoP port in Nim

Post by BarrOff »

Hello everyone,

SDLPoP is a great project that still gives me many hours of joy.

Some time ago I discovered the Nim programming language and have been privately using it since about the 1.0 release regularly for different purposes. While looking for a project to deepen my understanding of the language and what it offers the idea of rewriting SDLPoP somehow entered my mind and stayed. As Nim transpiles to C and has a great SDL2 wrapper I thought why not give it a try?

So nimPoP was born.

Since then I have learned a lot about not only Nim, but also SDL2 and deepened my C knowledge. As Nim does different runtime checks I also discovered some small errors in SDLPoP and could contribute some fixes.

This is a side project for me, mainly for fun and educational reasons.


Current status

The recording/replay and screenshot features are currently not implemented. I will add them when the base is stable enough. My focus is currently on fixing the remaining bugs.

The basic structure of the C source code has been mirrored in Nim by now. The game is playable, but there are still some bugs atop the ones from SDLPoP. The major issues are currently:
  1. The audio is only working when using the

    Code: Select all

    stdsnd
    command line option when starting nimPoP. Otherwise the game crashes upon loading a level.
  2. Enemies can't follow the Prince into another room
  3. The sprites for enemies aren't displayed correctly
I have been investigating the first one for quite some time now, using lldb, valgrind, cppcheck but to no avail. Initially I intended to announce nimPoP after fixing the issue, but as I seemingly can't find the reason I still announce it now. Help finding the reason of this bug would be really appreciated!


How to give nimPoP a try?

Linux binaries are offered on the release page. They were compiled on Debian using the development version of Nim. Therefore you don't need to modify the SDLPoP.ini file. However given the different Linux flavours I can not guarantee they will work on all distributions.

If you want to compile nimPoP from source, here is a step by step guide:
  1. Make sure Nim is installed properly. For this please refer to the official installation instructions. If you are using Windows, please make sure to run the finish.exe to install an accompanying C compiler for Nim. Also make sure to adjust the PATH variable according to the instructions given there.
  2. run the following two commands:

    Code: Select all

    nimble refresh
    nimble install https://gitea.com/BarrOff/nimPoP.git
    
  3. nimPoP should now be installed in the users "nimble/bin" folder. If you followed the installation instructions for Nim, this should be in your PATH.
  4. Change to the directory of your SDLPoP directory
  5. When not using the current development version of Nim, there is a small change to the SDLPoP.ini file, located in the game data folder, because of this bug in the Nim standard library. The file ends with 16 section names of the pattern \[Level x\], where x is a number between 0 and 15. You need to remove the spaces between 'Level' and 'x' for the program to start correctly.
  6. you should now be able to start the program by running the command

    Code: Select all

    nimPoP stdsnd
    
The source code can be found here containing some more informations.

Feedback is welcome!

Credit

I want to thank the following people, without them nimPoP wouldn't have been possible:
Last edited by BarrOff on April 17th, 2021, 11:03 pm, edited 2 times in total.
User avatar
atrueprincefanfrom18
Site Shah
Site Shah
Posts: 1786
Joined: January 21st, 2020, 2:53 pm
Contact:

Re: nimPoP: a SDLPoP port in Nim

Post by atrueprincefanfrom18 »

This sounds really cool!
Can the "how to compile" instructions be more clearer? I didn't understand how to compile. I definitely want to give this a try! :)
Love to create new MODS :)

My complete list of mods until now!

My channel. Do consider subscribing it! :)
BarrOff
Scholar Scribe
Scholar Scribe
Posts: 3
Joined: December 30th, 2020, 12:52 am

Re: nimPoP: a SDLPoP port in Nim

Post by BarrOff »

I have updated the introductory post with a short step-by-step instruction list.
Please let me know if this helps.

Are you using Linux, Windows or MacOS?
User avatar
atrueprincefanfrom18
Site Shah
Site Shah
Posts: 1786
Joined: January 21st, 2020, 2:53 pm
Contact:

Re: nimPoP: a SDLPoP port in Nim

Post by atrueprincefanfrom18 »

BarrOff wrote: April 17th, 2021, 1:41 pm I have updated the introductory post with a short step-by-step instruction list.
Please let me know if this helps.

Are you using Linux, Windows or MacOS?
Thanks. I'm using Ubuntu 18.04. I couldn't perform #2 step. I'm getting these errors:

Code: Select all

Downloading https://gitea.com/BarrOff/nimPoP.git using git
   Warning: Package 'nimPoP' has an incorrect structure. It should contain a single directory hierarchy for source files, named 'nimPoPpkg', but file 'seg004.nim' is in a directory named 'nimPoP' instead. This will be an error in the future.
      Hint: If 'nimPoP' contains source files for building 'nimPoP', rename it to 'nimPoPpkg'. Otherwise, prevent its installation by adding `skipDirs = @["nimPoP"]` to the .nimble file.
  Verifying dependencies for nimPoP@0.1.6
       Tip: 1 messages have been suppressed, use --verbose to show them.
     Error: Unsatisfied dependency: nim (>= 1.4.2)
Love to create new MODS :)

My complete list of mods until now!

My channel. Do consider subscribing it! :)
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5749
Joined: April 9th, 2009, 10:58 pm

Re: nimPoP: a SDLPoP port in Nim

Post by Norbert »

atrueprincefanfrom18 wrote: April 17th, 2021, 1:57 pmThanks. I'm using Ubuntu 18.04. I couldn't perform #2 step. I'm getting these errors:

Code: Select all

[...]
     Error: Unsatisfied dependency: nim (>= 1.4.2)
Probably you can do:
$ sudo apt install nim
User avatar
atrueprincefanfrom18
Site Shah
Site Shah
Posts: 1786
Joined: January 21st, 2020, 2:53 pm
Contact:

Re: nimPoP: a SDLPoP port in Nim

Post by atrueprincefanfrom18 »

Norbert wrote: April 17th, 2021, 2:05 pm Probably you can do:
$ sudo apt install nim
Have done it, in vain.
Did you try it?
Love to create new MODS :)

My complete list of mods until now!

My channel. Do consider subscribing it! :)
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5749
Joined: April 9th, 2009, 10:58 pm

Re: nimPoP: a SDLPoP port in Nim

Post by Norbert »

atrueprincefanfrom18 wrote: April 17th, 2021, 2:25 pm
Norbert wrote: April 17th, 2021, 2:05 pm Probably you can do:
$ sudo apt install nim
Have done it, in vain.
Did you try it?
This has a similar issue as MININIM had (has?), where it relies on very recent lib/lang release(s).
Your nim is most likely 1.0.6 instead of 1.4.2, and as a result the process fails.
If you modify nimPoP.nimble to accept 1.0.6, you'll then run into nim-crc32 requiring 1.4.2.
The best solution is for the developer to make the package work with 1.0.6 or newer, instead of expecting each user to struggle through this.
(Of course, in my opinion.)
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5749
Joined: April 9th, 2009, 10:58 pm

Re: nimPoP: a SDLPoP port in Nim

Post by Norbert »

Norbert wrote: April 17th, 2021, 2:42 pmThis has a similar issue as MININIM had (has?), where it relies on very recent lib/lang release(s).
Your nim is most likely 1.0.6 instead of 1.4.2, and as a result the process fails.
If you modify nimPoP.nimble to accept 1.0.6, you'll then run into nim-crc32 requiring 1.4.2.
The best solution is for the developer to make the package work with 1.0.6 or newer, instead of expecting each user to struggle through this.
(Of course, in my opinion.)
Alternatively, the documentation could include instructions on how to first obtain a recent nim release through cloning its repo.
Maybe Ubuntu has a very old version of nim? Or maybe nim simply isn't mature enough?
[Edit: Apparently, 1.0.6 is from 24 January 2020. And nim 1.0.0 from Sepember 2019. So, it's not that mature, it looks like.]
BarrOff
Scholar Scribe
Scholar Scribe
Posts: 3
Joined: December 30th, 2020, 12:52 am

Re: nimPoP: a SDLPoP port in Nim

Post by BarrOff »

Sorry to see this. I recently had to bump the required Nim version to 1.4.2 because of nim-crc32 as has been stated before. I have been looking for another way. There is the nim-fletcher package also providing crc32 functionality, but it has had no development since 2019 and I would like to avoid that.
Norbert wrote: April 17th, 2021, 2:42 pm The best solution is for the developer to make the package work with 1.0.6 or newer, instead of expecting each user to struggle through this.
(Of course, in my opinion.)
According to recent statistics more than 85% of Nim users use the latest version of 1.4.x or newer so I assumed the bump would be ok. I also link to the official installation instructions of Nim, which would install a recent enough version. Nevertheless I will take a look at making it compatible with Nim >= 1.0.x.

If you are using Linux, could you give chosenim a try? It makes it really easy to manage local versions of Nim.

I have been looking at a statically compiled version for Linux using musl-libc but this seems not possible. The SDL2 wrapper dynamically loads SDL2 at runtime which conflicts with musl. If someone could help me with this, it would be great.


EDIT:
I uploaded linux binaries on the release page. There is also a checksum file to verify integrity.
nimPoP was compiled on Debian using the development version of Nim and clang-13. You don't have to modify the SDLPoP.ini file for this binary. However I can not promise that they will work on Ubuntu. Please let me know if they work there. You need to have SDL2 and SDL2-image installed. On Debian/Ubuntu those packages are "libsdl2-2.0.0" and "libsdl2-image-2.0.0".
crem
Efendi
Efendi
Posts: 13
Joined: December 4th, 2020, 8:29 pm

Re: nimPoP: a SDLPoP port in Nim

Post by crem »

BarrOff wrote: April 16th, 2021, 10:53 pm I have been investigating the first one for quite some time now, using lldb, valgrind, cppcheck but to no avail. Initially I intended to announce nimPoP after fixing the issue, but as I seemingly can't find the reason I still announce it now. Help finding the reason of this bug would be really appreciated!
Sorry for not being completely on topic, but I'd like to mention the rr debugger, which usually cuts debugging time tenfold or even more. Probably is not helpful for this particular case, but I used it many times with SDLPoP and it works like a charm.

What it does is records the execution of the binary, and then you can run gdb for the recording the usual way, but it adds a few useful commands which allows to run it backwards: reverse-continue, reverse-step, reverse-next, reverse-finish and so on. All breakpoints/watchpoints/etc work during that reverse execution. So basically the debugging goes like following: you put breakpoint where you know something wrong happened, then do a few steps back to find out how we got there, usually you find the variable with unexpected value. Then put a watchpoint for this variable, and do reverse-continue. And you end up at the code where that was set.


As for nim, I tried it for a couple of months (during ~v0.4). It was fun but it felt like the projects in nim would quickly go unwieldy as they grow. Interestingly, I was trying to write an SDL wrapper, and couldn't do the RAII because there were no C++-style destructors. Hopefully something appeared since then. :)
Post Reply