From 6804e662083366efa8037ced9a69885b4aefbb40 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 26 Dec 2007 09:56:09 +0000 Subject: [PATCH] - Replaced 'C:\\ZDOOMDAT' with a #define in version.h. - Moved screenshot code into DCanvas so that it can be overridden by subclasses with a different buffer. SVN r643 (trunk) --- docs/rh-log.txt | 3 ++ src/d_main.cpp | 2 +- src/g_game.cpp | 2 +- src/gameconfigfile.cpp | 4 +-- src/m_misc.cpp | 70 ++++++++++++++++++++++++------------------ src/v_video.h | 7 +++++ src/version.h | 3 ++ 7 files changed, 57 insertions(+), 34 deletions(-) diff --git a/docs/rh-log.txt b/docs/rh-log.txt index 78dccf486d..706b9df55c 100644 --- a/docs/rh-log.txt +++ b/docs/rh-log.txt @@ -9,6 +9,9 @@ December 25, 2007 minor win for cards that support it. December 25, 2007 (Changes by Graf Zahl) +- Replaced 'C:\\ZDOOMDAT' with a #define in version.h. +- Moved screenshot code into DCanvas so that it can be overridden by + subclasses with a different buffer. - added a P_PointInSector function and replaced all calls to retrieve an actor's sector in the game engine code with it. This way there's a clear distinction between renderer-specific and game-specific calls. diff --git a/src/d_main.cpp b/src/d_main.cpp index 3a418e8f5c..4cab10cbfc 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -2259,7 +2259,7 @@ void D_DoomMain (void) if (Args.CheckParm("-cdrom")) { Printf (GStrings("D_CDROM")); - mkdir ("c:\\zdoomdat", 0); + mkdir (CDROM_DIR, 0); } #endif diff --git a/src/g_game.cpp b/src/g_game.cpp index 2711c006c7..29d2e408b7 100644 --- a/src/g_game.cpp +++ b/src/g_game.cpp @@ -1850,7 +1850,7 @@ FString G_BuildSaveName (const char *prefix, int slot) #ifndef unix else if (Args.CheckParm ("-cdrom")) { - leader = "c:/zdoomdat/"; + leader = CDROM_DIR "/"; } else { diff --git a/src/gameconfigfile.cpp b/src/gameconfigfile.cpp index 50f4b0b2bb..b29e0873bf 100644 --- a/src/gameconfigfile.cpp +++ b/src/gameconfigfile.cpp @@ -569,7 +569,7 @@ FString FGameConfigFile::GetConfigPath (bool tryProg) if (path.IsEmpty()) { if (Args.CheckParm ("-cdrom")) - return "c:\\zdoomdat\\zdoom.ini"; + return CDROM_DIR "\\zdoom.ini"; path = progdir; path += "zdoom.ini"; @@ -617,7 +617,7 @@ void FGameConfigFile::AddAutoexec (DArgs *list, const char *game) #ifndef unix if (Args.CheckParm ("-cdrom")) { - path = "c:\\zdoomdat\\autoexec.cfg"; + path = CDROM_DIR "\\autoexec.cfg"; } else { diff --git a/src/m_misc.cpp b/src/m_misc.cpp index 80cb5c1a0d..7478844028 100644 --- a/src/m_misc.cpp +++ b/src/m_misc.cpp @@ -306,9 +306,9 @@ FString GetUserFile (const char *file, bool nodir) FString path = home; if (path[path.Len()-1] != '/') - path += nodir ? "/" : "/.zdoom"; + path += nodir ? "/" : "/"GAME_DIR; else if (!nodir) - path += ".zdoom"; + path += GAME_DIR; if (!nodir) { @@ -542,7 +542,7 @@ void WritePCXfile (FILE *file, const DCanvas *canvas, const PalEntry *palette) void WritePNGfile (FILE *file, const DCanvas *canvas, const PalEntry *palette) { if (!M_CreatePNG (file, canvas, palette) || - !M_AppendPNGText (file, "Software", "ZDoom " DOTVERSIONSTR) || + !M_AppendPNGText (file, "Software", GAMENAME DOTVERSIONSTR) || !M_FinishPNG (file)) { Printf ("Could not create screenshot.\n"); @@ -572,9 +572,8 @@ static bool FindFreeName (FString &fullname, const char *extension) void M_ScreenShot (const char *filename) { - FILE *file; FString autoname; - bool writepcx = (stricmp (screenshot_type, "pcx") == 0); // PNG is the default + bool writepcx = screen->CanWritePCX() && (stricmp (screenshot_type, "pcx") == 0); // PNG is the default // find a file name to save it to if (filename == NULL || filename[0] == '\0') @@ -582,7 +581,7 @@ void M_ScreenShot (const char *filename) #ifndef unix if (Args.CheckParm ("-cdrom")) { - autoname = "C:\\ZDOOMDAT\\"; + autoname = CDROM_DIR "\\"; } else #endif @@ -615,30 +614,7 @@ void M_ScreenShot (const char *filename) CreatePath(screenshot_dir); // save the screenshot - screen->Lock (true); - //D_Display (true); - - PalEntry palette[256]; - screen->GetFlashedPalette (palette); - - file = fopen (autoname.GetChars(), "wb"); - if (file == NULL) - { - Printf ("Could not open %s\n", autoname.GetChars()); - screen->Unlock (); - return; - } - - if (writepcx) - { - WritePCXfile (file, screen, palette); - } - else - { - WritePNGfile (file, screen, palette); - } - fclose (file); - screen->Unlock (); + screen->Save(autoname, writepcx); if (!screenshot_quiet) { @@ -646,6 +622,40 @@ void M_ScreenShot (const char *filename) } } +bool DCanvas::CanWritePCX() +{ + return true; +} + +void DCanvas::Save(const char *filename, bool writepcx) +{ + FILE *file; + + Lock (true); + + PalEntry palette[256]; + screen->GetFlashedPalette (palette); + + file = fopen (filename, "wb"); + if (file == NULL) + { + Printf ("Could not open %s\n", filename); + Unlock (); + return; + } + + if (writepcx) + { + WritePCXfile (file, this, palette); + } + else + { + WritePNGfile (file, this, palette); + } + fclose (file); + Unlock (); +} + CCMD (screenshot) { if (argv.argc() == 1) diff --git a/src/v_video.h b/src/v_video.h index 294ef598df..c74b1a3d99 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -142,6 +142,7 @@ public: // Access control virtual bool Lock () = 0; // Returns true if the surface was lost since last time + virtual bool Lock (bool usesimplecanvas) { return Lock(); } virtual void Unlock () = 0; virtual bool IsLocked () { return Buffer != NULL; } // Returns true if the surface is locked @@ -181,6 +182,12 @@ public: // Can be overridden so that the colormaps for sector color/fade won't be built. virtual bool UsesColormap() const; + // software renderer always returns true but other renderers may not want to implement PCX. + bool CanWritePCX(); + + // Saves canvas to a file + void Save(const char *filename, bool writepcx); + // Text drawing functions ----------------------------------------------- virtual void SetFont (FFont *font); diff --git a/src/version.h b/src/version.h index 897a13aa95..0d1c098a15 100644 --- a/src/version.h +++ b/src/version.h @@ -86,6 +86,9 @@ #ifdef unix #define HOME_DIR "~/.zdoom" +#define GAME_DIR ".zdoom" +#else +#define CDROM_DIR "C:\\ZDOOMDAT" #endif // MINSAVEVER is the minimum level snapshot version that can be loaded.