[Scummvm-git-logs] scummvm master -> 3be7db2a9d745eb9aa9316ffe725dad355ad6752

a-yyg 76591232+a-yyg at users.noreply.github.com
Wed Jul 21 07:23:54 UTC 2021


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
3be7db2a9d SAGA2: Save thumbnail before opening menu


Commit: 3be7db2a9d745eb9aa9316ffe725dad355ad6752
    https://github.com/scummvm/scummvm/commit/3be7db2a9d745eb9aa9316ffe725dad355ad6752
Author: a/ (yuri.kgpps at gmail.com)
Date: 2021-07-21T16:23:06+09:00

Commit Message:
SAGA2: Save thumbnail before opening menu

Changed paths:
  A engines/saga2/gfx.cpp
  A engines/saga2/gfx.h
    engines/saga2/module.mk
    engines/saga2/saga2.cpp
    engines/saga2/saga2.h
    engines/saga2/uidialog.cpp


diff --git a/engines/saga2/gfx.cpp b/engines/saga2/gfx.cpp
new file mode 100644
index 0000000000..dfc870dcd8
--- /dev/null
+++ b/engines/saga2/gfx.cpp
@@ -0,0 +1,92 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "graphics/surface.h"
+
+#include "saga2/saga2.h"
+
+#include "saga2/gfx.h"
+
+namespace Saga2 {
+
+Renderer::Renderer(Saga2Engine *vm) : _vm(vm) {
+	for (int i = 0; i < kMaxBackBufferSources; ++i) {
+		_savedBackBuffers[i] = nullptr;
+	}
+}
+
+Renderer::~Renderer() {
+	for (int i = 0; i < kMaxBackBufferSources; i++) {
+		if (_savedBackBuffers[i]) {
+			delete[] _savedBackBuffers[i];
+			_savedBackBuffers[i] = nullptr;
+		}
+	}
+}
+
+void Renderer::saveBackBuffer(BackBufferSource source) {
+	if (source >= 0 && source < kMaxBackBufferSources) {
+		if (_savedBackBuffers[source])
+			removeSavedBackBuffer(source);
+
+		Graphics::Surface *surf = g_system->lockScreen();
+		int size = surf->w * surf->h;
+		
+		_savedBackBuffers[source] = new byte[size];
+		memcpy(_savedBackBuffers[source], surf->getPixels(), size);
+
+		g_system->unlockScreen();
+	}
+}
+
+void Renderer::popSavedBackBuffer(BackBufferSource source) {
+	restoreSavedBackBuffer(source);
+	removeSavedBackBuffer(source);
+}
+
+void Renderer::restoreSavedBackBuffer(BackBufferSource source) {
+	if (source >= 0 && source < kMaxBackBufferSources) {
+		if (_savedBackBuffers[source]) {
+			Graphics::Surface *surf = g_system->lockScreen();
+			int size = surf->w * surf->h;
+
+			memcpy(surf->getBasePtr(0, 0), _savedBackBuffers[source], size);
+
+			g_system->unlockScreen();
+		}
+	}
+}
+
+void Renderer::removeSavedBackBuffer(BackBufferSource source) {
+	if (source >= 0 && source < kMaxBackBufferSources) {
+		if (_savedBackBuffers[source])
+			delete[] _savedBackBuffers[source];
+
+		_savedBackBuffers[source] = nullptr;
+	}
+}
+
+bool Renderer::hasSavedBackBuffer(BackBufferSource source) {
+	return (source >= 0 && source < kMaxBackBufferSources) && _savedBackBuffers[source];
+}
+
+} // end of namespace Saga2
diff --git a/engines/saga2/gfx.h b/engines/saga2/gfx.h
new file mode 100644
index 0000000000..59c2d14c60
--- /dev/null
+++ b/engines/saga2/gfx.h
@@ -0,0 +1,59 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef SAGA2_GFX_H
+#define SAGA2_GFX_H
+
+#include "common/noncopyable.h"
+
+namespace Saga2 {
+
+enum BackBufferSource {
+	kBeforeOpeningMenu,
+	kBeforeTakingThumbnail,
+	kMaxBackBufferSources
+};
+
+class Renderer : public Common::NonCopyable {
+private:
+	Saga2Engine *_vm;
+
+	byte *_savedBackBuffers[kMaxBackBufferSources];
+	
+public:
+	Renderer(Saga2Engine *vm);
+	~Renderer();
+
+	void saveBackBuffer(BackBufferSource source);
+
+	void popSavedBackBuffer(BackBufferSource source);
+
+	void restoreSavedBackBuffer(BackBufferSource source);
+
+	void removeSavedBackBuffer(BackBufferSource source);
+
+	bool hasSavedBackBuffer(BackBufferSource source);
+};
+
+} // end of namespace Saga2
+
+#endif
diff --git a/engines/saga2/module.mk b/engines/saga2/module.mk
index 12a04c75d7..787fcb90a8 100644
--- a/engines/saga2/module.mk
+++ b/engines/saga2/module.mk
@@ -20,6 +20,7 @@ MODULE_OBJS := \
 	floating.o \
 	gamemode.o \
 	gdraw.o \
