- Printf related cleanup.

This commit is contained in:
Christoph Oelckers 2019-11-05 20:07:16 +01:00
parent d943fe036d
commit a4483f131d
20 changed files with 86 additions and 160 deletions

View file

@ -22,6 +22,8 @@ include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/../common/utility
${CMAKE_CURRENT_SOURCE_DIR}/../common/console
${CMAKE_CURRENT_SOURCE_DIR}/../common/textures
${CMAKE_CURRENT_SOURCE_DIR}/../common/fonts
${CMAKE_CURRENT_SOURCE_DIR}/../common/2d
${CMAKE_CURRENT_SOURCE_DIR}/../platform
)

View file

@ -31,13 +31,12 @@
#include "inputstate.h"
#include "c_cvars.h"
#include "i_time.h"
#include "c_dispatch.h"
#ifndef NETCODE_DISABLE
#include "enet.h"
#endif
#include "../../glbackend/glbackend.h"
bool gHaveNetworking;
#ifdef USE_OPENGL
# include "glbuild.h"
# include "glsurface.h"
@ -130,8 +129,6 @@ static SDL_Surface *appicon = NULL;
static SDL_Surface *loadappicon(void);
#endif
static mutex_t m_initprintf;
// Joystick dead and saturation zones
uint16_t joydead[9], joysatur[9];
@ -391,6 +388,7 @@ static void sighandler(int signum)
}
#endif
int GameMain();
#ifdef _WIN32
@ -453,34 +451,7 @@ int main(int argc, char *argv[])
if (initsystem()) Bexit(9);
try
{
// Write to the DOCUMENTS directory, not the game directory
// Initialize the netcode here, because enet pulls in a lot of headers that pollute the namespace.
#ifndef NETCODE_DISABLE
gHaveNetworking = !enet_initialize();
if (!gHaveNetworking)
initprintf("An error occurred while initializing ENet.\n");
#endif
FString logpath = M_GetDocumentsPath() + "demolition.log";
OSD_SetLogFile(logpath);
r = CONFIG_Init();
}
catch (const std::runtime_error & err)
{
wm_msgbox("Error", "%s", err.what());
return 3;
}
catch (const ExitEvent & exit)
{
// Just let the rest of the function execute.
r = exit.Reason();
}
#ifndef NETCODE_DISABLE
if (gHaveNetworking) enet_deinitialize();
#endif
r = GameMain();
#if defined(HAVE_GTK2)
gtkbuild_exit(r);
@ -539,6 +510,7 @@ int32_t sdlayer_checkversion(void);
#if SDL_MAJOR_VERSION != 1
int32_t sdlayer_checkversion(void)
{
#if 0
SDL_version compiled;
SDL_GetVersion(&linked);
@ -559,6 +531,7 @@ int32_t sdlayer_checkversion(void)
return -1;
}
#endif
return 0;
}
@ -569,12 +542,6 @@ int32_t initsystem(void)
{
const int sdlinitflags = SDL_INIT_VIDEO;
mutex_init(&m_initprintf);
#ifdef _WIN32
win_init();
#endif
if (sdlayer_checkversion())
return -1;

View file

@ -43,14 +43,8 @@
#include "cmdlib.h"
#include "c_dispatch.h"
#include "printf.h"
//#include "g_game.h"
//#include "d_player.h"
//#include "v_video.h"
//#include "d_netinf.h"
//#include "menu/menu.h"
//#include "vm.h"
struct FLatchedValue
{

View file

@ -865,6 +865,11 @@ FExecList *C_ParseCmdLineParams(FExecList *exec)
return exec;
}
void FConsoleCommand::PrintCommand()
{
Printf("%s\n", m_Name.GetChars());
}
bool FConsoleCommand::IsAlias ()
{
return false;

View file

@ -34,7 +34,7 @@
#ifndef __C_DISPATCH_H__
#define __C_DISPATCH_H__
#include "printf.h"
#include "c_console.h"
#include "zstring.h"
#include "c_commandline.h"
#include "zstring.h"
@ -87,7 +87,7 @@ public:
FConsoleCommand (const char *name, CCmdRun RunFunc);
virtual ~FConsoleCommand ();
virtual bool IsAlias ();
void PrintCommand () { Printf ("%s\n", m_Name.GetChars()); }
void PrintCommand();
virtual void Run (FCommandLine &args, void *instigator, int key);
static FConsoleCommand* FindByName (const char* name);

View file

@ -35,7 +35,7 @@
#include <time.h>
#include <algorithm>
#include "osd.h"
#include "printf.h"
#include "file_zip.h"
#include "ancientzip.h"
#include "templates.h"
@ -96,7 +96,7 @@ static bool UncompressZipLump(char *Cache, FileReader &Reader, int Method, int L
}
catch (const std::runtime_error &err)
{
OSD_Printf("%s\n", err.what());
Printf("%s\n", err.what());
return false;
}
return true;
@ -181,7 +181,7 @@ bool FZipFile::Open(bool quiet)
if (centraldir == 0)
{
if (!quiet) OSD_Printf("\n%s: ZIP file corrupt!\n", FileName.GetChars());
if (!quiet) Printf("\n%s: ZIP file corrupt!\n", FileName.GetChars());
return false;
}
@ -193,7 +193,7 @@ bool FZipFile::Open(bool quiet)
if (info.NumEntries != info.NumEntriesOnAllDisks ||
info.FirstDisk != 0 || info.DiskNumber != 0)
{
if (!quiet) OSD_Printf("\n%s: Multipart Zip files are not supported.\n", FileName.GetChars());
if (!quiet) Printf("\n%s: Multipart Zip files are not supported.\n", FileName.GetChars());
return false;
}
@ -226,7 +226,7 @@ bool FZipFile::Open(bool quiet)
if (dirptr > ((char*)directory) + dirsize) // This directory entry goes beyond the end of the file.
{
free(directory);
if (!quiet) OSD_Printf("\n%s: Central directory corrupted.", FileName.GetChars());
if (!quiet) Printf("\n%s: Central directory corrupted.", FileName.GetChars());
return false;
}
@ -246,7 +246,7 @@ bool FZipFile::Open(bool quiet)
zip_fh->Method != METHOD_IMPLODE &&
zip_fh->Method != METHOD_SHRINK)
{
if (!quiet) OSD_Printf("\n%s: '%s' uses an unsupported compression algorithm (#%d).\n", FileName.GetChars(), name.GetChars(), zip_fh->Method);
if (!quiet) Printf("\n%s: '%s' uses an unsupported compression algorithm (#%d).\n", FileName.GetChars(), name.GetChars(), zip_fh->Method);
skipped++;
continue;
}
@ -254,7 +254,7 @@ bool FZipFile::Open(bool quiet)
zip_fh->Flags = LittleShort(zip_fh->Flags);
if (zip_fh->Flags & ZF_ENCRYPTED)
{
if (!quiet) OSD_Printf("\n%s: '%s' is encrypted. Encryption is not supported.\n", FileName.GetChars(), name.GetChars());
if (!quiet) Printf("\n%s: '%s' is encrypted. Encryption is not supported.\n", FileName.GetChars(), name.GetChars());
skipped++;
continue;
}

View file

@ -713,16 +713,18 @@ void V_InitFonts()
FFont *CreateHexLumpFont(const char *fontname, const char* lump);
FFont *CreateHexLumpFont2(const char *fontname, const char * lump);
auto lump = kopenFileReader("newconsolefont.hex", 0); // This is always loaded from gzdoom.pk3 to prevent overriding it with incomplete replacements.
if (!lump.isOpen()) I_Error("newconsolefont.hex not found"); // This font is needed - do not start up without it.
NewConsoleFont = CreateHexLumpFont("NewConsoleFont", "newconsolefont.hex");
NewSmallFont = CreateHexLumpFont2("NewSmallFont", "newconsolefont.hex");
if (fileSystem.FindFile("demolition/newconsolefont.hex") < 0)
I_Error("newconsolefont.hex not found"); // This font is needed - do not start up without it.
NewConsoleFont = CreateHexLumpFont("NewConsoleFont", "demolition/newconsolefont.hex");
NewSmallFont = CreateHexLumpFont2("NewSmallFont", "demolition/newconsolefont.hex");
CurrentConsoleFont = NewConsoleFont;
/*
ConFont = V_GetFont("ConsoleFont", "CONFONT");
{
ConFont = SmallFont;
}
*/
}
void V_ClearFonts()

