QDENGINE: Initial code for saving thumbnails in ExtendedSaves

This commit is contained in:
Eugene Sandulenko 2024-07-25 18:42:14 +02:00
parent f17b503ad9
commit 309f050e4f
3 changed files with 38 additions and 2 deletions

View File

@ -19,9 +19,10 @@
*
*/
#define FORBIDDEN_SYMBOL_ALLOW_ALL
#include "qdengine/metaengine.h"
#include "qdengine/qdengine.h"
#include "qdengine/qdcore/qd_game_dispatcher.h"
const char *QDEngineMetaEngine::getName() const {
return "qdengine";
@ -43,6 +44,12 @@ bool QDEngineMetaEngine::hasFeature(MetaEngineFeature f) const {
(f == kSupportsLoadingDuringStartup);
}
void QDEngineMetaEngine::getSavegameThumbnail(Graphics::Surface &thumb) {
QDEngine::qdGameDispatcher *dp = QDEngine::qdGameDispatcher::get_dispatcher();
if (dp)
dp->game_screenshot(thumb);
}
#if PLUGIN_ENABLED_DYNAMIC(QDENGINE)
REGISTER_PLUGIN_DYNAMIC(QDENGINE, PLUGIN_TYPE_ENGINE, QDEngineMetaEngine);
#else

View File

@ -37,6 +37,8 @@ public:
* Used by e.g. the launcher to determine whether to enable the Load button.
*/
bool hasFeature(MetaEngineFeature f) const override;
virtual void getSavegameThumbnail(Graphics::Surface &thumb) override;
};
#endif // QDENGINE_METAENGINE_H

View File

@ -2912,11 +2912,38 @@ const char *qdGameDispatcher::get_save_name(int slot_id, SaveFileType file_type)
return file_name.c_str();
}
bool qdGameDispatcher::game_screenshot(Graphics::Surface &thumb) const {
int w = qdGameConfig::get_config().screen_sx();
int h = qdGameConfig::get_config().screen_sy();
thumb.create(w, h, Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0));
if (qdGameScene * sp = get_active_scene()) {
qdSprite sprite(w, h, GR_RGB565);
sp->redraw();
uint16 col;
for (int i = 0; i < h; i++) {
uint16 *dst = (uint16 *)thumb.getBasePtr(0, i);
for (int j = 0; j < w; j++) {
grDispatcher::instance()->GetPixel(j, i, col);
*dst = col;
dst++;
}
}
return true;
}
return false;
}
bool qdGameDispatcher::game_screenshot(const char *file_name, int sx, int sy) const {
if (qdGameScene * sp = get_active_scene()) {
qdSprite sprite(qdGameConfig::get_config().screen_sx(),
qdGameConfig::get_config().screen_sy(),
GR_RGB888);
GR_RGB565);
sp->redraw();