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

Show date and time of savegame in Save/Load menu #1200

Merged
merged 11 commits into from
Apr 23, 2024
Merged

Show date and time of savegame in Save/Load menu #1200

merged 11 commits into from
Apr 23, 2024

Conversation

JNechaevsky
Copy link
Collaborator

@JNechaevsky JNechaevsky commented Apr 22, 2024

TODO's:

  • Doom
  • Heretic
  • Hexen
  • Strife?

JNechaevsky and others added 6 commits April 22, 2024 13:35
Co-Authored-By: Fabian Greffrath <fabian@greffrath.com>
Better do not remove it, so the purpose of "-15" will be clear.
Working, but needs pixel perfection.
src/doom/m_menu.c Outdated Show resolved Hide resolved
@JNechaevsky
Copy link
Collaborator Author

Gorgeous! Not sure what to do about save date coloring though, traditionally is should have CR_GOLD, but the text itself is already gold/yellow. Green or red doesn't seems correct, CR_DARK is a bit too dark for this purpose. Probably worth to follow "if unsure, back to vanilla" logics? 🤔

image

Since everything is moved slightly up and no extra file slot is being drawed over status bar, "inhelpscreens" is now redundant.

Save date should not appear on status bar, since it's using same Y-coords as KIS stats.

Also, this making Save/Load menu slightly less expensive in terms of CPU usage, but fortunately, we are still on capped framerate while active menu.
@JNechaevsky JNechaevsky marked this pull request as ready for review April 22, 2024 17:43
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wformat-y2k"
#endif
strftime(filedate, sizeof(filedate), "%x %X", localtime(&st.st_mtime));
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woke up with a bad feeling, that it can be unsafe since Raven's font set doesn't have a backslash symbol, and attempt to draw non existing symbol is a direct path to program crash. But looks likes it is safe all around, none of existing date formats are using \.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could just fix font drawing to skip non-existent character patches.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat idea, even outside of this PR, this can potentially improve compatibility with custom texts. For small font drawing, it should be something like this:

+++ crispy-doom/src/heretic/mn_menu.c	Tue Apr 23 10:24:01 2024
@@ -631,6 +631,10 @@ void MN_DrTextA(const char *text, int x, int y)
         {
             x += 5;
         }