View file

@ -17,12 +17,21 @@
#include "rts.h"
#include "printf.h"
#include "c_bind.h"
#include "v_font.h"
#include "c_console.h"
#include "c_dispatch.h"
#include "i_specialpaths.h"
#ifndef NETCODE_DISABLE
#include "enet.h"
#endif
InputState inputState;
void SetClipshapes();
int ShowStartupWindow(TArray<GrpEntry> &);
void InitFileSystem(TArray<GrpEntry>&);
int globalShadeDiv;
bool gHaveNetworking;
FString currentGame;
FString LumpFilter;
@ -221,6 +230,40 @@ void CheckFrontend(int flags)
}
int GameMain()
{
// Set up the console before anything else so that it can receive text.
C_InitConsole(1024, 768, true);
FStringf logpath("logfile %sdemolition.log", M_GetDocumentsPath());
C_DoCommand(logpath);
#ifndef NETCODE_DISABLE
gHaveNetworking = !enet_initialize();
if (!gHaveNetworking)
initprintf("An error occurred while initializing ENet.\n");
#endif
int r;
try
{
r = CONFIG_Init();
}
catch (const std::runtime_error & err)
{
wm_msgbox("Error", "%s", err.what());
return 3;
}
catch (const ExitEvent & exit)
{
// Just let the rest of the function execute.
r = exit.Reason();
}
#ifndef NETCODE_DISABLE
if (gHaveNetworking) enet_deinitialize();
#endif
return r;
}
//==========================================================================
//
//
@ -342,6 +385,7 @@ int CONFIG_Init()
{
playername = userConfig.CommandName;
}
V_InitFonts();

