Watch tomorrow Castle Game Engine presentation at Embarcadero CodeRage 2022

Posted on

Enterprise CodeRage 2022

You’re welcome to watch Michalis presentation tomorrow, December 21, at Embarcadero Enterprise CodeRage 2022.

The topic of the presentation is using Castle Game Engine as a 3D visualization tool that you can add to the existing Delphi applications. As part of it, I also want to show for the first time a new feature, requested a few times by Delphi users — yeah, you guessed it, a CGE control you can put on FMX or VCL form! Of course, the talk will also feature a general overview of the engine capabilities, regardless of how you want to use it.

The hour is 3:00 PM in CST (Central Standard Time (US)).

The event is free, you can register a seat following this link or just watch a live stream on YouTube Embarcadero channel.

Comments on the forum ➤

My mind is blown. I can use AI to generate Castle Game Engine code to integrate it with PhysX. I can use AI to generate HTML documentation from comments in Pascal code.

Posted on

ChatGPT generating Pascal code integrating PhysX with Castle Game Engine
ChatGPT generating Pascal code integrating PhysX with Castle Game Engine
ChatGPT generating HTML documentation for Pascal source code
ChatGPT generating HTML documentation for Pascal source code
ChatGPT generating HTML documentation for Pascal source code

My mind is completely blown by the capabilities of OpenAI chat bot ChatGPT. It can tell jokes, invent stories and protagonists, write documents with game pitches, play an RPG game with you, pretend to be a virtual machine with an access to an Internet in a weird alternate universe (I checked, it works, you can even do wget https://castle-engine.io in that universe)…

Here are some interesting experiments with relation to Castle Game Engine and Pascal.

Integrating Castle Game Engine with PhysX

PhysX is a physics library from NVidia. It is not integrated with Castle Game Engine as of now. We use Kraft physics engine in CGE now.

As far as I know, no one has ever attempted so far to integrate PhysX with Castle Game Engine. Internet search doesn’t show any results even for PhysX in any Pascal application.

Yet AI can write ready code to do it..

My prompt: Write Pascal code implementation integrating PhysX with Castle Game Engine.

Bot answers:

It also added a short explanation. See the screenshots.

AI just integrated 2 libraries, never ever before integrated in the whole history of the universe.

Sure, there are a lot of problems with this code. It doesn’t really compile, the usage of TVector.One is wrong, there’s no unit called CastlePhysX

But it’s like written by a programmer that knows CGE, knows PhysX and understands the core of the task. And was just too lazy to check on some API details.

  • It is using CGE vectors API,

  • It is using PhysX API (DuckDuckGo confirms that PhysX has concepts like PhysXWorld, PxTransform, PxRigidDynamic).

  • It runs the simulation ~60 times per second, and uses Pascal Writeln to output the result. It added initial velocity to the object, to observe that it changes position. This is exactly what I would do in my first attempt at such application, to test the integration.

Next day, I realized I can ask it to fill the remaining stuff. I can say things like “Given the Pascal example as below: … , implement CastlePhysX unit”. Yes it works. I still didn’t reach a complete code that compiles… but wow. This is impressive.

Generating HTML documentation from Pascal source code (like PasDoc)

Let’s try something else. Let’s make it perform the job of PasDoc.

My prompt: Generate HTML documentation for the Pascal class declared as below:

(here I pasted actual long multi-line code declaring the TCastleButton class, cut down to public and published sections)

Answer with complete HTML code that can be easily copied and pasted.

It answered…

Next prompt: Show me the HTML markup of the above.

Bot answered with HTML markup…

Here is the HTML markup for the documentation of the TCastleButton class:

Yes, it’s a real HTML code. It’s cut — just a limitation of free ChatGPT version I guess, they limit the length of the answer.

It performed the basic job of PasDoc (convert Pascal code with comments -> HTML)….

Holy f**.

Comments on the forum ➤

Gamejam game using Blender and Castle Game Engine – “Lynch”

Posted on

"Lynch" gamejam game
"Lynch" gamejam game - in Castle Game Engine editor
"Lynch" gamejam game - in Castle Game Engine editor
"Lynch" gamejam game - planting trees
"Lynch" gamejam game - in Blender
"Lynch" gamejam game
"Lynch" gamejam game - in Blender

We held a gamejam in our Cat-Astrophe Games studio this Friday and I decided to make a short “walking simulator” game to refresh my Blender skills and of course test that the result works in Castle Game Engine!

The resulting game is on https://github.com/michaliskambi/lynch . It’s very much unfinished, I overestimated what I can do in a short amount of time — but I also learned a lot: using Archimesh, using Geometry Nodes, and generally I think I managed to made OKayish 3D model of a house + surroundings with reasonable proportions in game.

Enjoy the screens and (really trivial) code 🙂

P.S. The prominent pretty 3D asset comes from Bronze figurine of Cthulhu, from Sketchfab, by Jedi2583.

Comments on the forum ➤

Physics merge (pull request with 552 commits)! See you this Saturday on our open meeting!

Posted on

Physics forces visualization

After lots of work from Andrzej Kilijański and myself (started back in February this year), the big new physics features have landed! They are merged to the master branch of our Castle Game Engine now.

A full news announcement will be released once I’ll get some sleep :), short version:

  • new components to setup rigid bodies / colliders (also in the editor),

  • forces API,

  • 3rd-person navigation improvements to also be able to use physics,

  • buttons to run simulation from editor,

  • and much more…

