Initial commit

This commit is contained in:
2026-02-02 04:50:13 +01:00
commit 5b11698731
22592 changed files with 7677434 additions and 0 deletions

View File

@@ -0,0 +1,272 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
/*
* This code is based on the CRAB engine
*
* Copyright (c) Arvind Raja Yadav
*
* Licensed under MIT
*
*/
#include "common/file.h"
#include "graphics/managed_surface.h"
#include "graphics/screen.h"
#include "image/png.h"
#include "crab/crab.h"
#include "crab/filesystem.h"
#include "crab/image/Image.h"
using ImageDecoder = Image::PNGDecoder;
namespace Crab {
using namespace pyrodactyl::image;
//------------------------------------------------------------------------
// Purpose: Load a texture
//------------------------------------------------------------------------
bool Image::load(Graphics::ManagedSurface *surface) {
deleteImage();
_texture = new Graphics::ManagedSurface();
_texture->copyFrom(*surface);
_w = surface->w;
_h = surface->h;
return true;
}
bool Image::load(const Common::Path &path) {
// Get rid of preexisting texture
deleteImage();
// Load image at specified path
Common::File file;
ImageDecoder decoder;
if (fileOpen(path, &file) && decoder.loadStream(file)) {
_texture = new Graphics::ManagedSurface();
_texture->convertFrom(*decoder.getSurface(), g_engine->_format);
_w = _texture->w;
_h = _texture->h;
file.close();
debugC(kDebugFilePath, "Image::load() Image Texture(%s): w: %d h: %d", path.toString(Common::Path::kNativeSeparator).c_str(), _w, _h);
}
return _texture != nullptr;
}
bool Image::load(rapidxml::xml_node<char> *node, const char *name) {
if (node->first_attribute(name) != nullptr)
return load(node->first_attribute(name)->value());
return false;
}
//------------------------------------------------------------------------
// Purpose: Draw a texture to the screen without cropping
//------------------------------------------------------------------------
void Image::draw(const int &x, const int &y, Common::Rect *clip, const TextureFlipType &flip) {
Common::Rect srcRect;
if (clip != nullptr) {
srcRect = *clip;
} else {
srcRect = Common::Rect(x, y, _w + x, _h + y);
}
Common::Rect destRect(x, y, _w + x, _h + y);
if (clip != nullptr) {
destRect.right = clip->right;
destRect.bottom = clip->bottom;
}
// TODO: Do proper clipping
g_engine->_screen->blitFrom(*_texture, Common::Point(static_cast<int16>(x), static_cast<int16>(y)));
}
Graphics::Surface* Image::rotate(const Graphics::ManagedSurface &src, ImageRotateDegrees rotation) {
assert(!src.empty());
assert(src.w == src.h);
assert(src.format.bytesPerPixel == 4);
Graphics::Surface *dest = new Graphics::Surface();
dest->create(src.w, src.h, src.format);
const uint size = src.w;
const uint32 *s = (const uint32 *)src.getBasePtr(0, 0);
switch (rotation) {
case kImageRotateBy90:
for (uint y = 0; y < size; ++y) {
for (uint x = 0; x < size; ++x, ++s) {
*((uint32 *)dest->getBasePtr(size - y - 1, x)) = *s;
}
}
break;
case kImageRotateBy180: {
// 180 degrees
uint32 *d;
for (uint y = 0; y < size; ++y) {
const uint32 *e = (const uint32 *)src.getBasePtr(size - 1, y);
d = (uint32 *)dest->getBasePtr(size - 1, size - y - 1);
for (; s < e; ++s, --d) {
*d = *s;
}
}
break;
}
case kImageRotateBy270:
for (uint y = 0; y < size; ++y) {
for (uint x = 0; x < size; ++x, ++s) {
*((uint32 *)dest->getBasePtr(y, size - x - 1)) = *s;
}
}
break;
}
return dest;
}
void Image::draw(const int &x, const int &y, Rect *clip, const TextureFlipType &flip, Graphics::ManagedSurface *surf) {
if (surf == nullptr)
surf = g_engine->_screen;
Common::Rect srcRect(0, 0, _w, _h);
Common::Rect destRect(x, y, _w + x, _h + y);
if (clip) {
srcRect = Common::Rect(clip->x, clip->y, clip->x + clip->w, clip->y + clip->h);
destRect.right = static_cast<int16>(clip->w + x);
destRect.bottom = static_cast<int16>(clip->h + y);
}
Graphics::ManagedSurface s;
s.copyFrom(_texture->getSubArea(srcRect));
if (s.w < 1 || s.h < 1)
return;
Graphics::Surface *rotated_surf = nullptr;
switch(flip) {
case FLIP_NONE:
break;
case FLIP_X:
s.surfacePtr()->flipHorizontal(Common::Rect(s.w, s.h));
break;
case FLIP_Y:
s.surfacePtr()->flipVertical(Common::Rect(s.w, s.h));
break;
case FLIP_XY:
s.surfacePtr()->flipHorizontal(Common::Rect(s.w, s.h));
s.surfacePtr()->flipVertical(Common::Rect(s.w, s.h));
break;
case FLIP_D:
s.surfacePtr()->flipHorizontal(Common::Rect(s.w, s.h));
rotated_surf = rotate(s, kImageRotateBy270);
s.copyFrom(*rotated_surf);
delete rotated_surf;
break;
case FLIP_DX:
rotated_surf = rotate(s, kImageRotateBy90);
s.copyFrom(*rotated_surf);
delete rotated_surf;
break;
case FLIP_DY:
rotated_surf = rotate(s, kImageRotateBy270);
s.copyFrom(*rotated_surf);
delete rotated_surf;
break;
case FLIP_XYD:
s.surfacePtr()->flipVertical(Common::Rect(s.w, s.h));
rotated_surf = rotate(s, kImageRotateBy270);
s.copyFrom(*rotated_surf);
delete rotated_surf;
break;
default:
warning("Flipped texture: %d", flip);
}
surf->blitFrom(s, Common::Rect(s.w, s.h), destRect);
}
void Image::fastDraw(const int &x, const int &y, Rect *clip) {
Common::Rect destRect(x, y, _w + x, _h + y);
int in_y = 0, in_x = 0;
if (clip) {
destRect.setWidth(clip->w);
destRect.setHeight(clip->h);
in_x = clip->x;
in_y = clip->y;
}
const int he = destRect.height();
const int destW = destRect.width();
uint32 *out = (uint32*)g_engine->_screen->getBasePtr(destRect.left, destRect.top);
uint32 *in = (uint32*)_texture->getBasePtr(in_x, in_y);
const uint32 outPitch = g_engine->_screen->pitch / sizeof(uint32);
const uint32 inPitch = _texture->pitch / sizeof(uint32);
for (int y_ = 0; y_ < he; y_++) {
memcpy(out, in, destW * 4);
out += outPitch;
in += inPitch;
}
g_engine->_screen->addDirtyRect(destRect);
}
//------------------------------------------------------------------------
// Purpose: Delete texture data
//------------------------------------------------------------------------
void Image::deleteImage() {
if (_texture != nullptr && _w > 0 && _h > 0) {
_texture->free();
delete _texture;
_texture = nullptr;
_w = 0;
_h = 0;
}
}
} // End of namespace Crab

