Experimental feature: freely rearrange and dock/undock editor windows

Posted on

Castle Game Engine editor with docking
Castle Game Engine editor with docking
Castle Game Engine editor with docking
Castle Game Engine editor with docking

With many thanks to Trung Le (Kagamma), we have a new experimental way to manage editor windows. You can freely rearrange them within the main form, you can rearrange them in tabs, you can also detach them from the main form. This is great to spread the editor windows across multiple monitors too, to e.g. have a large “Design” (game preview) on one monitor, and the rest (object inspector, hierarchy etc.) on another.

Usage:

  1. This feature is experimental for now, and by default hidden. To enable it, create a file called enable-docking.txt in the editor user preferences directory: $HOME/.config/castle-editor/enable-docking.txt on Unix, c:/Users/USERNAME/AppData/Local/castle-editor/enable-docking.txt on Windows. If you ever used the editor, you will find existing castle-editor.conf in the same directory already.

  2. Enable it by checking “Window -> Docking” menu item.

  3. Close and reopen the project (you can also just close and reopen the entire editor).

  4. Have fun! Drag the headers to rearrange windows. Drop them in new areas to anchor there. Drop them over existing areas, to add to tabs. Drag them outside of the main window, to detach them.

  5. The layout is automatically saved (in layout.dock-layout in your preferences directory).

  6. If you ever lose a particular window, you can invoke it by various “Window -> Xxx” commands, like “Window -> Properties”.

  7. If you want to reset the layout, use “Window -> Reset Default Docking Layout”

The feature is very powerful.

We are waiting for champions to solve some of the issues (critical ones: 349, 348, 347, 345) and then of course the additional step to create enable-docking.txt will disappear. The additional step to enable them using the menu “Window -> Docking” may disappear too. All it takes is making it look and work perfectly, out-of-the-box, so that we can enable it for everyone without fear that new users could easily see some bug, or get easily into a weird layout without knowing how to “get back”.

Please support the engine development on our Patreon. It funds development of the engine, with many new features and fixes!

Comments on the forum ➤

TCastleWindow.SceneManager: removal of a deprecated property soon

Posted on

Castle Game Engine example - multiple_viewports

As we extend the engine, we sometimes have to deprecate some old features, that were not very useful, and sometimes prevented the engine API from being flexible and easy to understand.

One of these things was TCastleSceneManager class (renamed to TCastleViewport since 2 years), with its single “central” instance in TCastleWindow.SceneManager or TCastleControl.SceneManager. In a hindsight, I know it was a mistake to add such “central” reference to “one main scene manager”. It was much better to focus on adding multiple UI controls to your window (which we did), and realizing that various scenarios are possible:

  • Some games don’t need TCastleSceneManager / TCastleViewport at all.

    E.g. applications with simple UI, where everything is just a simple 2D UI control.

  • Some games need one instance of TCastleSceneManager / TCastleViewport (e.g. typical 3D FPS games). But it still may not exist always, so it better exists only within particular TUIState.

  • Some games need more instances of TCastleSceneManager / TCastleViewport. Maybe on one TUIState (e.g. split-screen local multiplayer games), maybe spread in many TUIState instances (e.g. 3D game view, 3D map view etc.).

This observation led to the API you now have and use. But… the TCastleWindow.SceneManager and TCastleControl.SceneManager are still defined, for backward compatibility. And we advise everyone to use classes with Base suffix, TCastleWindowBase and TCastleControlBase, to avoid having this “automatic central scene manager” present. This is causing complicated engine code (for backward compatibility), complicated docs (why the Base suffix?), and unnecessary dependencies in CastleWindow unit (that right now has to depend on almost all CGE code, as TCastleSceneManager / TCastleViewport depends on TCastleScene that depends on almost everything else).

We had TCastleWindow.SceneManager and TCastleControl.SceneManager deprecated for 2 years now, since December 2019. Time to actually remove them 🙂 So, a plea: if you use TCastleWindow or TCastleControl, if you see messages that they are deprecated but you keep using them anyway… stop 🙂

