D2X-XL Worklog
Notes on features and problems from the development of D2X-XL, newest first.
Code Cleanup |
|
SDL2 D2X-XL was built on SDL 1.2, a library that has been outdated for many years. It has been ported to SDL2, which now provides the window, the timer, keyboard, mouse and joystick input, music and the download of missions. Sound effects have moved to OpenAL. Floating Point Descent was written with fixed point arithmetic, which was the fast way of doing math on the PCs of its time, and D2X-XL had carried it along ever since: fixed point numbers, vectors and matrices, and angles in a format of their own. All of that is gone. D2X-XL 2.0 computes with floating point numbers throughout; angles are degrees and times are seconds. A Slim Interface To The Old Formats The data files of Descent are still fixed point, of course: levels, models, robot and weapon data, demos. They are converted in exactly one place, in the functions that read and write a file. What these hand to the game is floating point, and the rest of the program never gets to see a fixed point number. Historical Baggage D2X-XL could still load save games from versions long gone, and paid for it with two loaders and version checks all over the code. That has been removed: D2X-XL 2.0 only reads its own save games, and older ones no longer load. Levels, pilot files and demos from older versions still do. A lot more went out on this occasion: the nostalgia options, the console, KALI and IPX networking, the separate Descent 1 robot AI, the render paths for anaglyph and shutter glasses, and plenty of code nothing used anymore. The source code has shrunk by about a fifth. Vulkan And DirectX 12 Instead Of OpenGL The renderer has been rebuilt from scratch; nothing of the old rendering code is left. D2X-XL now renders with Vulkan or with DirectX 12 instead of OpenGL, because OpenGL supports modern features like hardware raytracing or VR poorly or not at all. Vulkan is its worthy modern successor: it is fast, it is universal, and it is available on many platforms, Linux in particular. There is a separate program for each of the two, and both are built on a rendering library of my own. All shaders are prepared when the program starts and kept in a cache on disk, and what the graphics card needs beyond that is set up while a level loads. This is to avoid the little hitches you get when such things are only prepared at the moment they are needed for the first time. Multithreading D2X-XL used to spread work over several CPU cores with OpenMP and a number of threads of its own. There is now a single thread pool for everything that runs in parallel. Its essential feature is a load threshold. Every loop tells the pool how much work one of its items is, and the pool only spreads the loop over several cores when there is enough work in total to make it worthwhile; handing five items to a dozen threads costs more than it gains. Running this way are robot AI, homing weapons, particles and sparks, visibility, the lights of segments and portals, the light in fog, tessellation and the conversion of textures. The number of threads can be set with the command line switch -multithreaded. |