131
engines/crab/image/Image.h Normal file
View File

@@ -0,0 +1,131 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
/*
* This code is based on the CRAB engine
*
* Copyright (c) Arvind Raja Yadav
*
* Licensed under MIT
*
*/
#ifndef CRAB_IMAGE_H
#define CRAB_IMAGE_H
#include "crab/Rectangle.h"
#include "crab/rapidxml/rapidxml.hpp"
namespace Graphics {
class ManagedSurface;
struct Surface;
} // End of namespace Graphics
namespace Common {
struct Rect;
} // End of namespace Common
namespace Crab {
namespace pyrodactyl {
namespace image {
// Image data used in Asset Manager
class Image {
// The dimensions of the image
int _w, _h;
enum ImageRotateDegrees {
kImageRotateBy90,
kImageRotateBy180,
kImageRotateBy270
};
public:
Graphics::ManagedSurface *_texture;
Image() : _texture(nullptr), _w(0), _h(0) {}
~Image() {}
Graphics::Surface* rotate(const Graphics::ManagedSurface &src, ImageRotateDegrees rotation);
// Set color modulation
void color(const uint8 &r, const uint8 &g, const uint8 &b) {
#if 0
SDL_SetTextureColorMod(texture, r, g, b);
#endif
warning("Setting color modulation for texture: %d %d %d", r, g, b);
}
// Set blending
#if 0
void BlendMode(const SDL_BlendMode &mode) { SDL_SetTextureBlendMode(texture, mode); }
#endif
// Set alpha modulation
int alpha(const uint8 &alpha) {
#if 0
return SDL_SetTextureAlphaMod(texture, alpha);
#endif
debug(5, "Setting alpha modulation for texture: %d ", alpha);
return 0;
}
// Get alpha modulation
uint8 alpha() {
uint8 res = 255;
#if 0
SDL_GetTextureAlphaMod(texture, &res);
#endif
return res;
}
// Load the image
bool load(const Common::Path &path);
bool load(rapidxml::xml_node<char> *node, const char *name);
bool load(Graphics::ManagedSurface *surface);
// Draw the texture
void draw(const int &x, const int &y, Common::Rect *clip = nullptr, const TextureFlipType &flip = FLIP_NONE);
void draw(const int &x, const int &y, Rect *clip, const TextureFlipType &flip = FLIP_NONE, Graphics::ManagedSurface *surf = nullptr);
void fastDraw(const int &x, const int &y, Rect *clip = nullptr);
// Delete the texture
void deleteImage();
int w() {
return _w;
}
int h() {
return _h;
}
bool valid() {
return _texture != nullptr;
}
};
} // End of namespace image
} // End of namespace pyrodactyl
} // End of namespace Crab
#endif // CRAB_IMAGE_H

View File

@@ -0,0 +1,181 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
/*
* This code is based on the CRAB engine
*
* Copyright (c) Arvind Raja Yadav
*
* Licensed under MIT
*
*/
//=============================================================================
// Author: Arvind
// Purpose: Contains the image manager class - used to manage in-game images
//=============================================================================
#include "crab/crab.h"
#include "crab/GameParam.h"
#include "crab/ScreenSettings.h"
#include "crab/XMLDoc.h"
#include "crab/image/ImageManager.h"
#include "crab/input/cursor.h"
namespace Crab {
using namespace pyrodactyl::image;
//------------------------------------------------------------------------
// Purpose: Load assets here.
//------------------------------------------------------------------------
void ImageManager::loadMap(const Common::Path &filename, const MapID &mapid) {
for (auto &it : _map[mapid])
it._value.deleteImage();
_map[mapid].clear();
XMLDoc imageList(filename);
if (imageList.ready()) {
rapidxml::xml_node<char> *node = imageList.doc()->first_node("res");
for (auto n = node->first_node("image"); n != nullptr; n = n->next_sibling("image")) {
ImageKey key;
if (loadImgKey(key, "name", n)) {
// Load different images depending on image quality setting
// Check if there is a low quality image specified for the asset id
// if yes, load it - if no, just load the higher quality one
bool valid = false;
Common::Path path;
if (!g_engine->_screenSettings->_quality)
valid = loadPath(path, "path_low", n, false);
if (!valid)
valid = loadPath(path, "path", n, false);
if (valid)
_map[mapid][key].load(path);
else
error("ImageManager::loadMap : Unable to load image id %u from %s!", key, path.toString(Common::Path::kNativeSeparator).c_str());
}
}
if (nodeValid("mouse", node, false)) {
using namespace pyrodactyl::input;
g_engine->_mouse->quit();
g_engine->_mouse->load(node->first_node("mouse"));
}
}
}
bool ImageManager::init() {
// First, delete everything that exists
quit();
// Load common assets
loadMap(g_engine->_filePath->_common, MAP_COMMON);
// Load main menu assets
loadMap(g_engine->_filePath->_currentR, MAP_CURRENT);
_invalidImg = _map[MAP_COMMON][0];
return true;
}
//------------------------------------------------------------------------
// Purpose: Get texture for a particular id
//------------------------------------------------------------------------
void ImageManager::getTexture(const ImageKey &id, Image &data) {
if (_map[MAP_CURRENT].contains(id))
data = _map[MAP_CURRENT][id];
else if (_map[MAP_COMMON].contains(id))
data = _map[MAP_COMMON][id];
else
data = _invalidImg;
}
Image &ImageManager::getTexture(const ImageKey &id) {
if (_map[MAP_CURRENT].contains(id))
return _map[MAP_CURRENT][id];
else if (_map[MAP_COMMON].contains(id))
return _map[MAP_COMMON][id];
return _invalidImg;
}
bool ImageManager::validTexture(const ImageKey &id) {
if (id != 0 && (_map[MAP_CURRENT].contains(id) || _map[MAP_COMMON].contains(id)))
return true;
return false;
}
//------------------------------------------------------------------------
// Purpose: Draw
//------------------------------------------------------------------------
void ImageManager::draw(const int &x, const int &y, const ImageKey &id, Common::Rect *clip,
const TextureFlipType &flip) {
getTexture(id).draw(x, y, clip, flip);
}
//------------------------------------------------------------------------
// Purpose: Draw
//------------------------------------------------------------------------
void ImageManager::draw(const int &x, const int &y, const ImageKey &id, Rect *clip,
const TextureFlipType &flip) {
getTexture(id).draw(x, y, clip, flip);
}
//------------------------------------------------------------------------
// Purpose: Dim the screen by drawing a 128 alpha black rectangle over it
//------------------------------------------------------------------------
void ImageManager::dimScreen() {
warning("STUB: ImageManger::DimScreen()");
#if 0
SDL_SetRenderDrawBlendMode(gRenderer, SDL_BLENDMODE_BLEND);
SDL_SetRenderDrawColor(gRenderer, 0, 0, 0, 128);
SDL_RenderFillRect(gRenderer, NULL);
#endif
}
void ImageManager::blackScreen() {
warning("STUB: ImageManger::blackScreen()");
#if 0
SDL_SetRenderDrawBlendMode(gRenderer, SDL_BLENDMODE_BLEND);
SDL_SetRenderDrawColor(gRenderer, 0, 0, 0, 255);
SDL_RenderFillRect(gRenderer, NULL);
#endif
}
//------------------------------------------------------------------------
// Purpose: free resources
//------------------------------------------------------------------------
void ImageManager::quit() {
for (int i = 0; i < MAP_TOTAL; i++) {
for (auto &it : _map[i])
it._value.deleteImage();
_map[i].clear();
}
}
} // End of namespace Crab

