Ton of improvements: Tiled maps, fonts on web, shader effects on lights, GTK 3 scaling, OPM, Swappy Jigsaw, FPC/Lazarus version updates

Posted on

Collage: Tiled, light effects, fonts
Map from Kenney https://kenney.nl/assets/tiny-battle
Map from Kenney https://kenney.nl/assets/tiny-battle (red and blue rects overlay by our code)
Light effect (stained glass). Light effect (stained glass). Assets from Kenney Mini Dungeon (CC0)
Light effect (stained glass). Light effect (stained glass). Assets from Kenney Mini Dungeon (CC0)
Multiple different fonts in CGE example (editor)
Multiple different fonts in CGE example

We have a big backlog of engine improvements to announce. They were done in the last ~3 months. Each week, each of these things seemed “too small to do a dedicated news announcement”, and that’s how we end up here 🙂 Enjoy, and see if you can find here something that makes your game development more fun.

As usual, everything listed below is already available in our downloads. Your support on Patreon is much appreciated and allows us to keep this development going.

Let’s go!

  1. Tiled maps expose a new property TCastleTiledMap.LayersZDistance. You can read it (and reliably position your objects in front / behind the layers you want) and write it.

    The way we organize Tiled layers always involved positioning each layer at a different Z value, but in the past we tried to keep this property internal, and asked you to not rely on a particular value. This was a mistake in hindsight — making this value public, and settable, should make using Tiled maps more obvious.

  2. Tiled maps example in examples/tiled/map_viewer/ contains a sample code to position scenes at map tiles.

    From the user’s perspective: run the example, open any Tiled map (possibly your own in your project) and press T (like “Test”) to place 100 rectangles on the map. You shall see they exactly hit the map tiles. They are simple TCastlePlane instances, you can add TCastleScene or anything else in the same way. You can find the code doing this in the GameViewMain unit.

  3. Thanks to the FPC developers, the web target got a big improvement: Exceptions are supported!

    See FPC wiki about web exceptions for a description of how this works. The default in latest FPC versions is “Branchful” making exceptions “just work”. You can raise and catch them. If you’re not sure how to use exceptions in Pascal, see the “Exceptions” chapter in our Pascal introduction.

    Our flag ApplicationProperties.CanCatchExceptions remains available, although it is now true always. (It will be false for FPC_WASM_NO_EXCEPTIONS version, and for older FPC versions that didn’t support web exceptions — but we no longer support them.)

    During compilation, we print a message like “Handling exceptions on web by “branchful” (slower, works everywhere) approach” to signal that exception support is compiled-in.

  4. Fonts on web are fixed: We now feature a Pascal-only implementation of FreeType API, used as a fallback when dynamic FreeType is not available, on all the platforms.

    This is particularly useful on platforms on which loading external FreeType library is not easily possible, like web, Delphi/mobile or Nintendo Switch.

    Disclosure: There are 3 units (+1 test) there which have been heavily AI-generated. I document it openly, and I’m not happy (I like to understand everything!) about this. But it was a practical choice. I already reworked the outer layer quite a bit manually, but I cannot yet claim I “own” this code with my human brain (in particular per-format font reading) — it is a TODO.

  5. Our internal unit on top of FreeType, CastleInternalFreeType, has been refactored and simplified a lot. This contained a lot of unnecessary baggage (we started this looking at FPC unit that does font management), which was removed, because all we need there is to load a font and render a single glyph using its Unicode number.

    Practically, such simplifications open the door for adding new features. E.g. we don’t do kerning now, but now it is more obvious how to fix it (pass the kerning information upward to our code that renders strings in TCastleFont.Print).

  6. Castle Game Engine in Lazarus OPM (Online Package Manager) has been updated to the latest version (from our snapshots at the beginning of October).

    This solves an old problem that OPM had ancient CGE 6.4, which didn’t compile with latest FPC 3.2.2. Big thanks to Werner Pamler who maintains OPM!

    Note: Downloading + unzipping it using OPM can take a while (it is much slower than downloading e.g. by Firefox and unzipping with regular systems tools). Werner is looking into this, see issue for details. In the meantime: have patience, it will download and unzip and install correctly 🙂

  7. Easily add shader effects on lights, using TCastleAbstractLight.SetEffects method. There’s a new example and bugfix around it too. See docs for shader effects.

  8. Various improvements have been done to ExtractUriName and friends, to make them properly strip the anchor (#xxx) or query (?xxx) at the end of the URL. We use proper URL parsing, ParseURI, and in all engine places URLs with anchor (#xxx) or query (?xxx) should be OK now.

  9. More about URLs: We fixed reading data from URLs that cannot “detect existence” like http(s) URLs.

    This means you can now use something crazy like https://example.org/my-game-online-data/ for ApplicationDataOverride.

    Hint: Setting ApplicationDataOverride to a remote URL like http(s) is not nice UX. It’s better to download a zip using TCastleDownload with nice progress bar into castle-config:/my-data.zip, and set ApplicationDataOverride to point inside this ZIP, see data from ZIP. It’s a bit more work, but UX will be much better 🙂

  10. Editor toolbar icons (to interact, select, translate, rotate, zoom) now look good in dark themes.

  11. SVG icons of our engine and model viewer now look correct with Qt SVG rendering (used e.g. by Dux Modular Shell (formerly Dank Material Shell) and PikaOS + Niri setups on Linux).

  12. I have forked and restored Swappy Jigsaw, game done by the late Eugene Loza. It now works with the latest engine, following our views concepts, and has updated downloads.

  13. We have updated our bundled FPC version, which is also FPC used to make releases. On Raspberry Pi and macOS, it is now 3.2.5. (On other platforms, it remains at last stable 3.2.2 now.)

    This also means we are 100% ready for FPC 3.2.4 release. (Not released yet, even though fixes_3_2 branch has moved to 3.2.5 now.)

  14. We have updated our Lazarus used to make releases to 4.8.

    Note: we keep using GTK 2 widgetset, as LCL with GTK 3 still has known issues from my last testing. If you test Lazarus 5 release candidate, please keep this in mind. And if you want to help, you’re most welcome to isolate and submit to Lazarus developers GTK3-specific regressions in our editor.

  15. Speaking about GTK 3, our TCastleWindow backend using GTK 3 on Linux got a significant fix/improvement to support GDK/GTK scaling. This for now accounts for GTK 3 integer scaling, but the underlying code is also ready for GTK 4 fractional scaling. See this comment for details.

We hope you enjoy these updates and we appreciate your support on Patreon. Have fun making games!

Start the discussion at Castle Game Engine Forum