The best way to upgrade is to switch to using TUIState, designed by CGE editor, and put TCastleViewport in your games this way. But as a last resort, you can even create local copy of existing TCastleWindow code from castlewindow.pas, it isn’t long.

At the end of January 2022 (in 1 month) we will actually remove TCastleWindow.SceneManager and TCastleControl.SceneManager. The TCastleWindow and TCastleControl will become equivalent to their ...Base counterparts, and we will encourage to use again the simpler names (as there will be no point in using ...Base suffix). It is easy to try it right now: go to src/common_includes/castleconf.inc, find

{$ifdef FPC}
  {$define CASTLE_DEPRECATED_WINDOW_CLASSES}
{$endif}

and just remove it. Or add something, e.g. dot, to make the {$define CASTLE_DEPRECATED_WINDOW_CLASSES} inactive, like this:

{$ifdef FPC}
  {.$define CASTLE_DEPRECATED_WINDOW_CLASSES}
{$endif}

This will change the TCastleWindow and TCastleControl to be equivalent to their ...Base counterparts, without any deprecated SceneManager property.

Please support the engine development on our Patreon. It funds development of the engine, it means we have resources to design the engine the right way!

Comments on the forum ➤

Alpha Bleeding explained

Posted on

Alpha bleeding investigation

Blending is a common technique to achieve partial-transparency of various things (UI, 2D and 3D models). In many cases it means that your texture has an additional channel, alpha channel, that determines how much each pixel is opaque.

But there is a trap — colors from fully transparent pixels (that you, by default, don’t see in usual 2D image viewers and editors) can still affect the final rendering output, because when rendering we do filtering that can average RGB colors from neighboring pixels. The way to fix these problems is alpha bleeding, which means that your transparent pixels also need some sensible RGB values.

I have written now a proper manual page about the “alpha bleeding”, what problem does it solve and how to actually use it.

Our castle-view-image, that is already bundled with CGE binary release, contains a ready menu item to do it.

Note that the issue is not specific to Castle Game Engine. It’s an effect of how the GPU is using alpha and averaging RGBA pixels, and it really affects all game engines that exist. But some engines hide it better than us right now 🙂 E.g. Unity does alpha bleeding for you automatically, during texture import, if you select Alpha is Transparency. In CGE, we do not (yet) have so trivial UI to do this.

Please support the engine development on our Patreon. It funds development of the engine, it means we have resources to add engine features that make it easier to use and we have time to document them properly!

Comments on the forum ➤

Better ASTC texture compression tooling and formats

Posted on

ASTC compression variants, from https://en.wikipedia.org/wiki/Adaptive_scalable_texture_compression

Thanks to Eugene Loza we have an improved pipeline for compressing textures using ASTC (useful on modern Android and iOS versions). See Auto-generated compressed and scaled textures about GPU texture compression in general.

Now:

  • We can use astcenc tool and the .astc file format it generates for ASTC textures.

    See PR #321 for details.

  • We even package the astcenc tool within the Castle Game Engine. We can, as it is open-source. It’s available in our binary releases as well as GitHub Repo (tools/contrib/). So you don’t have to download/install anything to be able to compress textures using ASTC.

    See PR #351 for details.

  • Where to go from here? What more texture tools to “just bundle with CGE”? I started the thread on our forum. I think bundling AMD Compressonator with CGE is sensible.

Please support the engine development on our Patreon. It funds development of the engine, it means we have resources to do the engine in the right way — that works efficiently and is easy to use.

Comments on the forum ➤

Drag-and-drop in editor hierarchy improved

Posted on

Hierarchy editing in platformer demo

Thanks to PR #354 by Andrzej Kilijański dragging-and-dropping items in the editor is now better:

  1. We do not reload hierarchy. This is esp. important when editing larger hierarchy of UI / transformations.

  2. We keep the selection.

  3. Also occasional Access Violation when doing drag-and-drop on hierarchy on Windows is fixed. See the issue #353.

Please support the engine development on our Patreon. It allows us to fund development of important features and fixes such as this. Andrzej’s time is financed by Patreon proceeds and we have much better engine thanks to it!

Comments on the forum ➤