Preliminary new (rather short now) docs are here.

I could direct you to the list of commits in the PR, but it’s too big to browse nicely on GitHub, so let me try to crash our website by pasting the result of git log master..physics > physics-log.txt below 🙂

And remember we have a 4th open meeting this Saturday. The meeting will take place at the usual hour (15:00 UTC) on our Discord. You can go to the meeting already and click there “Interested” and add it to your calendar. See you there! I will of course, among other things, present the new physics.

And now:

Comments on the forum (1) ➤

Fixes to 3rd-person navigation, UI outline and groups, LSP range check error

Posted on

third_person_navigation demo

Fixes to third person navigation component and example:

Fixes to UI:

LSP server:

Comments on the forum ➤

Dark Mode design :)

Posted on

Castle Game Engine Dark Mode design

I can’t count anymore how many times I’ve been asked “when is the Dark Mode coming to CGE editor” 🙂

One answer is: It is already possible. We use LCL and our editor just follows your OS (Windows, GTK, …) theme. If you switch your system theme to something dark, then all your applications (including CGE) will become dark. There are small improvements to it in the physics PR too — I hope to finally finish and merge it this weekend!

Another answer is: We will get to the dark mode (in a cross-platform way, that can be activated specifically for CGE editor) one day, just because we have to 🙂 No matter how hard it may be with LCL.

Here’s a dark mode design by Adrianna Matejek. Thank you!

Comments on the forum (1) ➤

Documentation enhancements: using children components, API and code conventions about memory management, nils, BeforeDestruction and more

Posted on

Raspberry Pi Pico by abdoubouam from https://sketchfab.com/3d-models/raspberry-pi-pico-79aba8c863a14b4682e34e241f2159d2

We have a number of enhancements to our 2 large documentation pages (targeting mostly advanced engine users / developers):

  1. Custom Components documentation was extended with description how do we advise to create children components in your custom components. This is useful when you want to create a new component, register it in CGE editor, and you want to use existing components as children.

    1. You can have internal children (using SetTransient).

    2. You can create regular components in OnCreate method that the user can later completely change and even remove (free).

    3. You can have subcomponents (where user can configure properties, but shouldn’t free / assign a different instance).

    All cases are documented with example code.

  2. We have a big Coding Conventions page that documents a lot of low-level and high-level guidelines about how the engine is developed. It starts with some mundane stuff (like indentation — 2 spaces, never tabs!) but later discussed more interesting topics that I recommend to read:

    1. Our guidelines for BeforeDestruction usage. Big thanks for Andrzej Kilijański for talking it over with me — it’s a very powerful mechanism when combined with clear guidelines when to use it.

    2. You can (and should) free the things you allocated; you should never free other things, unless explicitly allowed.

    3. What can be nil.

    4. Declarative API (classes with independent properties) is simple to use.

    5. Optimize smartly: profile, optimize where it matters (and not where it doesn’t), think about smarter algorithms and moving CPU work to GPU to get big benefits.

    6. Fix warnings (let the compiler help you write reliable code). (Shining example: recent critical TCastleThirdPersonNavigation fix for seemingly-random bug.)

    7. Be consistent in API design.

    8. Backward compatibility is important; having a consistent (easy to learn) API and useful features is even more important.

This post’s image follows our tradition if there’s no clear image to illustrate this, just search for any pretty 3D model. It turns out that if you search for “documentation” on Sketchfab, one of the things that comes up are 3D models of Raspberry Pi, which we love and support in CGE (both as a platform where you can work, and as a platform to which you can compile your games). So here’s a screenshot of CGE editor rendering a 3D model of Raspberry Pi Pico by abdou bouam.

Comments on the forum ➤

Texture coordinate transformation (KHR_texture_transform) in glTF support

Posted on

glTF KHR_texture_transform test
Blender UV map transform

Extending our glTF support, we now handle texture coordinate transformation following the KHR_texture_transform extension.