+	gfx.o \
 	gpointer.o \
 	grabinfo.o \
 	grequest.o \
diff --git a/engines/saga2/saga2.cpp b/engines/saga2/saga2.cpp
index 46220aa904..d37e35c605 100644
--- a/engines/saga2/saga2.cpp
+++ b/engines/saga2/saga2.cpp
@@ -62,6 +62,7 @@ Saga2Engine::Saga2Engine(OSystem *syst)
 	g_vm = this;
 
 	_console = nullptr;
+	_renderer = nullptr;
 	_bandList = nullptr;
 	_mouseInfo = nullptr;
 	_smkDecoder = nullptr;
@@ -110,6 +111,8 @@ Saga2Engine::~Saga2Engine() {
 
 	// Dispose your resources here
 	delete _rnd;
+	delete _renderer;
+
 	delete _imageCache;
 	delete _mTaskList;
 	delete _bandList;
@@ -132,6 +135,8 @@ Common::Error Saga2Engine::run() {
 	_console = new Console(this);
 	setDebugger(_console);
 
+	_renderer = new Renderer(this);
+
 	readConfig();
 
 	loadExeResources();
@@ -177,7 +182,14 @@ Common::Error Saga2Engine::saveGameState(int slot, const Common::String &desc, b
 	CHUNK_BEGIN;
 	uint32 pos = outS->pos() + 4;
 
+	_renderer->saveBackBuffer(kBeforeTakingThumbnail);
+
+	if (_renderer->hasSavedBackBuffer(kBeforeOpeningMenu))
+		_renderer->restoreSavedBackBuffer(kBeforeOpeningMenu);
+
 	getMetaEngine()->appendExtendedSaveToStream(out, g_vm->getTotalPlayTime() / 1000, desc, false, pos);
+
+	_renderer->popSavedBackBuffer(kBeforeTakingThumbnail);
 	CHUNK_END;
 
 	outS->finalize();
diff --git a/engines/saga2/saga2.h b/engines/saga2/saga2.h
index fbb40c3fd9..f0d99aefce 100644
--- a/engines/saga2/saga2.h
+++ b/engines/saga2/saga2.h
@@ -31,6 +31,7 @@
 #include "engines/engine.h"
 
 #include "saga2/console.h"
+#include "saga2/gfx.h"
 #include "saga2/idtypes.h"
 #include "saga2/weapons.h"
 #include "saga2/vdraw.h"
@@ -130,6 +131,7 @@ public:
 	// We need random numbers
 	Common::RandomSource *_rnd;
 	Console *_console;
+	Renderer *_renderer;
 
 	WeaponStuff _weaponRack[kMaxWeapons];
 	weaponID _loadedWeapons;
diff --git a/engines/saga2/uidialog.cpp b/engines/saga2/uidialog.cpp
index 49db38a4da..68bed67807 100644
--- a/engines/saga2/uidialog.cpp
+++ b/engines/saga2/uidialog.cpp
@@ -777,6 +777,9 @@ void enableUserControls(void);
 void updateAllUserControls(void);
 
 int16 OptionsDialog(bool disableSaveResume) {
+	// Save back buffer before opening the dialog
+	g_vm->_renderer->saveBackBuffer(kBeforeOpeningMenu);
+
 	// text for dialog
 	const char  *btnStrings[kNumOptionsBtns] = {
 		OPTN_DIALOG_BUTTON1,




More information about the Scummvm-git-logs mailing list