+        else if (c > 91)
+        {
+            continue;
+        }
         else
         {
             p = W_CacheLumpNum(FontABaseLump + c - 33, PU_CACHE);

Why exactly > 91: no font characters available starting from 92, acording to ASCII table. Raven fonts starting from FONTA01, while in ASCII characters it's a 33. Last available lump for small font is FONTA59, so 59 + 33 equals 92.

Hopefully. 🙂 At least this way I no longer have crashes by using \ symbol in text drawing. But probably worth to leave it for separated PR?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, Heretic's A-font does only have 59 characters, so everything after 33+59 should be skipped. I would extend the earlier check, though, and just print a blank space.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡! True, patch drawing is guarded by following else condition, so it can be simplified to just

        if (c < 33 || c > 91)
        {
            x += 5;
        }

Worth to do same trick with big font FONTB**, except it have 58 characters, so check should be if (c < 33 || c > 90)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, please. And I think it belongs into this bug report, because the time and date string is not under our control.

Co-Authored-By: Fabian Greffrath <fabian@greffrath.com>
Copy link
Owner

@fabiangreffrath fabiangreffrath left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@JNechaevsky JNechaevsky merged commit 4c658f2 into master Apr 23, 2024
5 checks passed
@JNechaevsky JNechaevsky deleted the savedate branch April 23, 2024 11:34
@JNechaevsky
Copy link
Collaborator Author

Glad to be back, happy to make good things good. 🤗

I have one more suggestion, yet it's very small: JNechaevsky/CRL@e68bc1b.

Pretty self-explanatory, but I found it useful when I need to restart game level from tally screen, i.e. not only while GS_LEVEL state. In the middle of winter I was practicing Zone300 MAP12 by UV MAX, but not by demo recording rules - just for some personal fun. And here's the thing: to start MAP12 over again, I have to start MAP13 first, then type IDCLEV12, or load a save on MAP12 and restart the level.

So, this small correction could be useful for handling such cases, and if I'm not mistaking, Woof behaves same way.

@fabiangreffrath
Copy link
Owner

Woof behaves same way.

In Woof, G_GotoNextLevel() only works if gamestate == GS_LEVEL.

@JNechaevsky
Copy link
Collaborator Author

I'll investigate it then. Correction itself is very straight-forward, but how it should work with possible UMAPINFO replacement - really no idea. But honestly, I'm not really a Boom-person either. 😐

@rfomin
Copy link
Collaborator

rfomin commented Apr 23, 2024

Woof behaves same way.

In Woof, G_GotoNextLevel() only works if gamestate == GS_LEVEL.

Woof can restart level if gamestate == GS_INTERMISSION, see https://github.com/fabiangreffrath/woof/blob/8f0ba6e119ad6bd3c9db5d82e14ad832df732b04/src/g_game.c#L1252-L1258 (it works in multiplayer too)

@JNechaevsky
Copy link
Collaborator Author

The idea behind != GS_DEMOSCREEN was to allow to restart/goto next even on text screen, if user accidently have passed tally screen.

@rfomin
Copy link
Collaborator

rfomin commented Apr 23, 2024

The idea behind != GS_DEMOSCREEN was to allow to restart/goto next even on text screen, if user accidently have passed tally screen.

Maybe we should be more conservative and just add a restart on the tally screen? Other options are not very practical.

@fabiangreffrath
Copy link
Owner

I'd agree with (gamestate == GS_LEVEL || gamestate == GS_INTERMISSION) for the reload level case. I'd prefer to explicit allow two game states than forbid the others.

@@ -627,7 +627,7 @@ void MN_DrTextA(const char *text, int x, int y)

while ((c = *text++) != 0)
{
if (c < 33)
if (c < 33 || c > 91) // [crispy] fail-safe: draw patches above FONTA59 as spaces
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a Right Thing to do in terms of fail-safe, but there is still some potential for improvement. Small example, I'm using British Antigua and Barbuda locale, which is using lowercase for am/pm designation. Unlike Doom, Heretic can't handle lowercase characters, that's why all game strings are always uppercased. In this case, designation can't appear:

image

Possible solution is to forcefully convert lower case chars to uppercase, this will do the trick:

    while ((c = *text++) != 0)
    {
+++        if (c > 96 && c < 123) // means, all ASCII chars "a" ... "z"
+++            c -= 32;           // ... will be reindexed to "A" ... "Z"

But how to properly make this condition friendly with newly introduced || c > 91) and avoid messy maze of conditions, that's a good question. 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like this, but needs support for big font (it doesn't have [ symbol (№59) which is a cursor) and probably smarter conditions for indexes checking.

+++ international-doom/src/heretic/mn_menu.c	Wed Apr 24 08:41:20 2024
@@ -4148,6 +4148,24 @@
 //
 //---------------------------------------------------------------------------
 
+static const char MN_CheckValidChar (char ascii_index, int small_font)
+{
+    // Following characters not exising in font graphics, replace with spaces:
+    // \ ] ^ _ { | } ~
+    if ((ascii_index >= 92 && ascii_index <= 96) || ascii_index >= 123)
+    {
+        return 32;
+    }
+    // Force lowercase a...z characters to uppercase A...Z.
+    if (ascii_index >= 97 && ascii_index <= 122)
+    {
+        return ascii_index -= 32;
+    }
+
+    // Valid char, do not modify ASCII index.
+    return ascii_index;
+}
+
 void MN_DrTextA (const char *text, int x, int y, byte *table)
 {
     char c;
@@ -4157,6 +4175,8 void MN_DrTextA (const char *text, int x, int y, byte *table) @@
 
     while ((c = *text++) != 0)
     {
+        c = MN_CheckValidChar(c, 1);
+
         if (c < 33)
         {
             x += 5;

image

This way, even such messy string will work: E1M1: THE \\ {|} ~ dOcKs

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.

None yet

3 participants