Full compatibility with C++ Builder

Posted on

C++ Builder application using Castle Game Engine (TCastleControl) within FMX (FireMonkey)
C++ Builder application using Castle Game Engine (TCastleWindow) with views, scenes, viewports

This is probably a bit surprising news, coming from a game engine written in Pascal 🙂 Don’t worry, there are improvements relevant for Pascal too, at the bottom of this post!

That said, I do love playing with new toys, and a toy I played with recently was C++ Builder. C++ Builder is Embarcadero C++ compiler and IDE, closely integrated with Delphi and so Pascal. I played with exposing our engine classes to C++ developers. It turns out it is really trivial to expose full Castle Game Engine API (with all classes and features) to C++ developers this way!

For example, you can now write code like below to operate on TCastleScene from C++:

__fastcall void TViewMain::ClickMove(TObject* Sender)
    Scene1->Translation = Scene1->Translation + Vector3(0, 1, 0);
__fastcall void TViewMain::ClickBunny(TObject* Sender)
    Scene1->Url = "castle-data:/Bunny.gltf";

The end result is that our engine API is 100% available for C++ developers. This includes

All the related classes are just available to you as C++ classes. The Pascal units are available as C++ header files. Properties, methods, global routines, enums etc. — just everything works and is exposed in C++ using concepts analogous to Pascal. This is the amazing power of C++ Builder.

The examples are in the latest engine official download, in particular:

Follow the installation procedure inside, in particular please note you have to build and install Delphi packages. This generates the C++ header files and the object files to be linked.

Don’t worry, we’re still a Pascal game engine 🙂 And we continue to love and promote Pascal. The beauty of this integration is that it doesn’t require any maintenance, our Delphi and Pascal code is just completely automatically available for C++ developers with equivalent capabilities. So, going forward, we are fully committed to supporting both Pascal and C++ developers this way.

I am excited to see where this will take us 🙂 If you have C++ Builder, and wonder about using Castle Game Engine with C++ this way, please go ahead and be sure to report any issues or success stories!

Please note that right now the CGE documentation remains Pascal-oriented. I hope that the above two C++ Builder examples (in examples/delphi/cpp_builder/) are enough to give you an example how Pascal concepts map to C++. If it’s unclear how to access anything from C++, let us know (ask on forum, Discord…).

While doing this, we polished by the way some engine pieces useful for Delphi (Pascal):

  • We introduce a new castle_engine_window Delphi runtime package. This includes units that work with our TCastleWindow component. While you don’t have to use this runtime package to build Pascal CGE applications using TCastleWindow (instead, new projects by default will just link to CGE Pascal units, without using the package) but it’s an important stepping stone to make Delphi aware of all our classes and go with GetIt.

  • We now automatically cooperate with default Delphi and C++ Builder convention to put exe files in a project subdirectory like Win32/Debug/, Win32/Release/, Win64/Debug/ and so on. We will detect this situation and access data directory automatically correctly, so that your applications using data directory will work correctly out-of-the-box in this case.

  • We have explicitly switched our XML vendor in Delphi to OmniXML, for all platforms. This is a fast cross-platform XML vendor. We use it on all platforms with Delphi now (not MSXML on Windows) to have most consistent cross-platform behavior.

Start the discussion at Castle Game Engine Forum