[Scummvm-git-logs] scummvm master -> 7946001da0255a484e377530e6f439739054e238
OMGPizzaGuy
noreply at scummvm.org
Mon Mar 25 01:43:41 UTC 2024
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:
7946001da0 ULTIMA8: Make ultima8 palette inherit from graphics palette
Commit: 7946001da0255a484e377530e6f439739054e238
https://github.com/scummvm/scummvm/commit/7946001da0255a484e377530e6f439739054e238
Author: Matthew Jimenez (matthew.jimenez at outlook.com)
Date: 2024-03-24T20:42:49-05:00
Commit Message:
ULTIMA8: Make ultima8 palette inherit from graphics palette
Changed paths:
engines/ultima/ultima8/graphics/cycle_process.cpp
engines/ultima/ultima8/graphics/fonts/font_manager.cpp
engines/ultima/ultima8/graphics/palette.cpp
engines/ultima/ultima8/graphics/palette.h
engines/ultima/ultima8/graphics/palette_manager.cpp
engines/ultima/ultima8/graphics/palette_manager.h
engines/ultima/ultima8/graphics/render_surface.h
engines/ultima/ultima8/graphics/shape.h
engines/ultima/ultima8/graphics/shape_archive.h
engines/ultima/ultima8/graphics/skf_player.h
engines/ultima/ultima8/gumps/movie_gump.cpp
engines/ultima/ultima8/gumps/shape_viewer_gump.cpp
engines/ultima/ultima8/kernel/mouse.cpp
engines/ultima/ultima8/ultima8.cpp
engines/ultima/ultima8/world/minimap.cpp
diff --git a/engines/ultima/ultima8/graphics/cycle_process.cpp b/engines/ultima/ultima8/graphics/cycle_process.cpp
index bc362632f41..05d041c74a2 100644
--- a/engines/ultima/ultima8/graphics/cycle_process.cpp
+++ b/engines/ultima/ultima8/graphics/cycle_process.cpp
@@ -93,19 +93,18 @@ void CycleProcess::run() {
PaletteManager *pm = PaletteManager::get_instance();
Palette *pal = pm->getPalette(PaletteManager::Pal_Game);
- uint8 *paldata = pal->_palette;
// Step 1: Rotate 7 colors (1~7)
- uint8 tmpcol[3];
+ byte r1, g1, b1;
// tmp copy of color 1
- copyColor(tmpcol, paldata + 3);
+ pal->get(1, r1, g1, b1);
for (int i = 1; i < 7; i++) {
- uint8 *dstptr = paldata + i * 3;
- const uint8 *srcptr = paldata + (i + 1) * 3;
- copyColor(dstptr, srcptr);
+ byte r, g, b;
+ pal->get(i + 1, r, g, b);
+ pal->set(i, r, g, b);
}
// move color 1 -> color 7
- copyColor(paldata + 3 * 7, tmpcol);
+ pal->set(7, r1, g1, b1);
Common::RandomSource &rs = Ultima8Engine::get_instance()->getRandomSource();
@@ -118,8 +117,7 @@ void CycleProcess::run() {
_cycleColData[i][1] += rs.getRandomNumber(9);
_cycleColData[i][2] += rs.getRandomNumber(9);
}
- uint8 *dstptr = paldata + (i + 8) * 3;
- copyColor(dstptr, _cycleColData[i]);
+ pal->set(i + 8, _cycleColData[i][0], _cycleColData[i][1], _cycleColData[i][2]);
}
// Update the cached palette.
diff --git a/engines/ultima/ultima8/graphics/fonts/font_manager.cpp b/engines/ultima/ultima8/graphics/fonts/font_manager.cpp
index 6963a82a850..2334824f9ac 100644
--- a/engines/ultima/ultima8/graphics/fonts/font_manager.cpp
+++ b/engines/ultima/ultima8/graphics/fonts/font_manager.cpp
@@ -174,9 +174,7 @@ bool FontManager::addJPOverride(unsigned int fontnum,
// the main text uses index 3
// indices 1,2 and 3 are in use for the bullets for conversation options
for (int i = 1; i < 4; ++i) {
- pal->_palette[3 * i + 0] = (rgb >> 16) & 0xFF;
- pal->_palette[3 * i + 1] = (rgb >> 8) & 0xFF;
- pal->_palette[3 * i + 2] = (rgb) & 0xFF;
+ pal->set(i, (rgb >> 16) & 0xFF, (rgb >> 8) & 0xFF, (rgb) & 0xFF);
}
palman->updatedPalette(fontpal);
diff --git a/engines/ultima/ultima8/graphics/palette.cpp b/engines/ultima/ultima8/graphics/palette.cpp
index 8629ac3cbd1..1e858f3c5fc 100644
--- a/engines/ultima/ultima8/graphics/palette.cpp
+++ b/engines/ultima/ultima8/graphics/palette.cpp
@@ -33,13 +33,12 @@ void Palette::load(Common::ReadStream &rs, Common::ReadStream &xformrs) {
void Palette::load(Common::ReadStream &rs) {
int i;
- rs.read(_palette, 768);
+ byte raw[768];
+ rs.read(raw, 768);
// convert from 0-63 to 0-255 _palette
for (i = 0; i < 256; i++) {
- _palette[i * 3] = (_palette[i * 3] * 255) / 63;
- _palette[i * 3 + 1] = (_palette[i * 3 + 1] * 255) / 63;
- _palette[i * 3 + 2] = (_palette[i * 3 + 2] * 255) / 63;
+ set(i, (raw[i * 3] * 255) / 63, (raw[i * 3 + 1] * 255) / 63, (raw[i * 3 + 2] * 255) / 63);
}
for (i = 0; i < 256; i++)
diff --git a/engines/ultima/ultima8/graphics/palette.h b/engines/ultima/ultima8/graphics/palette.h
index 7b9e0652da2..f7f4ea31736 100644
--- a/engines/ultima/ultima8/graphics/palette.h
+++ b/engines/ultima/ultima8/graphics/palette.h
@@ -22,12 +22,16 @@
#ifndef ULTIMA8_GRAPHICS_PALETTE_H
#define ULTIMA8_GRAPHICS_PALETTE_H
+#include "graphics/palette.h"
#include "ultima/ultima8/graphics/pal_transforms.h"
namespace Ultima {
namespace Ultima8 {
-struct Palette {
+class Palette: public Graphics::Palette {
+public:
+ Palette() : Graphics::Palette(256) {}
+
void load(Common::ReadStream &rs, Common::ReadStream &xformrs);
void load(Common::ReadStream &rs);
@@ -35,19 +39,16 @@ struct Palette {
// Not designed for speed - just useful for one-offs.
void transformRGB(int &r, int &g, int &b) const;
- // 256 rgb entries
- uint8 _palette[768];
-
- // Untransformed native format palette. Created by the RenderSurface
+ // Untransformed pixel format palette map
uint32 _native_untransformed[256];
- // Transformed native format palette. Created by the RenderSurface
+ // Transformed pixel format palette map
uint32 _native[256];
- // Untransformed XFORM ARGB palette
+ // Untransformed XFORM ARGB palette map
uint32 _xform_untransformed[256];
- // Transformed XFORM ARGB palette. Created by the RenderSurface
+ // Transformed XFORM ARGB palette map
uint32 _xform[256];
// Colour transformation matrix (for fades, hue shifts)
diff --git a/engines/ultima/ultima8/graphics/palette_manager.cpp b/engines/ultima/ultima8/graphics/palette_manager.cpp
index 440c6816441..ea024b339da 100644
--- a/engines/ultima/ultima8/graphics/palette_manager.cpp
+++ b/engines/ultima/ultima8/graphics/palette_manager.cpp
@@ -74,6 +74,29 @@ void PaletteManager::resetTransforms() {
}
}
+bool PaletteManager::loadTransforms(Common::ReadStream& rs) {
+ int16 matrix[12];
+ for (int i = 0; i < 12; i++)
+ matrix[i] = rs.readUint16LE();
+
+ PaletteManager::get_instance()->transformPalette(PaletteManager::Pal_Game, matrix);
+ Palette *pal = getPalette(PaletteManager::Pal_Game);
+ pal->_transform = static_cast<PalTransforms>(rs.readUint16LE());
+
+ if (pal->_transform >= Transform_Invalid) {
+ warning("Invalid palette transform %d. Corrupt savegame?", static_cast<int>(pal->_transform));
+ return false;
+ }
+ return true;
+}
+
+void PaletteManager::saveTransforms(Common::WriteStream& ws) {
+ Palette *pal = getPalette(PaletteManager::Pal_Game);
+ for (int i = 0; i < 12; i++)
+ ws.writeUint16LE(pal->_matrix[i]);
+ ws.writeUint16LE(pal->_transform);
+}
+
void PaletteManager::PixelFormatChanged(const Graphics::PixelFormat &format) {
_format = format;
@@ -337,33 +360,33 @@ void PaletteManager::createNativePalette(Palette *palette, int maxindex, const G
maxindex = 256;
for (int i = 0; i < maxindex; i++) {
int32 r, g, b;
+ byte sr, sg, sb;
// Normal palette
- palette->_native_untransformed[i] = format.RGBToColor(palette->_palette[i * 3 + 0],
- palette->_palette[i * 3 + 1],
- palette->_palette[i * 3 + 2]);
+ palette->get(i, sr, sg, sb);
+ palette->_native_untransformed[i] = format.RGBToColor(sr, sg, sb);
- r = palette->_matrix[0] * palette->_palette[i * 3 + 0] +
- palette->_matrix[1] * palette->_palette[i * 3 + 1] +
- palette->_matrix[2] * palette->_palette[i * 3 + 2] +
+ r = palette->_matrix[0] * sr +
+ palette->_matrix[1] * sg +
+ palette->_matrix[2] * sb +
palette->_matrix[3] * 255;
if (r < 0)
r = 0;
if (r > 0x7F800)
r = 0x7F800;
- g = palette->_matrix[4] * palette->_palette[i * 3 + 0] +
- palette->_matrix[5] * palette->_palette[i * 3 + 1] +
- palette->_matrix[6] * palette->_palette[i * 3 + 2] +
+ g = palette->_matrix[4] * sr +
+ palette->_matrix[5] * sg +
+ palette->_matrix[6] * sb +
palette->_matrix[7] * 255;
if (g < 0)
g = 0;
if (g > 0x7F800)
g = 0x7F800;
- b = palette->_matrix[8] * palette->_palette[i * 3 + 0] +
- palette->_matrix[9] * palette->_palette[i * 3 + 1] +
- palette->_matrix[10] * palette->_palette[i * 3 + 2] +
+ b = palette->_matrix[8] * sr +
+ palette->_matrix[9] * sg +
+ palette->_matrix[10] * sb +
palette->_matrix[11] * 255;
if (b < 0)
b = 0;
@@ -371,7 +394,6 @@ void PaletteManager::createNativePalette(Palette *palette, int maxindex, const G
b = 0x7F800;
// Transformed normal palette
- // FIXME - Wont work on non SDL SRS Implementations
palette->_native[i] = format.RGBToColor(static_cast<uint8>(r >> 11),
static_cast<uint8>(g >> 11),
static_cast<uint8>(b >> 11));
diff --git a/engines/ultima/ultima8/graphics/palette_manager.h b/engines/ultima/ultima8/graphics/palette_manager.h
index 997f386232b..48827d70bbd 100644
--- a/engines/ultima/ultima8/graphics/palette_manager.h
+++ b/engines/ultima/ultima8/graphics/palette_manager.h
@@ -29,7 +29,7 @@
namespace Ultima {
namespace Ultima8 {
-struct Palette;
+class Palette;
class PaletteManager {
public:
@@ -86,6 +86,8 @@ public:
//! Reset all the transforms back to default
void resetTransforms();
+ bool loadTransforms(Common::ReadStream &rs);
+ void saveTransforms(Common::WriteStream &ws);
void createNativePalette(Palette *palette, int maxindex, const Graphics::PixelFormat &format);
diff --git a/engines/ultima/ultima8/graphics/render_surface.h b/engines/ultima/ultima8/graphics/render_surface.h
index 95305d4c8ea..8bf108280fe 100644
--- a/engines/ultima/ultima8/graphics/render_surface.h
+++ b/engines/ultima/ultima8/graphics/render_surface.h
@@ -30,7 +30,6 @@ namespace Ultima8 {
class Shape;
-struct Palette;
struct Rect;
//
diff --git a/engines/ultima/ultima8/graphics/shape.h b/engines/ultima/ultima8/graphics/shape.h
index 5938c8f3bab..8c91d899d56 100644
--- a/engines/ultima/ultima8/graphics/shape.h
+++ b/engines/ultima/ultima8/graphics/shape.h
@@ -29,7 +29,7 @@ namespace Ultima8 {
class ShapeFrame;
class RawShapeFrame;
-struct Palette;
+class Palette;
struct Rect;
struct ConvertShapeFormat;
diff --git a/engines/ultima/ultima8/graphics/shape_archive.h b/engines/ultima/ultima8/graphics/shape_archive.h
index c9671345546..d75d69d5bd6 100644
--- a/engines/ultima/ultima8/graphics/shape_archive.h
+++ b/engines/ultima/ultima8/graphics/shape_archive.h
@@ -29,7 +29,7 @@ namespace Ultima8 {
class Shape;
struct ConvertShapeFormat;
-struct Palette;
+class Palette;
class ShapeArchive : public Archive {
public:
diff --git a/engines/ultima/ultima8/graphics/skf_player.h b/engines/ultima/ultima8/graphics/skf_player.h
index 14e32689ecc..f4fd6a551e3 100644
--- a/engines/ultima/ultima8/graphics/skf_player.h
+++ b/engines/ultima/ultima8/graphics/skf_player.h
@@ -32,7 +32,7 @@ namespace Ultima8 {
struct SKFEvent;
class RawArchive;
class RenderedText;
-struct Palette;
+class Palette;
class SKFPlayer : public MoviePlayer {
public:
diff --git a/engines/ultima/ultima8/gumps/movie_gump.cpp b/engines/ultima/ultima8/gumps/movie_gump.cpp
index c66ece1f425..6060b2c9e79 100644
--- a/engines/ultima/ultima8/gumps/movie_gump.cpp
+++ b/engines/ultima/ultima8/gumps/movie_gump.cpp
@@ -380,7 +380,7 @@ uint32 MovieGump::I_playMovieOverlay(const uint8 *args,
const Palette *pal = palman->getPalette(PaletteManager::Pal_Game);
assert(pal);
- CruMovieViewer(name, x, y, pal->_palette, nullptr, 52);
+ CruMovieViewer(name, x, y, pal->data(), nullptr, 52);
}
return 0;
diff --git a/engines/ultima/ultima8/gumps/shape_viewer_gump.cpp b/engines/ultima/ultima8/gumps/shape_viewer_gump.cpp
index e20d632fec2..fdc5f229868 100644
--- a/engines/ultima/ultima8/gumps/shape_viewer_gump.cpp
+++ b/engines/ultima/ultima8/gumps/shape_viewer_gump.cpp
@@ -188,9 +188,8 @@ void ShapeViewerGump::PaintThis(RenderSurface *surf, int32 lerp_factor, bool /*s
const ShapeFrame *frame = shape->getFrame(_curFrame);
if (frame && frame->hasPoint(relx, rely)) {
uint8 rawpx = frame->getPixel(relx, rely);
- uint8 px_r = shape->getPalette()->_palette[rawpx * 3];
- uint8 px_g = shape->getPalette()->_palette[rawpx * 3 + 1];
- uint8 px_b = shape->getPalette()->_palette[rawpx * 3 + 2];
+ uint8 px_r, px_g, px_b;
+ shape->getPalette()->get(rawpx, px_r, px_g, px_b);
Common::sprintf_s(buf2, "px: (%d, %d)(%d, %d): %d (%d, %d, %d)", relx, rely, frame->_xoff, frame->_yoff, rawpx, px_r, px_g, px_b);
rendtext = font->renderText(buf2, remaining);
diff --git a/engines/ultima/ultima8/kernel/mouse.cpp b/engines/ultima/ultima8/kernel/mouse.cpp
index 708da926363..15b0bcf2773 100644
--- a/engines/ultima/ultima8/kernel/mouse.cpp
+++ b/engines/ultima/ultima8/kernel/mouse.cpp
@@ -561,7 +561,7 @@ void Mouse::update() {
if (frame >= 0 && (uint)frame < mouse->frameCount()) {
const ShapeFrame *f = mouse->getFrame(frame);
CursorMan.replaceCursor(f->getSurface(), f->_xoff, f->_yoff, f->_keycolor);
- CursorMan.replaceCursorPalette(mouse->getPalette()->_palette, 0, 256);
+ CursorMan.replaceCursorPalette(mouse->getPalette()->data(), 0, 256);
CursorMan.showMouse(true);
} else {
CursorMan.showMouse(false);
diff --git a/engines/ultima/ultima8/ultima8.cpp b/engines/ultima/ultima8/ultima8.cpp
index ecc9d228b4c..624709a9d6b 100644
--- a/engines/ultima/ultima8/ultima8.cpp
+++ b/engines/ultima/ultima8/ultima8.cpp
@@ -33,7 +33,6 @@
#include "ultima/ultima8/games/start_u8_process.h"
#include "ultima/ultima8/games/start_crusader_process.h"
#include "ultima/ultima8/graphics/fonts/font_manager.h"
-#include "ultima/ultima8/graphics/palette.h"
#include "ultima/ultima8/graphics/render_surface.h"
#include "ultima/ultima8/games/game_data.h"
#include "ultima/ultima8/world/world.h"
@@ -1432,9 +1431,7 @@ void Ultima8Engine::save(Common::WriteStream *ws) {
ws->writeUint32LE(static_cast<uint32>(absoluteTime));
ws->writeUint16LE(_avatarMoverProcess->getPid());
- Palette *pal = PaletteManager::get_instance()->getPalette(PaletteManager::Pal_Game);
- for (int i = 0; i < 12; i++) ws->writeUint16LE(pal->_matrix[i]);
- ws->writeUint16LE(pal->_transform);
+ PaletteManager::get_instance()->saveTransforms(*ws);
ws->writeUint16LE(static_cast<uint16>(_inversion));
@@ -1461,13 +1458,8 @@ bool Ultima8Engine::load(Common::ReadStream *rs, uint32 version) {
uint16 amppid = rs->readUint16LE();
_avatarMoverProcess = dynamic_cast<AvatarMoverProcess *>(Kernel::get_instance()->getProcess(amppid));
- int16 matrix[12];
- for (int i = 0; i < 12; i++)
- matrix[i] = rs->readUint16LE();
-
- PaletteManager::get_instance()->transformPalette(PaletteManager::Pal_Game, matrix);
- Palette *pal = PaletteManager::get_instance()->getPalette(PaletteManager::Pal_Game);
- pal->_transform = static_cast<PalTransforms>(rs->readUint16LE());
+ if (!PaletteManager::get_instance()->loadTransforms(*rs))
+ return false;
_inversion = rs->readUint16LE();
@@ -1480,10 +1472,6 @@ bool Ultima8Engine::load(Common::ReadStream *rs, uint32 version) {
warning("No AvatarMoverProcess. Corrupt savegame?");
return false;
}
- if (pal->_transform >= Transform_Invalid) {
- warning("Invalid palette transform %d. Corrupt savegame?", static_cast<int>(pal->_transform));
- return false;
- }
if (_saveCount > 1024*1024) {
warning("Improbable savecount %d. Corrupt savegame?", _saveCount);
return false;
diff --git a/engines/ultima/ultima8/world/minimap.cpp b/engines/ultima/ultima8/world/minimap.cpp
index 0a55072e387..c3d1c9ab82d 100644
--- a/engines/ultima/ultima8/world/minimap.cpp
+++ b/engines/ultima/ultima8/world/minimap.cpp
@@ -154,9 +154,8 @@ uint32 MiniMap::sampleAtPoint(const Item &item, int x, int y) {
continue;
uint8 p = frame->getPixel(i - sx, j - sy);
- byte r2 = pal->_palette[p * 3 + 0];
- byte g2 = pal->_palette[p * 3 + 1];
- byte b2 = pal->_palette[p * 3 + 2];
+ byte r2, g2, b2;
+ pal->get(p, r2, g2, b2);
r += RenderSurface::_gamma22toGamma10[r2];
g += RenderSurface::_gamma22toGamma10[g2];
b += RenderSurface::_gamma22toGamma10[b2];
More information about the Scummvm-git-logs
mailing list