Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add native Linux support #3483

Draft
wants to merge 31 commits into
base: master
Choose a base branch
from
Draft

Add native Linux support #3483

wants to merge 31 commits into from

Conversation

xtremeqg
Copy link
Contributor

No description provided.

This change splits cmd_exec into many small functions,
each responsible for one single command.

Replaces the non-standard function cmd_strtok with strsep.
This change cuts build time in half by not compiling everything twice.
Logging should now also be better because heavylog was a rather
all-or-nothing approach. Either you'd get no logging or
you'd get too much logging.

Removal of BFDEBUG_LEVEL also fixed some issues, it wasn't actually
possible to compile without BFDEBUG_LEVEL as it caused some variables
to disappear. Secondly, changes would introduce silent bugs as the
compiler skipped over anything with insufficient BFDEBUG_LEVEL. Only
after raising BFDEBUG_LEVEL sufficiently the compiler would read
the now-bugged code and complain.

Seven separate logging channels have been introduced.
Each channel has its own verbosity level ranging from
off (nothing) to debug (everything).

Log verbosity is controlled in-game using the new "!log" command.
Found several places that used unbounded printf
calls to write into a fixed-size buffer.

Also replaced a few non-standard sprintf_s calls.
On Linux the value returned by this function would overflow,
causing freezes and weirdness. I've added several implementations
for different clock resolutions.

It should be noted that when CLOCKS_PER_SEC = 1000000,
clock() will wrap around every 72 minutes.

To fix wrap around, a different clock source should be used.
Since C++ 17, std::lerp has been added to the global namespace as lerp.
Post-increment is a read+write operation which, on a volatile
can result in undesired behavior.

While the use of std::atomic is a better solution, implementation
is non-trivial as it would require type-erasure tricks to keep
the header file usable by plain C sources.
Mix_GetMusicTitle, Mix_GetMusicArtistTag and Mix_GetMusicCopyrightTag
require SDL2 Mixer 2.6.0 or greater. As we're only writing to a log
file, not having these functions is not critical.

Also fixes stack corruption by songs where the concatenated string
exceeded 255 bytes in length.
Custom GUI sprite that didn't load properly may have
their Data pointer set to bad_icon_data, which is a
static variable and cannot be freed. Doing so will
crash the game.

Fixes dkfans#3482
Spent some time learning Ghidra and found out that gtblock_draw
is some convoluted Duff's device.

Its sole purpose is to improve performance when the player is
using the frontview camera zoomed out to FRONTVIEW_CAMERA_ZOOM_MAX.

The thing is that FRONTVIEW_CAMERA_ZOOM_MAX rarely occurs on higher
display resolutions because players can zoom far, far beyond ZOOM_MAX.

So I just straight up removed the entire optimization.
One less thing to worry about.
Embedding _finddata_t into TbFileFind made everything Windows-specific.

By using an opaque pointer and introducing a generic result struct,
directory file search can now be implemented for any platform.

I also removed all fields from TbFileFind except for Filename,
none of the other fields were being used anywhere.
Lots of time in Ghidra resulted in a giant function consisting
of yet another Duff's device (surprise).

The disassembly is a bit gnarly and has some bugs in it but at least
we can now compile for any platform.
Including a header file from obj folder just feels wrong.
Apparently gcc 13 is broken and cannot compile libspng.

See: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109504
This removes the sound heap which was used as a cache to store samples.
Samples were loaded on-demand directly from disk as a means to save memory.

Loading sound samples like this is at least partially responsible
for the stutter every time a game is started or loaded.

This is one of the steps needed for OpenAL conversion.
Allows for logging to include the sample name in the future
Very low-level implementation without actually using
OpenAL's 3D functionality.

Made various makefile adjustments to ensure everything is built
and linked correctly. No, cannot use -j yet.

Currently the game crashes trying to play the intro. Not sure why.
OpenAL happens to print lots of information by calling OutputDebugString.

Unfortunately, Vex_handler doesnt't know how to
handle such calls and assumed the game crashed.
For some reason exit_handler is registered to be called on exit.

All this function does is print "Application exit called".

This happened to crash LbLog (vfprintf) because the log file
had already been closed at this point.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant