mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-11-10 23:02:03 +00:00
- replaced the semi-broken screenshot name generator.
Also took this file out of the 'build' folder, now that all code in here comes from elsewhere. This also removes a few dead declarations.
This commit is contained in:
parent
ee93c6e366
commit
3cb68b2bf0
9 changed files with 170 additions and 221 deletions
|
@ -699,7 +699,6 @@ set (PCH_SOURCES
|
|||
build/src/palette.cpp
|
||||
build/src/polymost.cpp
|
||||
build/src/pragmas.cpp
|
||||
build/src/screenshot.cpp
|
||||
build/src/scriptfile.cpp
|
||||
build/src/sdlayer.cpp
|
||||
build/src/smalltextfont.cpp
|
||||
|
@ -723,6 +722,7 @@ set (PCH_SOURCES
|
|||
common/compositesavegame.cpp
|
||||
common/savegamehelp.cpp
|
||||
common/quotes.cpp
|
||||
common/screenshot.cpp
|
||||
|
||||
common/2d/v_2ddrawer.cpp
|
||||
common/2d/v_draw.cpp
|
||||
|
|
|
@ -149,9 +149,6 @@ void mouseGrabInput(bool grab);
|
|||
void mouseLockToWindow(bool a);
|
||||
void mouseMoveToCenter(void);
|
||||
|
||||
void joyReadButtons(int32_t *pResult);
|
||||
void joySetDeadZone(int32_t axis, uint16_t dead, uint16_t satur);
|
||||
void joyGetDeadZone(int32_t axis, uint16_t *dead, uint16_t *satur);
|
||||
extern int32_t inputchecked;
|
||||
|
||||
void getScreen(uint8_t* imgBuf);
|
||||
|
|
|
@ -35,8 +35,6 @@ bool g_mouseLockedToWindow = 1;
|
|||
|
||||
controllerinput_t joystick;
|
||||
|
||||
void joySetCallback(void (*callback)(int32_t, int32_t)) { joystick.pCallback = callback; }
|
||||
void joyReadButtons(int32_t *pResult) { *pResult = appactive ? joystick.bits : 0; }
|
||||
|
||||
// Calculate ylookup[] and call setvlinebpl()
|
||||
void calc_ylookup(int32_t bpl, int32_t lastyidx)
|
||||
|
|
|
@ -1,166 +0,0 @@
|
|||
#include "compat.h"
|
||||
#include "build.h"
|
||||
#include "baselayer.h"
|
||||
#include "version.h"
|
||||
#include "m_png.h"
|
||||
#include "i_specialpaths.h"
|
||||
#include "m_argv.h"
|
||||
#include "cmdlib.h"
|
||||
#include "gamecontrol.h"
|
||||
#include "printf.h"
|
||||
#include "c_dispatch.h"
|
||||
|
||||
#include "../../glbackend/glbackend.h"
|
||||
|
||||
EXTERN_CVAR(Float, png_gamma)
|
||||
//
|
||||
// screencapture
|
||||
//
|
||||
|
||||
FileWriter *OutputFileCounter::opennextfile(char *fn, char *zeros)
|
||||
{
|
||||
do // JBF 2004022: So we don't overwrite existing screenshots
|
||||
{
|
||||
if (count > 9999) return nullptr;
|
||||
|
||||
zeros[0] = ((count/1000)%10)+'0';
|
||||
zeros[1] = ((count/100)%10)+'0';
|
||||
zeros[2] = ((count/10)%10)+'0';
|
||||
zeros[3] = (count%10)+'0';
|
||||
if (!FileExists(fn)) break;
|
||||
count++;
|
||||
} while (1);
|
||||
|
||||
return FileWriter::Open(fn);
|
||||
}
|
||||
|
||||
FileWriter *OutputFileCounter::opennextfile_withext(char *fn, const char *ext)
|
||||
{
|
||||
char *dot = strrchr(fn, '.');
|
||||
strcpy(dot+1, ext);
|
||||
return opennextfile(fn, dot-4);
|
||||
}
|
||||
|
||||
static OutputFileCounter capturecounter;
|
||||
|
||||
# ifdef USE_OPENGL
|
||||
# define HICOLOR (videoGetRenderMode() >= REND_POLYMOST && in3dmode())
|
||||
# else
|
||||
# define HICOLOR 0
|
||||
# endif
|
||||
|
||||
void getScreen(uint8_t* imgBuf)
|
||||
{
|
||||
GLInterface.ReadPixels(xdim, ydim, imgBuf);
|
||||
}
|
||||
|
||||
|
||||
CVAR(String, screenshotname, "", CVAR_ARCHIVE) // not GLOBALCONFIG - allow setting this per game.
|
||||
CVAR(String, screenshot_dir, "", CVAR_ARCHIVE) // same here.
|
||||
|
||||
//
|
||||
// WritePNGfile
|
||||
//
|
||||
void WritePNGfile(FileWriter* file, const uint8_t* buffer, const PalEntry* palette,
|
||||
ESSType color_type, int width, int height, int pitch, float gamma)
|
||||
{
|
||||
FStringf software("Demolition %s", GetVersionString());
|
||||
if (!M_CreatePNG(file, buffer, palette, color_type, width, height, pitch, gamma) ||
|
||||
!M_AppendPNGText(file, "Software", software) ||
|
||||
!M_FinishPNG(file))
|
||||
{
|
||||
Printf("Failed writing screenshot\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int videoCaptureScreen()
|
||||
{
|
||||
PalEntry Palette[256];
|
||||
|
||||
size_t dirlen;
|
||||
FString autoname = Args->CheckValue("-shotdir");
|
||||
if (autoname.IsEmpty())
|
||||
{
|
||||
autoname = screenshot_dir;
|
||||
}
|
||||
dirlen = autoname.Len();
|
||||
if (dirlen == 0)
|
||||
{
|
||||
autoname = M_GetScreenshotsPath();
|
||||
dirlen = autoname.Len();
|
||||
}
|
||||
if (dirlen > 0)
|
||||
{
|
||||
if (autoname[dirlen - 1] != '/' && autoname[dirlen - 1] != '\\')
|
||||
{
|
||||
autoname += '/';
|
||||
}
|
||||
}
|
||||
autoname = NicePath(autoname);
|
||||
CreatePath(autoname);
|
||||
|
||||
if (**screenshotname) autoname << screenshotname;
|
||||
else autoname << currentGame;
|
||||
autoname << "_0000";
|
||||
char* fn = autoname.LockBuffer();
|
||||
FileWriter *fil = capturecounter.opennextfile_withext(fn, "png");
|
||||
autoname.UnlockBuffer();
|
||||
|
||||
if (fil == nullptr)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
uint8_t * const imgBuf = (uint8_t *) Xmalloc(xdim * ydim * (HICOLOR ? 3 : 1));
|
||||
|
||||
videoBeginDrawing(); //{{{
|
||||
|
||||
if (HICOLOR)
|
||||
{
|
||||
getScreen(imgBuf);
|
||||
int const bytesPerLine = xdim * 3;
|
||||
|
||||
// flip rows
|
||||
uint8_t* rowBuf = (uint8_t *) Xmalloc(bytesPerLine);
|
||||
|
||||
for (int i = 0, numRows = ydim >> 1; i < numRows; ++i)
|
||||
{
|
||||
memcpy(rowBuf, imgBuf + i * bytesPerLine, bytesPerLine);
|
||||
memcpy(imgBuf + i * bytesPerLine, imgBuf + (ydim - i - 1) * bytesPerLine, bytesPerLine);
|
||||
memcpy(imgBuf + (ydim - i - 1) * bytesPerLine, rowBuf, bytesPerLine);
|
||||
}
|
||||
|
||||
Xfree(rowBuf);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (bssize_t i = 0; i < 256; ++i)
|
||||
{
|
||||
Palette[i].r = curpalettefaded[i].r;
|
||||
Palette[i].g = curpalettefaded[i].g;
|
||||
Palette[i].b = curpalettefaded[i].b;
|
||||
}
|
||||
|
||||
for (int i = 0; i < ydim; ++i)
|
||||
Bmemcpy(imgBuf + i * xdim, (uint8_t *)frameplace + ylookup[i], xdim);
|
||||
}
|
||||
|
||||
videoEndDrawing(); //}}}
|
||||
|
||||
WritePNGfile(fil, imgBuf, Palette, HICOLOR ? SS_RGB : SS_PAL, xdim, ydim, HICOLOR? xdim*3 : xdim, png_gamma);
|
||||
delete fil;
|
||||
Xfree(imgBuf);
|
||||
Printf("Saved screenshot to %s\n", fn);
|
||||
capturecounter.count++;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
CCMD(screenshot)
|
||||
{
|
||||
videoCaptureScreen();
|
||||
}
|
||||
|
||||
#undef HICOLOR
|
||||
|
|
@ -925,26 +925,6 @@ const char *joyGetName(int32_t what, int32_t num)
|
|||
}
|
||||
|
||||
|
||||
//
|
||||
// setjoydeadzone() -- sets the dead and saturation zones for the joystick
|
||||
//
|
||||
void joySetDeadZone(int32_t axis, uint16_t dead, uint16_t satur)
|
||||
{
|
||||
joydead[axis] = dead;
|
||||
joysatur[axis] = satur;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// getjoydeadzone() -- gets the dead and saturation zones for the joystick
|
||||
//
|
||||
void joyGetDeadZone(int32_t axis, uint16_t *dead, uint16_t *satur)
|
||||
{
|
||||
*dead = joydead[axis];
|
||||
*satur = joysatur[axis];
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
//
|
||||
// ---------------------------------------
|
||||
|
|
|
@ -610,31 +610,6 @@ int32_t handleevents_pollsdl(void)
|
|||
}
|
||||
break;
|
||||
|
||||
#if 0
|
||||
case SDL_JOYAXISMOTION:
|
||||
#if SDL_MAJOR_VERSION >= 2
|
||||
if (joystick.isGameController)
|
||||
break;
|
||||
fallthrough__;
|
||||
case SDL_CONTROLLERAXISMOTION:
|
||||
#endif
|
||||
if (appactive && ev.jaxis.axis < joystick.numAxes)
|
||||
{
|
||||
joystick.pAxis[ev.jaxis.axis] = ev.jaxis.value;
|
||||
int32_t const scaledValue = ev.jaxis.value * 10000 / 32767;
|
||||
if ((scaledValue < joydead[ev.jaxis.axis]) &&
|
||||
(scaledValue > -joydead[ev.jaxis.axis]))
|
||||
joystick.pAxis[ev.jaxis.axis] = 0;
|
||||
else if (scaledValue >= joysatur[ev.jaxis.axis])
|
||||
joystick.pAxis[ev.jaxis.axis] = 32767;
|
||||
else if (scaledValue <= -joysatur[ev.jaxis.axis])
|
||||
joystick.pAxis[ev.jaxis.axis] = -32767;
|
||||
else
|
||||
joystick.pAxis[ev.jaxis.axis] = joystick.pAxis[ev.jaxis.axis] * 10000 / joysatur[ev.jaxis.axis];
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
||||
case SDL_JOYHATMOTION:
|
||||
{
|
||||
int32_t hatvals[16] = {
|
||||
|
|
169
source/common/screenshot.cpp
Normal file
169
source/common/screenshot.cpp
Normal file
|
@ -0,0 +1,169 @@
|
|||
/*
|
||||
** screenshot.cpp
|
||||
**
|
||||
**---------------------------------------------------------------------------
|
||||
** Copyright 2019 Christoph Oelckers
|
||||
** All rights reserved.
|
||||
**
|
||||
** Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions
|
||||
** are met:
|
||||
**
|
||||
** 1. Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** 2. Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in the
|
||||
** documentation and/or other materials provided with the distribution.
|
||||
** 3. The name of the author may not be used to endorse or promote products
|
||||
** derived from this software without specific prior written permission.
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
**---------------------------------------------------------------------------
|
||||
**
|
||||
*/
|
||||
|
||||
#include "compat.h"
|
||||
#include "build.h"
|
||||
#include "baselayer.h"
|
||||
#include "version.h"
|
||||
#include "m_png.h"
|
||||
#include "i_specialpaths.h"
|
||||
#include "m_argv.h"
|
||||
#include "cmdlib.h"
|
||||
#include "gamecontrol.h"
|
||||
#include "printf.h"
|
||||
#include "c_dispatch.h"
|
||||
|
||||
#include "../../glbackend/glbackend.h"
|
||||
|
||||
EXTERN_CVAR(Float, png_gamma)
|
||||
//
|
||||
// screencapture
|
||||
//
|
||||
|
||||
static FileWriter *opennextfile(const char *fn)
|
||||
{
|
||||
static int count = 0;
|
||||
FString name;
|
||||
do
|
||||
{
|
||||
name.Format(fn, count++);
|
||||
} while (FileExists(name));
|
||||
return FileWriter::Open(name);
|
||||
}
|
||||
|
||||
static void getScreen(uint8_t* imgBuf)
|
||||
{
|
||||
GLInterface.ReadPixels(xdim, ydim, imgBuf);
|
||||
}
|
||||
|
||||
|
||||
CVAR(String, screenshotname, "", CVAR_ARCHIVE) // not GLOBALCONFIG - allow setting this per game.
|
||||
CVAR(String, screenshot_dir, "", CVAR_ARCHIVE) // same here.
|
||||
|
||||
//
|
||||
// WritePNGfile
|
||||
//
|
||||
static void WritePNGfile(FileWriter* file, const uint8_t* buffer, const PalEntry* palette,
|
||||
ESSType color_type, int width, int height, int pitch, float gamma)
|
||||
{
|
||||
FStringf software("Demolition %s", GetVersionString());
|
||||
if (!M_CreatePNG(file, buffer, palette, color_type, width, height, pitch, gamma) ||
|
||||
!M_AppendPNGText(file, "Software", software) ||
|
||||
!M_FinishPNG(file))
|
||||
{
|
||||
Printf("Failed writing screenshot\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int SaveScreenshot()
|
||||
{
|
||||
PalEntry Palette[256];
|
||||
|
||||
size_t dirlen;
|
||||
FString autoname = Args->CheckValue("-shotdir");
|
||||
if (autoname.IsEmpty())
|
||||
{
|
||||
autoname = screenshot_dir;
|
||||
}
|
||||
dirlen = autoname.Len();
|
||||
if (dirlen == 0)
|
||||
{
|
||||
autoname = M_GetScreenshotsPath();
|
||||
dirlen = autoname.Len();
|
||||
}
|
||||
if (dirlen > 0)
|
||||
{
|
||||
if (autoname[dirlen - 1] != '/' && autoname[dirlen - 1] != '\\')
|
||||
{
|
||||
autoname += '/';
|
||||
}
|
||||
}
|
||||
autoname = NicePath(autoname);
|
||||
CreatePath(autoname);
|
||||
|
||||
if (**screenshotname) autoname << screenshotname;
|
||||
else autoname << currentGame;
|
||||
autoname << "_%04d.png";
|
||||
FileWriter *fil = opennextfile(autoname);
|
||||
|
||||
if (fil == nullptr)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
auto truecolor = videoGetRenderMode() >= REND_POLYMOST;
|
||||
TArray<uint8_t> imgBuf(xdim * ydim * (truecolor ? 3 : 1), true);
|
||||
|
||||
videoBeginDrawing();
|
||||
|
||||
if (truecolor)
|
||||
{
|
||||
getScreen(imgBuf.Data());
|
||||
int bytesPerLine = xdim * 3;
|
||||
|
||||
TArray<uint8_t> rowBuf(bytesPerLine * 3, true);
|
||||
|
||||
for (int i = 0, numRows = ydim >> 1; i < numRows; ++i)
|
||||
{
|
||||
memcpy(rowBuf.Data(), imgBuf.Data() + i * bytesPerLine, bytesPerLine);
|
||||
memcpy(imgBuf.Data() + i * bytesPerLine, imgBuf.Data() + (ydim - i - 1) * bytesPerLine, bytesPerLine);
|
||||
memcpy(imgBuf.Data() + (ydim - i - 1) * bytesPerLine, rowBuf.Data(), bytesPerLine);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < 256; ++i)
|
||||
{
|
||||
Palette[i].r = curpalettefaded[i].r;
|
||||
Palette[i].g = curpalettefaded[i].g;
|
||||
Palette[i].b = curpalettefaded[i].b;
|
||||
}
|
||||
|
||||
for (int i = 0; i < ydim; ++i)
|
||||
memcpy(imgBuf.Data() + i * xdim, (uint8_t *)frameplace + ylookup[i], xdim);
|
||||
}
|
||||
|
||||
videoEndDrawing();
|
||||
|
||||
WritePNGfile(fil, imgBuf.Data(), Palette, truecolor ? SS_RGB : SS_PAL, xdim, ydim, truecolor? xdim*3 : xdim, png_gamma);
|
||||
delete fil;
|
||||
Printf("screenshot saved\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
CCMD(screenshot)
|
||||
{
|
||||
SaveScreenshot();
|
||||
}
|
||||
|
|
@ -37,8 +37,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||
|
||||
BEGIN_DUKE_NS
|
||||
|
||||
static OutputFileCounter savecounter;
|
||||
|
||||
// For storing pointers in files.
|
||||
// back_p==0: ptr -> "small int"
|
||||
// back_p==1: "small int" -> ptr
|
||||
|
|
|
@ -35,8 +35,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||
BEGIN_RR_NS
|
||||
|
||||
|
||||
static OutputFileCounter savecounter;
|
||||
|
||||
// For storing pointers in files.
|
||||
// back_p==0: ptr -> "small int"
|
||||
// back_p==1: "small int" -> ptr
|
||||
|
|
Loading…
Reference in a new issue