diff --git a/src/c_console.cpp b/src/c_console.cpp index e717ecba86..77afd6a29a 100644 --- a/src/c_console.cpp +++ b/src/c_console.cpp @@ -131,8 +131,6 @@ static GameAtExit *ExitCmdList; EXTERN_CVAR (Bool, show_messages) -static bool ConsoleDrawing; - // Buffer for AddToConsole() static char *work = NULL; static int worklen = 0; @@ -586,49 +584,6 @@ CUSTOM_CVAR (Int, msgmidcolor2, 4, CVAR_ARCHIVE) setmsgcolor (PRINTLEVELS+1, self); } -struct TextQueue -{ - TextQueue (bool notify, int printlevel, const char *text) - : Next(NULL), bNotify(notify), PrintLevel(printlevel), Text(text) - { - } - TextQueue *Next; - bool bNotify; - int PrintLevel; - FString Text; -}; - -TextQueue *EnqueuedText, **EnqueuedTextTail = &EnqueuedText; - -void EnqueueConsoleText (bool notify, int printlevel, const char *text) -{ - TextQueue *queued = new TextQueue (notify, printlevel, text); - *EnqueuedTextTail = queued; - EnqueuedTextTail = &queued->Next; -} - -void DequeueConsoleText () -{ - TextQueue *queued = EnqueuedText; - - while (queued != NULL) - { - TextQueue *next = queued->Next; - if (queued->bNotify) - { - NotifyStrings.AddString(queued->PrintLevel, queued->Text); - } - else - { - AddToConsole (queued->PrintLevel, queued->Text); - } - delete queued; - queued = next; - } - EnqueuedText = NULL; - EnqueuedTextTail = &EnqueuedText; -} - EColorRange C_GetDefaultFontColor() { // Ideally this should analyze the SmallFont and pick a matching color. @@ -827,12 +782,6 @@ void FNotifyBuffer::AddString(int printlevel, FString source) con_notifylines == 0) return; - if (ConsoleDrawing) - { - EnqueueConsoleText (true, printlevel, source); - return; - } - width = DisplayWidth / active_con_scaletext(con_consolefont); FFont *font = *con_consolefont ? NewConsoleFont : SmallFont; @@ -888,11 +837,51 @@ void FNotifyBuffer::AddString(int printlevel, FString source) void AddToConsole (int printlevel, const char *text) { - conbuffer->AddText(printlevel, MakeUTF8(text), Logfile); + conbuffer->AddText(printlevel, MakeUTF8(text)); } -int PrintString (int printlevel, const char *outline) +//========================================================================== +// +// +// +//========================================================================== + +void WriteLineToLog(FILE *LogFile, const char *outline) { + // Strip out any color escape sequences before writing to the log file + TArray copy(strlen(outline) + 1); + const char * srcp = outline; + char * dstp = copy.Data(); + + while (*srcp != 0) + { + + if (*srcp != TEXTCOLOR_ESCAPE) + { + *dstp++ = *srcp++; + } + else if (srcp[1] == '[') + { + srcp += 2; + while (*srcp != ']' && *srcp != 0) srcp++; + if (*srcp == ']') srcp++; + } + else + { + if (srcp[1] != 0) srcp += 2; + else break; + } + } + *dstp = 0; + + fputs(copy.Data(), LogFile); + fflush(LogFile); +} + + +int PrintString (int iprintlevel, const char *outline) +{ + int printlevel = iprintlevel & PRINT_TYPES; if (printlevel < msglevel || *outline == '\0') { return 0; @@ -907,16 +896,15 @@ int PrintString (int printlevel, const char *outline) { I_PrintStr(outline); - conbuffer->AddText(printlevel, outline, Logfile); - if (vidactive && screen && SmallFont) + conbuffer->AddText(printlevel, outline); + if (vidactive && screen && SmallFont && !(iprintlevel & PRINT_NONOTIFY)) { NotifyStrings.AddString(printlevel, outline); } } - else if (Logfile != nullptr) + if (Logfile != nullptr && !(iprintlevel & PRINT_NOLOG)) { - fputs(outline, Logfile); - fflush(Logfile); + WriteLineToLog(Logfile, outline); } return count; } @@ -1220,8 +1208,6 @@ void C_DrawConsole () int bottomline = ConBottom / textScale - CurrentConsoleFont->GetHeight()*2 - 4; - ConsoleDrawing = true; - for(FBrokenLines *p = printline; p >= blines && lines > 0; p--, lines--) { if (textScale == 1) @@ -1237,8 +1223,6 @@ void C_DrawConsole () } } - ConsoleDrawing = false; - if (ConBottom >= 20) { if (gamestate != GS_STARTUP) @@ -1758,27 +1742,19 @@ CCMD (echo) /* Printing in the middle of the screen */ -CVAR (Float, con_midtime, 3.f, CVAR_ARCHIVE) +CVAR(Float, con_midtime, 3.f, CVAR_ARCHIVE) -static const char bar1[] = TEXTCOLOR_RED "\n\35\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36" - "\36\36\36\36\36\36\36\36\36\36\36\36\37" TEXTCOLOR_TAN "\n"; -static const char bar2[] = TEXTCOLOR_RED "\n\35\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36" - "\36\36\36\36\36\36\36\36\36\36\36\36\37" TEXTCOLOR_GREEN "\n"; -static const char bar3[] = TEXTCOLOR_RED "\n\35\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36" - "\36\36\36\36\36\36\36\36\36\36\36\36\37" TEXTCOLOR_NORMAL "\n"; +const char *console_bar = "----------------------------------------"; -void C_MidPrint (FFont *font, const char *msg) +void C_MidPrint (FFont *font, const char *msg, bool bold) { - if (StatusBar == NULL || screen == NULL) + if (StatusBar == nullptr || screen == nullptr) return; - if (msg != NULL) + if (msg != nullptr) { - AddToConsole (-1, bar1); - AddToConsole (-1, msg); - AddToConsole (-1, bar3); - - auto color = (EColorRange)PrintColors[PRINTLEVELS]; + auto color = (EColorRange)PrintColors[bold? PRINTLEVELS+1 : PRINTLEVELS]; + Printf(PRINT_NONOTIFY, TEXTCOLOR_ESCAPESTR "%c%s\n%s\n%s\n", color, console_bar, msg, console_bar); bool altscale = false; if (font == nullptr) @@ -1797,32 +1773,6 @@ void C_MidPrint (FFont *font, const char *msg) } } -void C_MidPrintBold (FFont *font, const char *msg) -{ - if (msg) - { - AddToConsole (-1, bar2); - AddToConsole (-1, msg); - AddToConsole (-1, bar3); - - auto color = (EColorRange)PrintColors[PRINTLEVELS+1]; - bool altscale = false; - if (font == nullptr) - { - altscale = con_midconsolefont; - font = altscale ? NewConsoleFont : SmallFont; - if (altscale && color == CR_UNTRANSLATED) color = C_GetDefaultFontColor(); - } - - StatusBar->AttachMessage (Create (font, msg, 1.5f, 0.375f, 0, 0, - color, con_midtime, altscale), MAKE_ID('C','N','T','R')); - } - else - { - StatusBar->DetachMessage (MAKE_ID('C','N','T','R')); - } -} - DEFINE_ACTION_FUNCTION(_Console, MidPrint) { PARAM_PROLOGUE; @@ -1831,8 +1781,7 @@ DEFINE_ACTION_FUNCTION(_Console, MidPrint) PARAM_BOOL(bold); const char *txt = text[0] == '$'? GStrings(&text[1]) : text.GetChars(); - if (!bold) C_MidPrint(fnt, txt); - else C_MidPrintBold(fnt, txt); + C_MidPrint(fnt, txt, bold); return 0; } diff --git a/src/c_console.h b/src/c_console.h index 41fcd1eb0f..276c8b7933 100644 --- a/src/c_console.h +++ b/src/c_console.h @@ -78,8 +78,7 @@ void C_AdjustBottom (void); void C_FlushDisplay (void); class FFont; -void C_MidPrint (FFont *font, const char *message); -void C_MidPrintBold (FFont *font, const char *message); +void C_MidPrint (FFont *font, const char *message, bool bold = false); bool C_Responder (event_t *ev); @@ -87,4 +86,6 @@ void C_AddTabCommand (const char *name); void C_RemoveTabCommand (const char *name); void C_ClearTabCommands(); // Removes all tab commands +extern const char *console_bar; + #endif diff --git a/src/c_consolebuffer.cpp b/src/c_consolebuffer.cpp index 0d0d0bc030..2c8f99de00 100644 --- a/src/c_consolebuffer.cpp +++ b/src/c_consolebuffer.cpp @@ -55,33 +55,6 @@ FConsoleBuffer::FConsoleBuffer() mBrokenStart.Push(0); } -//========================================================================== -// -// -// -//========================================================================== - -FConsoleBuffer::~FConsoleBuffer() -{ - FreeBrokenText(); -} - -//========================================================================== -// -// -// -//========================================================================== - -void FConsoleBuffer::FreeBrokenText(unsigned start, unsigned end) -{ - if (end > m_BrokenConsoleText.Size()) end = m_BrokenConsoleText.Size(); - for (unsigned i = start; i < end; i++) - { - m_BrokenConsoleText[i].Clear(); - m_BrokenConsoleText[i].ShrinkToFit(); - } -} - //========================================================================== // // Adds a new line of text to the console @@ -95,7 +68,7 @@ void FConsoleBuffer::FreeBrokenText(unsigned start, unsigned end) // //========================================================================== -void FConsoleBuffer::AddText(int printlevel, const char *text, FILE *logfile) +void FConsoleBuffer::AddText(int printlevel, const char *text) { FString build = TEXTCOLOR_TAN; @@ -135,117 +108,9 @@ void FConsoleBuffer::AddText(int printlevel, const char *text, FILE *logfile) mAddType = APPENDLINE; } - // don't bother about linefeeds etc. inside the text, we'll let the formatter sort this out later. + // don't bother with linefeeds etc. inside the text, we'll let the formatter sort this out later. build.AppendCStrPart(text, textsize); mConsoleText.Push(build); - if (logfile != NULL) WriteLineToLog(logfile, text); -} - -//========================================================================== -// -// -// -//========================================================================== - -void FConsoleBuffer::WriteLineToLog(FILE *LogFile, const char *outline) -{ - // Strip out any color escape sequences before writing to the log file - TArray copy(strlen(outline)+1); - const char * srcp = outline; - char * dstp = copy.Data(); - - while (*srcp != 0) - { - - if (*srcp != TEXTCOLOR_ESCAPE) - { - switch (*srcp) - { - case '\35': - *dstp++ = '<'; - break; - - case '\36': - *dstp++ = '-'; - break; - - case '\37': - *dstp++ = '>'; - break; - - default: - *dstp++=*srcp; - break; - } - srcp++; - } - else if (srcp[1] == '[') - { - srcp+=2; - while (*srcp != ']' && *srcp != 0) srcp++; - if (*srcp == ']') srcp++; - } - else - { - if (srcp[1]!=0) srcp+=2; - else break; - } - } - *dstp=0; - - fputs (copy.Data(), LogFile); - fflush (LogFile); -} - -//========================================================================== -// -// -// -//========================================================================== - -void FConsoleBuffer::WriteContentToLog(FILE *LogFile) -{ - if (LogFile != NULL) - { - for (unsigned i = 0; i < mConsoleText.Size(); i++) - { - WriteLineToLog(LogFile, mConsoleText[i]); - } - } -} - -//========================================================================== -// -// ensures that the following text is not appended to the current line. -// -//========================================================================== - -void FConsoleBuffer::Linefeed(FILE *Logfile) -{ - if (mAddType != NEWLINE && Logfile != NULL) fputc('\n', Logfile); - mAddType = NEWLINE; -} - -//========================================================================== -// -// -// -//========================================================================== - -static const char bar1[] = TEXTCOLOR_RED "\35\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36" - "\36\36\36\36\36\36\36\36\36\36\36\36\37" TEXTCOLOR_TAN "\n"; -static const char bar2[] = TEXTCOLOR_RED "\35\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36" - "\36\36\36\36\36\36\36\36\36\36\36\36\37" TEXTCOLOR_GREEN "\n"; -static const char bar3[] = TEXTCOLOR_RED "\35\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36" - "\36\36\36\36\36\36\36\36\36\36\36\36\37" TEXTCOLOR_NORMAL "\n"; - -void FConsoleBuffer::AddMidText(const char *string, bool bold, FILE *Logfile) -{ - Linefeed(Logfile); - AddText (-1, bold? bar2 : bar1, Logfile); - AddText (-1, string, Logfile); - Linefeed(Logfile); - AddText(-1, bar3, Logfile); } //========================================================================== @@ -258,7 +123,6 @@ void FConsoleBuffer::FormatText(FFont *formatfont, int displaywidth) { if (formatfont != mLastFont || displaywidth != mLastDisplayWidth || mBufferWasCleared) { - FreeBrokenText(); m_BrokenConsoleText.Clear(); mBrokenStart.Clear(); mBrokenStart.Push(0); diff --git a/src/c_consolebuffer.h b/src/c_consolebuffer.h index 1b46156b29..98a42b42e4 100644 --- a/src/c_consolebuffer.h +++ b/src/c_consolebuffer.h @@ -61,19 +61,12 @@ class FConsoleBuffer int mLastDisplayWidth; bool mLastLineNeedsUpdate; - void WriteLineToLog(FILE *LogFile, const char *outline); - void FreeBrokenText(unsigned int start = 0, unsigned int end = INT_MAX); - - void Linefeed(FILE *Logfile); public: FConsoleBuffer(); - ~FConsoleBuffer(); - void AddText(int printlevel, const char *string, FILE *logfile = NULL); - void AddMidText(const char *string, bool bold, FILE *logfile); + void AddText(int printlevel, const char *string); void FormatText(FFont *formatfont, int displaywidth); void ResizeBuffer(unsigned newsize); - void WriteContentToLog(FILE *logfile); void Clear() { mBufferWasCleared = true; diff --git a/src/doomtype.h b/src/doomtype.h index a5f38e2d04..47a636552f 100644 --- a/src/doomtype.h +++ b/src/doomtype.h @@ -89,7 +89,10 @@ enum PRINT_CHAT, // chat messages PRINT_TEAMCHAT, // chat messages from a teammate PRINT_LOG, // only to logfile - PRINT_BOLD = 200 // What Printf_Bold used + PRINT_BOLD = 200, // What Printf_Bold used + PRINT_TYPES = 1023, // Bitmask. + PRINT_NONOTIFY = 1024, // Flag - do not add to notify buffer + PRINT_NOLOG = 2048, // Flag - do not print to log file }; enum diff --git a/src/g_level.cpp b/src/g_level.cpp index 66a8b9c57a..6f90326b31 100644 --- a/src/g_level.cpp +++ b/src/g_level.cpp @@ -1062,12 +1062,8 @@ void FLevelLocals::DoLoadLevel(const FString &nextmapname, int position, bool au if (isPrimaryLevel()) { FString mapname = nextmapname; - mapname.ToLower(); - Printf( - "\n\35\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36" - "\36\36\36\36\36\36\36\36\36\36\36\36\37\n\n" - TEXTCOLOR_BOLD "%s - %s\n\n", - mapname.GetChars(), LevelName.GetChars()); + mapname.ToUpper(); + Printf("\n%s\n\n" TEXTCOLOR_BOLD "%s - %s\n\n", console_bar, mapname.GetChars(), LevelName.GetChars()); } // Set the sky map. diff --git a/src/gamedata/fonts/v_text.h b/src/gamedata/fonts/v_text.h index 90c38d44c7..365674b521 100644 --- a/src/gamedata/fonts/v_text.h +++ b/src/gamedata/fonts/v_text.h @@ -44,6 +44,7 @@ struct FBrokenLines }; #define TEXTCOLOR_ESCAPE '\034' +#define TEXTCOLOR_ESCAPESTR "\034" #define TEXTCOLOR_BRICK "\034A" #define TEXTCOLOR_TAN "\034B" diff --git a/src/p_acs.cpp b/src/p_acs.cpp index e5c338b00c..76d26b742d 100644 --- a/src/p_acs.cpp +++ b/src/p_acs.cpp @@ -536,8 +536,6 @@ -extern FILE *Logfile; - FRandom pr_acs ("ACS"); // I imagine this much stack space is probably overkill, but it could @@ -8614,10 +8612,7 @@ scriptwait: if (pcd == PCD_ENDPRINTBOLD || screen == NULL || screen->CheckLocalView()) { - if (pcd == PCD_ENDPRINTBOLD && (gameinfo.correctprintbold || (Level->flags2 & LEVEL2_HEXENHACK))) - C_MidPrintBold(activefont, work); - else - C_MidPrint (activefont, work); + C_MidPrint (activefont, work, pcd == PCD_ENDPRINTBOLD && (gameinfo.correctprintbold || (Level->flags2 & LEVEL2_HEXENHACK))); } STRINGBUILDER_FINISH(work); } @@ -8720,17 +8715,8 @@ scriptwait: (type & HUDMSG_LAYER_MASK) >> HUDMSG_LAYER_SHIFT); if (type & HUDMSG_LOG) { - static const char bar[] = TEXTCOLOR_ORANGE "\n\35\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36" - "\36\36\36\36\36\36\36\36\36\36\36\36\37" TEXTCOLOR_NORMAL "\n"; - char consolecolor[3]; - - consolecolor[0] = '\x1c'; - consolecolor[1] = color >= CR_BRICK && color <= CR_YELLOW ? color + 'A' : '-'; - consolecolor[2] = '\0'; - AddToConsole (-1, bar); - AddToConsole (-1, consolecolor); - AddToConsole (-1, work); - AddToConsole (-1, bar); + int consolecolor = color >= CR_BRICK && color <= CR_YELLOW ? color + 'A' : '-'; + Printf(PRINT_NONOTIFY, "\n" TEXTCOLOR_ESCAPESTR "%c%s\n%s\n%s\n", consolecolor, console_bar, work, console_bar); } } } diff --git a/src/p_actionfunctions.cpp b/src/p_actionfunctions.cpp index 24f4d68b87..afd7049094 100644 --- a/src/p_actionfunctions.cpp +++ b/src/p_actionfunctions.cpp @@ -1341,7 +1341,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_PrintBold) con_midtime = float(time); } FString formatted = strbin1(text); - C_MidPrintBold(font, formatted.GetChars()); + C_MidPrint(font, formatted.GetChars(), true); con_midtime = saved; return 0; } diff --git a/src/p_conversation.cpp b/src/p_conversation.cpp index b94d19535d..6f3bec89b5 100644 --- a/src/p_conversation.cpp +++ b/src/p_conversation.cpp @@ -695,8 +695,7 @@ static void TerminalResponse (const char *str) if (StatusBar != NULL) { - AddToConsole(-1, str); - AddToConsole(-1, "\n"); + Printf(PRINT_NONOTIFY, "%s\n", str); // The message is positioned a bit above the menu choices, because // merchants can tell you something like this but continue to show // their dialogue screen. I think most other conversations use this diff --git a/src/p_user.cpp b/src/p_user.cpp index 1833641246..baaafc5409 100644 --- a/src/p_user.cpp +++ b/src/p_user.cpp @@ -426,9 +426,7 @@ void player_t::SetLogText (const char *text) if (mo && mo->CheckLocalView()) { // Print log text to console - AddToConsole(-1, TEXTCOLOR_GOLD); - AddToConsole(-1, LogText[0] == '$'? GStrings(text+1) : text ); - AddToConsole(-1, "\n"); + Printf(PRINT_NONOTIFY, TEXTCOLOR_GOLD, "%s\n", LogText[0] == '$' ? GStrings(text + 1) : text); } }