View file

@ -22,6 +22,8 @@ include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/../common/utility
${CMAKE_CURRENT_SOURCE_DIR}/../common/console
${CMAKE_CURRENT_SOURCE_DIR}/../common/textures
${CMAKE_CURRENT_SOURCE_DIR}/../common/fonts
${CMAKE_CURRENT_SOURCE_DIR}/../common/2d
${CMAKE_CURRENT_SOURCE_DIR}/../platform
)

View file

@ -29,6 +29,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "savegame.h"
#include "screens.h"
#include "i_specialpaths.h"
#include "printf.h"
#include "vfs.h"
@ -104,7 +105,7 @@ static int32_t G_OpenDemoRead(int32_t g_whichDemo) // 0 = mine
i = sv_loadsnapshot(g_demo_recFilePtr, -g_whichDemo, &saveh);
if (i)
{
OSD_Printf(OSD_ERROR "There were errors opening demo %d (code: %d).\n", g_whichDemo, i);
Printf(OSD_ERROR "There were errors opening demo %d (code: %d).\n", g_whichDemo, i);
g_demo_recFilePtr.Close();
return 0;
}
@ -183,7 +184,7 @@ void G_OpenDemoWrite(void)
{
MAYBE_FCLOSE_AND_NULL(g_demo_filePtr);
error_wopen_demo:
Bstrcpy(apStrings[QUOTE_RESERVED4], "FAILED STARTING DEMO RECORDING. SEE OSD FOR DETAILS.");
Bstrcpy(apStrings[QUOTE_RESERVED4], "FAILED STARTING DEMO RECORDING. SEE CONSOLE FOR DETAILS.");
P_DoQuote(QUOTE_RESERVED4, g_player[myconnectindex].ps);
ud.recstat = ud.m_recstat = 0;
return;

View file

@ -5710,7 +5710,6 @@ void G_Shutdown(void)
CONTROL_Shutdown();
engineUnInit();
G_Cleanup();
OSD_Cleanup();
Bfflush(NULL);
}
@ -6469,33 +6468,8 @@ MAIN_LOOP_RESTART:
// only allow binds to function if the player is actually in a game (not in a menu, typing, et cetera) or demo
inputState.SetBindsEnabled(!!(myplayer.gm & (MODE_GAME|MODE_DEMO)));
#ifndef _WIN32
// stdin -> OSD input for dedicated server
if (g_networkMode == NET_DEDICATED_SERVER)
{
int32_t nb;
char ch;
static uint32_t bufpos = 0;
static char buf[128];
#ifndef GEKKO
int32_t flag = 1;
ioctl(0, FIONBIO, &flag);
#endif
if ((nb = read(0, &ch, 1)) > 0 && bufpos < sizeof(buf))
{
if (ch != '\n')
buf[bufpos++] = ch;
if (ch == '\n' || bufpos >= sizeof(buf)-1)
{
buf[bufpos] = 0;
OSD_Dispatch(buf);
bufpos = 0;
}
}
}
else
#endif
if (g_networkMode != NET_DEDICATED_SERVER)
G_HandleLocalKeys();
OSD_DispatchQueued();

