![image](https://github.com/Xeeynamo/sotn-decomp/assets/6128729/81e07623-f2d5-4b00-9624-7aa678593aa8)
Add colours to the various logs to make sense out of all the produced
noise. Also gets rid of the square brackets and use a nicer column
separator. Don't mind the error log being mis-labeled. My hunger for
copy&pasting code consistently betrays me.
![image](https://github.com/Xeeynamo/sotn-decomp/assets/6128729/1873521f-cb41-4a80-aa0c-7e6b6a752ffa)
but most importantly groups the logs to avoid spamming the same one for
every frame. The log count keeps getting updated on the left-hand side
of the log, replacing the beginning of the path (almost never relevant).
If the log is old, the logging function will go back, update the line
and go back down.
It is a tad bit slower than the original implementation, but logs are
never meant to be seen anyway, especially debug logs. I used a
relatively fast hashing function paired with a dictionary to avoid
unnecessary loops. There are two hashes. `logHash` simply works as an
index to the massive 65K entry dictionary to pick an index. If an entry
is found then check the other hash `altHash` to check if the dictionary
collided with an actually different log, effectively replacing it. Since
`entry->hash` is `0` at the beginning, that also works for new elements.
I believe the slowest part of the code are the two `while (nLinesBack--
> 0)`. I am thinking to maybe unroll the loop in a similar way `memcpy`
works internally to save `fputs` calls. But I have little clue on how to
measure improvements. If you know better on how to take advantage of
moving the cursor through the TTY, please let me know.
You can disable this entire functionality with `#define
FORCE_LINEAR_LOGS` and it gets disabled if `stderr` is not printing on a
terminal.
The most prominent change is the new macro which replaces the `DEBUGF`
for each stub, but that is the least interesting part. This allows to go
through the different steps `Game_Init`, `Game_NowLoading` and once it
finally lands into `Game_Play` it calls `func_800F298C`, which is our
new `main` function for testing stuff.
In Italian we say "Abbiamo fatto 30, facciamo 31". It literally means
"We come all the way up to 30, it wouldn't cost nothing to push a little
further for 31".
I moved `log.h` into `include/` to easily logging stuff elsewhere and
without weird `#ifdef VERSION_*` by adding `-DNO_LOGS` in the main
Makefile.
This is a bit hacky, but it does the trick. I had to expand `D_80138784`
otherwise I would get a segfault.
Both `SoundInit` and `func_801361F8` are called in the main, so I
removed them. To restore the previous behaviour and isolate the sound
engine, just replace `MainGame()` in the `main.c` with a `SoundInit()`
and then a loop that calls `UpdateGame()`.
Last, but not least, SDL2 is in.