Integration with Vampyre Imaging Library, new example image_display to test image loading speed and format support

Posted on

Castle Game Engine example - image_display
examples/images_videos/image_display speed test

We now can use Vampyre Imaging Library to load and save images in various formats. After some testing, I’m very impressed with how easy it is to use Vampyre, and we are already:

  • Using it with Delphi by default (no need to do anything).

  • Vampyre source code is bundled with CGE, so you don’t need to set up / download anything extra. Vampyre is just automatically used under the hood by CGE to load/save some image formats. It is in src/vampyre_imaginglib of CGE, and CGE build tool automatically passes paths to it when building CGE applications.

For FPC:

I have also tested using Vampyre with FPC, and our build tool already contains the necessary paths. Every FPC user of CGE can just define USE_VAMPYRE_IMAGING symbol to use it. There are a number of ways to define it, the advised is to define it in CastleEngineManifest.xml, like here.

In the near future we will likely just use Vampyre with FPC by default, so the need to define USE_VAMPYRE_IMAGING is just a temporary thing. We just need more testing, with various FPC versions and platforms (see lower for examples).

In the more distant future, we may also remove the code to use FpImage with FPC, even as a fallback, since Vampyre seems just better than FpImage in every way.

Advantages of using Vampyre:

  • Vampyre Imaging Library is cross-platform.

  • Works with both FPC and Delphi. Unlike FPC-specific FpImage or Delphi-specific PngImage (and other stuff in Delphi Vcl.Imaging).

  • Supports many image formats, both reading and writing. It even supports a bit more than FpImage, e.g. we added now loading TIFF, JPEG 2000, XPM without any extra tools.

  • It has really good and simple API. Almost entire CGE + Vampyre integration code is in this include file.

  • It is well documented on https://imaginglib.sourceforge.io/ , with manual and reference.

  • It is efficient. Unlike e.g. FpImage from FPC — which turned out to be very inefficient when it comes e.g. to PNG image reading (despite our efforts to make it fast, using TFPCompactImgRGBA8Bit, using format detection in InternalDetectClassPNG).

  • It doesn’t require any external libraries. Unlike LibPng approach in CGE.

Help us test!

I’m eager to hear about your tests of Vampyre on various platforms, with various compilers, with your images.

You can use e.g. our castle-view-image (image viewer) for easy testing. It compiles now with both FPC and Delphi.

You can also use a new cross-platform example: examples/images_videos/image_display . This loads the image in a number of formats (making sure we support them all), and can perform speed testing – to compare loading times of various libraries, so you can verify the speed of Vampyre vs FpImage vs LibPng yourself.

What about LibPng, DDS, KTX?

Vampyre is still a bit slower for reading PNGs than LibPng (about 2x slower on Linux/x86_64, which is anyway better than FpImage that was 4x slower), so we will keep relying on LibPng for PNG. Still, Vampyre is a much better fallback than FpImage when LibPng will be missing.

We may rely on Vampyre for some formats that are currently built-in in CGE code, too. This includes BMP, RGBE, PPM.

We will likely keep our own CGE code for loading DDS and KTX though. (Vampyre can handle DDS. But we want DDS and KTX to go though a similar code path in CGE, and we want to efficiently use all their features — cubemaps, texture compression, 3d textures, mipmaps.)

Comments on the forum (2) ➤

Big merge: Delphi compatibility, integration with Vampyre Imaging Library, many new/upgraded examples, inspector improvements, more

Posted on

Castle Game Engine example - multiple_viewports
Castle Game Engine example - Castle Game Engine example - shader_override
Castle Game Engine example - image_display
Castle Game Engine example - listen_on_x3d_events
Castle Game Engine example - use_designed_curve

I have just merged a giant pull request to CGE with 334 commits! This is a big work from Andrzej Kilijański and me (Michalis Kamburelis) from the last 3.5 months, and it includes:

Edit: I initially wrote that it is “250 commits”, not 334. It turns out that GitHub PR interface just shows only 250 commits, but there are more! 🙂

Comments on the forum ➤

Inspect your game hierarchy and logs at runtime — just press F8

Posted on

Castle Game Engine Inspector - Mousey glTF animation
Castle Game Engine Inspector - Platformer
Castle Game Engine Inspector - Escape from the Universe

Initial version of this post said we use F12. We had to change this shortcut to F8 though, because when running the application in Delphi debugger on Windows — F12 breaks the process (this is a feature of Windows+Delphi…).

I’m happy to announce a feature that may forever change how you use Castle Game Engine! Simply recompile your game with the latest engine version, press F8 and behold… a powerful tool to see your log and hierarchy of objects in the game.

Watch a presentation:

Yes, this looks effectively like a (very minimalistic) editor-at-runtime. It is cross-platform and automatically available for all your games. Invoke it at any point, and inspect (soon: even edit) the visible CGE objects (UI, transformations, scenes…).

Features:

  • View the hierarchy of TCastleUserInterface and TCastleTransform at runtime (just like in CGE editor)

  • Select any component (by picking it from hierarchy, or hovering mouse over it with various “Auto-Select” options) to see its properties, updated in real-time

  • View logs (each time you press F8, we show 10 last logs, and we’ll collect any more logs that will be submitted while the inspector is open)

  • All panels (hierarchy, properties, profiler, log) can be hidden and shown independently

  • Inspector opacity can be controlled, to better see your game content underneath. The current opacity and panels are remembered when you toggle inspector by F8 repeatedly.

  • Powerful frame profiler shows where do you spend most of the time each frame: update, render, physics, swap. It also shows FPS history.

  • The key to invoke the inspector can be configured, you can also make it available in the release mode. By default, we assign {$ifdef DEBUG} keyF8 {$else} keyNone {$endif}.

Note: long time ago I had a plan for a different approach to “editor at runtime” : compile with CASTLE_WINDOW_LCL backend, and add LCL UI — reused between “editor at runtime” and actual CGE editor. Downside: it would work only on desktops. For Delphi devs, it would also mean that we need to compile the game with FPC too. Upside: It would be easier to support 100% of editor features. What is the ideal approach? We’ll see 🙂 For now we develop CGE editor using LCL, and in-game inspector using CGE UI, and we’ll see how these 2 approaches converge.

Comments on the forum ➤

Various engine improvements – editing collections in editor, Tiled fix for multiple tilesets, API simplifications

Posted on

Editing collection in CGE editor
Editing collection in CGE editor
Tiled Map Viewer
  1. Thanks to Trung Le (Kagamma), you can now use collection editors in Castle Game Engine Editor just like in Lazarus.

    This allows to visually edit e.g. particle effect anchors in cge-3d-particle-emitter or a TDbf.FieldDefs from castle-db-aware-controls.

  2. Thanks to Matthias (Free Pascal meets SDL), we have an important Tiled bug fixed — in case you used multiple tilesets within one Tiled map. Testcases are within examples/tiled/map_viewer data.

  3. On our quest of simplifying CGE API, we recently removed a useless TInputListener class (it is now a deprecated alias for TCastleUserInterface) and the new non-deprecated name for TUIContainer is now TCastleContainer.

  4. view3dscene supports a new command-line option --no-x3d-extensions if you’d like to convert models from various formats (e.g. glTF) to X3D without any Castle Game Engine X3D extensions. While it may make the models a bit less functional in CGE, it makes them more readily useful with other X3D viewers like X3DOM.

  5. During the development of The Unholy Society for iOS, we noticed a weirdness with Release events on iOS, which stem from how iOS reports touchesEnded / touchesCancelled events. There’s nothing we can do about them (and every iOS application suffers from them, as far as we can tell, regardless of the engine/framework used to make it), so they are just documented now at iOS – Known Problems.

Comments on the forum ➤

Presentation about Castle Game Engine from DelphiCon 2021

Posted on

Our presentation about Castle Game Engine from DelphiCon this week is now available to watch on YouTube! I highly advise watching this to every CGE developer — regardless of your favorite Pascal compiler/IDE. I describe the engine features, and go into a very practical session where I modify one of our templates, showing a number of basic CGE features. I hope you enjoy this!

Comments on the forum ➤