View file

@ -104,6 +104,7 @@ static inline void VM_DrawTilePalSmall(int32_t x, int32_t y, int32_t tilenum, in
void VM_DrawTileSmall(int32_t x, int32_t y, int32_t tilenum, int32_t shade, int32_t orientation);
#endif
#define CON_ERRPRINTF(Text, ...) do { \
vm.flags |= VM_RETURN; \
OSD_Printf("Line %d, %s: " Text, VM_DECODE_LINE_NUMBER(g_tw), VM_GetKeywordForID(VM_DECODE_INST(g_tw)), ## __VA_ARGS__); \
@ -111,8 +112,7 @@ void VM_DrawTileSmall(int32_t x, int32_t y, int32_t tilenum, int32_t shade, int3
#define CON_CRITICALERRPRINTF(Text, ...) do { \
vm.flags |= VM_RETURN; \
OSD_Printf("Line %d, %s: " Text, VM_DECODE_LINE_NUMBER(g_tw), VM_GetKeywordForID(VM_DECODE_INST(g_tw)), ## __VA_ARGS__); \
wm_msgbox(APPNAME, "Line %d, %s: " Text, VM_DECODE_LINE_NUMBER(g_tw), VM_GetKeywordForID(VM_DECODE_INST(g_tw)), ## __VA_ARGS__); \
I_Error("Line %d, %s: " Text, VM_DECODE_LINE_NUMBER(g_tw), VM_GetKeywordForID(VM_DECODE_INST(g_tw)), ## __VA_ARGS__); \
} while (0)
void G_GetTimeDate(int32_t * pValues);

View file

@ -342,8 +342,6 @@ void Gv_ResetVars(void) /* this is called during a new game and nowhere else */
{
Gv_Free();
osd->log.errors = 0;
for (auto &aGameVar : aGameVars)
{
if (aGameVar.szLabel != NULL)

View file

@ -36,9 +36,9 @@
#import <Foundation/NSFileManager.h>
#include "cmdlib.h"
#include "m_misc.h"
#include "version.h" // for GAMENAME
FString M_GetMacAppSupportPath(const bool create);
static FString GetSpecialPath(const NSSearchPathDirectory kind, const BOOL create = YES, const NSSearchPathDomainMask domain = NSUserDomainMask)
{

View file

@ -14,50 +14,6 @@ FString progdir;
// CheckWinVersion() -- check to see what version of Windows we happen to be running under (stripped down to what is actually still supported.)
//
void win_init(void)
{
const char *ver = "";
OSVERSIONINFOEXA osv;
osv.dwOSVersionInfoSize = sizeof(osv);
GetVersionExA((LPOSVERSIONINFOA)&osv);
switch (osv.dwPlatformId)
{
case VER_PLATFORM_WIN32_NT:
switch (osv.dwMajorVersion)
{
case 6:
switch (osv.dwMinorVersion)
{
case 0: ver = osv.wProductType == VER_NT_WORKSTATION ? "Vista" : "Server 2008"; break;
case 1: ver = osv.wProductType == VER_NT_WORKSTATION ? "7" : "Server 2008 R2"; break;
case 2: ver = osv.wProductType == VER_NT_WORKSTATION ? "8" : "Server 2012"; break;
case 3: ver = osv.wProductType == VER_NT_WORKSTATION ? "8.1" : "Server 2012 R2"; break;
}
break;
case 10:
switch (osv.dwMinorVersion)
{
case 0: ver = osv.wProductType == VER_NT_WORKSTATION ? "10" : "Server 2016"; break;
}
break;
}
break;
}
FStringf str("Windows %s", ver);
// service packs
if (osv.szCSDVersion[0])
{
str.AppendFormat(" %s", osv.szCSDVersion);
}
initprintf("Running on %s (build %lu.%lu.%lu)\n", str.GetChars(), osv.dwMajorVersion, osv.dwMinorVersion, osv.dwBuildNumber);
}
//==========================================================================
//
// win_buildargs

View file

@ -22,6 +22,8 @@ include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/../common/utility
${CMAKE_CURRENT_SOURCE_DIR}/../common/console
${CMAKE_CURRENT_SOURCE_DIR}/../common/textures
${CMAKE_CURRENT_SOURCE_DIR}/../common/fonts
${CMAKE_CURRENT_SOURCE_DIR}/../common/2d
${CMAKE_CURRENT_SOURCE_DIR}/../platform
)

View file

@ -7078,7 +7078,6 @@ void G_Shutdown(void)
G_SetFog(0);
engineUnInit();
G_Cleanup();
OSD_Cleanup();
Bfflush(NULL);
}
@ -7878,26 +7877,6 @@ MAIN_LOOP_RESTART:
// stdin -> OSD input for dedicated server
if (g_networkMode == NET_DEDICATED_SERVER)
{
int32_t nb;
char ch;
static uint32_t bufpos = 0;
static char buf[128];
#ifndef GEKKO
int32_t flag = 1;
ioctl(0, FIONBIO, &flag);
#endif
if ((nb = read(0, &ch, 1)) > 0 && bufpos < sizeof(buf))
{
if (ch != '\n')
buf[bufpos++] = ch;
if (ch == '\n' || bufpos >= sizeof(buf)-1)
{
buf[bufpos] = 0;
OSD_Dispatch(buf);
bufpos = 0;
}
}
}
else
#endif

View file

@ -289,7 +289,6 @@ void G_PrintGameQuotes(int32_t snum);
void G_SetCrosshairColor(int32_t r,int32_t g,int32_t b);
void G_Shutdown(void);
void G_UpdatePlayerFromMenu(void);
void M32RunScript(const char *s);
void P_DoQuote(int32_t q,DukePlayer_t *p);
void P_SetGamePalette(DukePlayer_t *player, uint32_t palid, int32_t set);
void G_OnMotorcycle(DukePlayer_t *pPlayer, int spriteNum);

View file

@ -54,8 +54,7 @@ int32_t __fastcall G_GetAngleDelta(int32_t currAngle, int32_t newAngle);
} while (0)
#define CON_CRITICALERRPRINTF(Text, ...) do { \
OSD_Printf("Line %d, %s: " Text, g_errorLineNum, VM_GetKeywordForID(g_tw), ## __VA_ARGS__); \
wm_msgbox(APPNAME, "Line %d, %s: " Text, g_errorLineNum, VM_GetKeywordForID(g_tw), ## __VA_ARGS__); \
I_Error("Line %d, %s: " Text, VM_DECODE_LINE_NUMBER(g_tw), VM_GetKeywordForID(VM_DECODE_INST(g_tw)), ## __VA_ARGS__); \
} while (0)
void G_GetTimeDate(int32_t * pValues);

View file

@ -22,6 +22,8 @@ include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/../common/utility
${CMAKE_CURRENT_SOURCE_DIR}/../common/console
${CMAKE_CURRENT_SOURCE_DIR}/../common/textures
${CMAKE_CURRENT_SOURCE_DIR}/../common/fonts
${CMAKE_CURRENT_SOURCE_DIR}/../common/2d
${CMAKE_CURRENT_SOURCE_DIR}/../platform
)