View File

@@ -0,0 +1,116 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
/*
* This code is based on the CRAB engine
*
* Copyright (c) Arvind Raja Yadav
*
* Licensed under MIT
*
*/
//=============================================================================
// Author: Arvind
// Purpose: Contains the image manager class - used to manage in-game assets
//=============================================================================
#ifndef CRAB_IMAGEMANAGER_H
#define CRAB_IMAGEMANAGER_H
#include "crab/image/Image.h"
#include "crab/TMX/TMXTileSet.h"
#include "common/hashmap.h"
namespace Crab {
// We use this object as the key for all image assets
typedef uint ImageKey;
// Since we use uint as a key for images, our loadImgKey function is loadNum
#define loadImgKey loadNum
namespace pyrodactyl {
namespace image {
// We store images here
typedef Common::HashMap<ImageKey, Image> TextureMap;
// Two image maps are used in the game - current (changes with level) and common
enum MapID {
MAP_CURRENT,
MAP_COMMON,
MAP_TOTAL
};
class ImageManager {
// Assets are stored in images
// Common is stuff used everywhere - this is only loaded once
TextureMap _map[MAP_TOTAL];
// The default image for all invalid image names
Image _invalidImg;
public:
// The tile sets used in the level
TMX::TileSetGroup _tileset;
// This image is used to notify player about changes to quests and inventory
ImageKey _notify;
ImageManager() {
_notify = 0;
}
~ImageManager() {}
void quit();
bool init();
// image related stuff
// Load all images specified in an xml file in a map
void loadMap(const Common::Path &filename, const MapID &mapid = MAP_CURRENT);
void getTexture(const ImageKey &id, Image &data);
Image &getTexture(const ImageKey &id);
bool validTexture(const ImageKey &id);
void draw(const int &x, const int &y, const ImageKey &id,
Common::Rect *clip = nullptr, const TextureFlipType &flip = FLIP_NONE);
void draw(const int &x, const int &y, const ImageKey &id,
Rect *clip, const TextureFlipType &flip = FLIP_NONE);
void dimScreen();
void blackScreen();
// Draw the notification icon
void notifyDraw(const int &x, const int &y) {
auto *k = &getTexture(_notify);
draw(x - k->w() / 2, y - k->h() / 2, _notify);
}
};
} // End of namespace image
} // End of namespace pyrodactyl
} // End of namespace Crab
#endif // CRAB_IMAGEMANAGER_H