Foster icon indicating copy to clipboard operation
Foster copied to clipboard

Remove C library

Open NoelFB opened this issue 8 months ago • 3 comments

I would really like to remove the C library at some point, and rely solely on SDL3 for native code. However, image and font loading are both done using the C stb headers. There are C# ports of them, but I don't want to rely on other assemblies or NuGet packages within Foster itself.

Ultimately I would like to inline them into single-file C# variants of the stb headers, but it's kind of a low priority.

NoelFB avatar Apr 26 '25 18:04 NoelFB

I have looked at this issue out of curiosity and there could either a new single-file C# replacement for the libraries are made or C code is still used. Both of these options are not ideal. For the first case, libraries are complicated. Really complicated. A single file version of stb_image or stb_truetype would easily be thousands of lines long, which doesn't seem that great. C# could also potentially be a bottleneck in the future. The second approach would be a bit better but not perfect. When using a game framework, it would be great if the game code and the library code were made in the same language. That's not possible with a C#/C codebase.

I do not have much experience with C# or programming in general but I see two possible paths:

  1. mono repos -> Have new solutions corresponding to each part of the framework. It's just the single-file header idea but better. This is what tons of other projects do as their complexity increases.
  2. Vendoring -> Instead of adding a NuGet package to the framework itself you just "copy-paste" the package into the repository. If any issues crop up then you just modify the library itself instead of reaching out to the library developers.

Another option would be to use SDL_Image and SDL_TTF instead of the STB headers, which follow SDL's coding style more but this doesn't solve the core issue.

AlexisAndA avatar May 31 '25 20:05 AlexisAndA

SDL3.4 is adding PNG reading/writing methods. Reading/writing qoi files is really simple in C#, so realistically the only remaining thing in the C library is font reading with stb_truetype.

NoelFB avatar Oct 24 '25 01:10 NoelFB

If you are thinking of going down the route of MSDF fonts anyway you don’t need stb_truetype here. IMHO

Personally I use Slug but that’s a whole other can of worms.

xgalaxy avatar Oct 24 '25 05:10 xgalaxy

This has been implemented - using SDL3 for png loading from the prerelease, used a cut-down/modified version of StbTrueTypeSharp for font bitmaps.

Still experimental, but I think it's nice.

NoelFB avatar Dec 08 '25 22:12 NoelFB