The glTFs using it can be generated e.g. by Blender if you transform UV Map using the Mapping node (see the screenshot at this post).

Comments on the forum ➤

Visual Studio Code integration, intelligent code completion with our LSP server, also for Emacs, NeoVim and other text editors

Posted on

Visual Studio Code - Pascal code completion
Visual Studio Code - Pascal LSP server configuration
Visual Studio Code - Installing VSIX

If you use Visual Studio Code, we have a new manual page for you and an LSP server distributed and tested with Castle Game Engine that provides a perfect Pascal code completion.

Most important link

Read everything here: Visual Studio Code with Castle Game Engine.

What is an “LSP server”

LSP (Language Server Protocol) is a protocol to define code tools functionality (e.g. code completion) in a way independent from the text editor.

  • Multiple text editors can act as LSP clients, e.g. VS Code (where the LSP originated), Emacs, Neovim.

  • They can access any LSP server. There are lots of LSP servers, in particular there are a few suitable for Pascal.

What I did

I was having some fun exploring the options and I actually got to work 2 LSP servers targeting Pascal: Philip Zander (Isopod) LSP server and Ryan Joseph (genericptr) LSP server. They both use Lazarus CodeTools underneath.

I then modified them (both) adding some CGE-specific features and testing how to make them perfect. I wanted to have it all — support for VS Code (which I know many people like), Emacs (which is my favorite text editor), out-of-the-box support to complete code using CGE API, working everywhere (I tested both Linux and Windows).

  1. We had a few conversations with Philip Zander (thank you a lot for all the information how everything works and being open to my PRs!), I made our fork with Castle Game Engine enhancements, I submitted some PRs back: #1, #2, #4.

  2. I also made a fork of LSP server from Ryan Joseph and submitted PR #33.

My forks add support for additional configuration using INI file and you can make LSP servers trivially aware of CGE paths this way. The details of my additions are in README files on both LSP servers.

Note: Both the above LSP servers actually come from initial Arjan Adriaanse work (though, after 3 commits, it seems he didn’t maintain it further) on github.com/arjanadriaanse/pascal-language-server.

Finally, I gathered a lot of notes and links about existing options to use LSP with Pascal.

Making it easy to use

As a last step, I made the setup as easy as possible to use:

This was a lot of integration work 🙂 And it’s not finished! A lot of pieces can be improved and/or it can be made to work more out-of-the-box. It is possible we’ll have our own Castle Game Engine extension for VS Code one day. It could take care of LSP, help with debugging and running CGE projects from VS Code, maybe more?

Stay tuned 🙂 Do you like this? Please support our work.

Comments on the forum (4) ➤

TCastleTransform.RenderLayer to render stuff in front, TCastleScene.PreciseColisions, upcoming plans

Posted on

So I have now around 5 things in parallel in progress 🙂

  1. Review and merging of new physics (components for colliders, rigid body, joints) with Andrzej Kilijański. It takes a while, but it’s also a large change, and I want to iron out various API details.

  2. Working on big upgrade to FPS game graphics with Adrianna Matejek and Alya Vaneskehyan. Aside from a prettier demo, I get from them a ton of feedback about engine experience from a perspective of experienced 2D and 3D graphic artists. And I have a ton of resulting good TODOs and priorities that will over time find their way into the egnine (some of them already did).

  3. I’m planning restructure of our settings. I would like to deprecate our CastleSettings.xml in favor of a design like CastleProject.json that allows to specify more, and is editable in editor too. In addition to current settings, it would also allow to define some project-wide components (like sounds and fonts that should be loaded and available for the entire application lifetime).

    While a plan is written down, I will likely postpone it after 7.0 release.

  4. I have a great plan how to allow to visually customize materials and material effects in CGE. We have some unique challenges and unique features (our compositing shaders or easy mirrors are really great, we just need to expose them in a way that is simple — both from editor and from Pascal to use).

    I consider this high priority and want to push to make it happen before 7.0 release.

  5. I’m organizing a Windows certificate so that our EXE files are less scary to run on Windows 🙂

Some things done lately that are already available in CGE master branch:

  1. New property TCastleTransform.RenderLayer to force some things to be rendered in front of others. Particularly useful in 3D, e.g. to display weapon in FPS game always in front of other 3D objects.

  2. New property PreciseCollisions and deprecating previous complicated Spatial property. This is anyway part of old “simple physics” — while still available, with time we will want to move everything to new physics, so PreciseCollisions is doomed to be deprecated (at some future point, after 7.0 release) too. But for now it’s great to e.g. easily control how FPS navigation by TCastleWalkNavigation behaves.

  3. Important fix for DistanceCulling with shadows.

  4. Testing LSP servers with Pascal! More about it in next news post 🙂

Comments on the forum ➤