Added Screenshot feature (ALT+S).

This commit is contained in:
SpinDizzy 2020-09-19 07:54:26 +00:00
parent ca57659fcb
commit 981cdc33f5
3 changed files with 120 additions and 99 deletions

View file

@ -58,6 +58,7 @@ CInputs::CInputs(CInputSystem *system)
uiToggleFrLimit = AddSwitchInput("UIToggleFrameLimit", "Toggle Frame Limiting", Game::INPUT_UI, "KEY_ALT+KEY_T"); uiToggleFrLimit = AddSwitchInput("UIToggleFrameLimit", "Toggle Frame Limiting", Game::INPUT_UI, "KEY_ALT+KEY_T");
uiDumpInpState = AddSwitchInput("UIDumpInputState", "Dump Input State", Game::INPUT_UI, "KEY_ALT+KEY_U"); uiDumpInpState = AddSwitchInput("UIDumpInputState", "Dump Input State", Game::INPUT_UI, "KEY_ALT+KEY_U");
uiDumpTimings = AddSwitchInput("UIDumpTimings", "Dump Frame Timings", Game::INPUT_UI, "KEY_ALT+KEY_O"); uiDumpTimings = AddSwitchInput("UIDumpTimings", "Dump Frame Timings", Game::INPUT_UI, "KEY_ALT+KEY_O");
uiScreenshot = AddSwitchInput("UIScreenShot", "Screenshot", Game::INPUT_UI, "KEY_ALT+KEY_S");
#ifdef SUPERMODEL_DEBUGGER #ifdef SUPERMODEL_DEBUGGER
uiEnterDebugger = AddSwitchInput("UIEnterDebugger", "Enter Debugger", Game::INPUT_UI, "KEY_ALT+KEY_B"); uiEnterDebugger = AddSwitchInput("UIEnterDebugger", "Enter Debugger", Game::INPUT_UI, "KEY_ALT+KEY_B");
#endif #endif

View file

@ -105,6 +105,7 @@ public:
CSwitchInput *uiToggleFrLimit; CSwitchInput *uiToggleFrLimit;
CSwitchInput *uiDumpInpState; CSwitchInput *uiDumpInpState;
CSwitchInput *uiDumpTimings; CSwitchInput *uiDumpTimings;
CSwitchInput *uiScreenshot;
#ifdef SUPERMODEL_DEBUGGER #ifdef SUPERMODEL_DEBUGGER
CSwitchInput *uiEnterDebugger; CSwitchInput *uiEnterDebugger;
#endif #endif

View file

@ -71,6 +71,7 @@
#include "SDLIncludes.h" #include "SDLIncludes.h"
#include <iostream> #include <iostream>
#include "Util/BMPFile.h"
/****************************************************************************** /******************************************************************************
@ -413,6 +414,27 @@ static void DumpPPCRegisters(IBus *bus)
} }
#endif #endif
static void SaveFrameBuffer(const std::string& file)
{
std::shared_ptr<uint8_t> pixels(new uint8_t[totalXRes * totalYRes * 4], std::default_delete<uint8_t[]>());
glReadPixels(0, 0, totalXRes, totalYRes, GL_RGBA, GL_UNSIGNED_BYTE, pixels.get());
Util::WriteSurfaceToBMP<Util::RGBA8>(file, pixels.get(), totalXRes, totalYRes, true);
}
void Screenshot()
{
// Make a screenshot
char file[128];
string info = "Screenshot created: ";
time_t now = time(0);
tm* ltm = localtime(&now);
sprintf(file, "Screenshot %.4d-%.2d-%.2d (%.2d-%.2d-%.2d).bmp", 1900 + ltm->tm_year, 1 + ltm->tm_mon, ltm->tm_mday, ltm->tm_hour, ltm->tm_min, ltm->tm_sec);
info += file;
puts(info.c_str());
SaveFrameBuffer(file);
}
/****************************************************************************** /******************************************************************************
Render State Analysis Render State Analysis
@ -421,17 +443,9 @@ static void DumpPPCRegisters(IBus *bus)
#ifdef DEBUG #ifdef DEBUG
#include "Model3/Model3GraphicsState.h" #include "Model3/Model3GraphicsState.h"
#include "Util/BMPFile.h"
#include "OSD/SDL/PolyAnalysis.h" #include "OSD/SDL/PolyAnalysis.h"
#include <fstream> #include <fstream>
static void SaveFrameBuffer(const std::string &file)
{
std::shared_ptr<uint8_t> pixels(new uint8_t[totalXRes*totalYRes*4], std::default_delete<uint8_t[]>());
glReadPixels(0, 0, totalXRes, totalYRes, GL_RGBA, GL_UNSIGNED_BYTE, pixels.get());
Util::WriteSurfaceToBMP<Util::RGBA8>(file, pixels.get(), totalXRes, totalYRes, true);
}
static std::string s_gfxStatePath; static std::string s_gfxStatePath;
static std::string GetFileBaseName(const std::string &file) static std::string GetFileBaseName(const std::string &file)
@ -1175,6 +1189,11 @@ int Supermodel(const Game &game, ROMSet *rom_set, IEmulator *Model3, CInputs *In
s_runtime_config.Get("Throttle").SetValue(!s_runtime_config["Throttle"].ValueAs<bool>()); s_runtime_config.Get("Throttle").SetValue(!s_runtime_config["Throttle"].ValueAs<bool>());
printf("Frame limiting: %s\n", s_runtime_config["Throttle"].ValueAs<bool>() ? "On" : "Off"); printf("Frame limiting: %s\n", s_runtime_config["Throttle"].ValueAs<bool>() ? "On" : "Off");
} }
else if (Inputs->uiScreenshot->Pressed())
{
// Make a screenshot
Screenshot();
}
#ifdef SUPERMODEL_DEBUGGER #ifdef SUPERMODEL_DEBUGGER
else if (Debugger != NULL && Inputs->uiEnterDebugger->Pressed()) else if (Debugger != NULL && Inputs->uiEnterDebugger->Pressed())
{ {