Lately I’ve done a number of rearrangements in CGE units, to make the engine code cleaner (easier to understand, both for new people and seasoned devs):
- Units map documentation is now up-to-date and more straightforward.
A lot of obscure/internal units have been renamed to
CastleInternalXxxor marked as deprecated. We’re not finished with this cleanup yet, see more potential units that can become internal. But our list of units is already much shorter, making CGE API smaller so simpler to learn.
src/x3dis now src/scene. It contains
TCastleSceneand friends (like
TCastleViewport). I moved the 2 big units that define X3D fields and nodes to a subdirectory
src/scene/x3d. The code loading particular model formats is now in
src/scene/load, and some formats even get their own subdirectory, like
I added subdirectory src/base_rendering, that contains some base OpenGL units (and will contain in the future alternative subdirectories for OpenGL, Vulkan etc.).
We no longer use
openglsubdirectories inside various other CGE directories. Things from
images/opengl/mostly move to
base_rendering. Things from
ui/opengl/mostly move to parent dir, i.e. just
The original idea for separating units that depend on OpenGL from things that don’t was that it would make it easier to recognize what needs to change when we add another renderer (like Vulkan).
However, a lot of CGE units now depend on OpenGL only “very indirectly” and they have a clear API independent from OpenGL. For example,
CastleControlsunit depends on OpenGL, but actually both its interface and implementation are completely independent from OpenGL, and they will likely look the same when we have Vulkan available. They just use
DrawPrimitive2Dthat make sense for any renderer.
Similar notes go for e.g.
CastleViewport. They depend on OpenGL now, but if (when?) we’ll jump to Vulkan, they will continue to exist with the same API, and even they’ll retain most of their implementation. We will just introduce then an abstraction layer, to make renderer “pluggable”, so that underneath
TCastleUserInterfacewill refer to the “current renderer” to do their drawing.
All this meant that keeping these units in
opengl/subdirectory was not really very helpful. In fact, most of important CGE units were in
opengl/subdirectories, which was likely more confusing than helpful. E.g.
ui/looked like a mostly empty directory (mostly just joystick units) until you looked in
ui/opengl/that contained a lot of important classes.
A few usages of
is nestedwere cleaned — as it is not supported by Delphi. We previously tried to use “is nested” on FPC and anonymous methods on Delphi, but this resulted in a code complicated with
ifdefs. It’s better to stick to a common subset of FPC and Delphi for now, which means — no “is nested”, no anonymous methods. (Of course you’re free to use them in your own projects, if you only care about using one of these compilers.)