[Scummvm-git-logs] scummvm master -> 71057ddefd368f4c7d2a23a297f085558f9aaeb4
mduggan
mgithub at guarana.org
Tue Jul 7 05:41:09 UTC 2020
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:
71057ddefd ULTIMA8: Add environmental palette cycling like crusader
Commit: 71057ddefd368f4c7d2a23a297f085558f9aaeb4
https://github.com/scummvm/scummvm/commit/71057ddefd368f4c7d2a23a297f085558f9aaeb4
Author: Matthew Duggan (mgithub at guarana.org)
Date: 2020-07-07T14:40:36+09:00
Commit Message:
ULTIMA8: Add environmental palette cycling like crusader
Changed paths:
A engines/ultima/ultima8/graphics/cycle_process.cpp
A engines/ultima/ultima8/graphics/cycle_process.h
engines/ultima/module.mk
engines/ultima/ultima8/graphics/base_soft_render_surface.cpp
engines/ultima/ultima8/graphics/base_soft_render_surface.h
engines/ultima/ultima8/graphics/fonts/font_manager.cpp
engines/ultima/ultima8/graphics/palette_manager.cpp
engines/ultima/ultima8/graphics/palette_manager.h
engines/ultima/ultima8/graphics/render_surface.h
engines/ultima/ultima8/ultima8.cpp
diff --git a/engines/ultima/module.mk b/engines/ultima/module.mk
index 2c3f017992..b112de5542 100644
--- a/engines/ultima/module.mk
+++ b/engines/ultima/module.mk
@@ -419,6 +419,7 @@ MODULE_OBJS := \
ultima8/graphics/anim_dat.o \
ultima8/graphics/avi_player.o \
ultima8/graphics/base_soft_render_surface.o \
+ ultima8/graphics/cycle_process.o \
ultima8/graphics/frame_id.o \
ultima8/graphics/fade_to_modal_process.o \
ultima8/graphics/gump_shape_archive.o \
diff --git a/engines/ultima/ultima8/graphics/base_soft_render_surface.cpp b/engines/ultima/ultima8/graphics/base_soft_render_surface.cpp
index 386e4b77d0..b3cd772686 100644
--- a/engines/ultima/ultima8/graphics/base_soft_render_surface.cpp
+++ b/engines/ultima/ultima8/graphics/base_soft_render_surface.cpp
@@ -335,8 +335,10 @@ Texture *BaseSoftRenderSurface::GetSurfaceAsTexture() {
//
// Desc: Create a palette of colours native to the surface
//
-void BaseSoftRenderSurface::CreateNativePalette(Palette *palette) {
- for (int i = 0; i < 256; i++) {
+void BaseSoftRenderSurface::CreateNativePalette(Palette *palette, int maxindex) {
+ if (maxindex == 0)
+ maxindex = 256;
+ for (int i = 0; i < maxindex; i++) {
int32 r, g, b;
// Normal palette
diff --git a/engines/ultima/ultima8/graphics/base_soft_render_surface.h b/engines/ultima/ultima8/graphics/base_soft_render_surface.h
index 6aba7db8b6..d29e7e91fb 100644
--- a/engines/ultima/ultima8/graphics/base_soft_render_surface.h
+++ b/engines/ultima/ultima8/graphics/base_soft_render_surface.h
@@ -164,7 +164,7 @@ public:
// Get The Surface Palette
// TODO: virtual void GetPalette(uint8 palette[768]);
- void CreateNativePalette(Palette *palette) override;
+ void CreateNativePalette(Palette *palette, int maxindex = 0) override;
Graphics::ManagedSurface *getRawSurface() const override {
return _surface;
diff --git a/engines/ultima/ultima8/graphics/cycle_process.cpp b/engines/ultima/ultima8/graphics/cycle_process.cpp
new file mode 100644
index 0000000000..04fd2e0cd1
--- /dev/null
+++ b/engines/ultima/ultima8/graphics/cycle_process.cpp
@@ -0,0 +1,142 @@
+/* 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 "ultima/ultima8/misc/pent_include.h"
+#include "ultima/ultima8/graphics/cycle_process.h"
+#include "ultima/ultima8/kernel/kernel.h"
+#include "ultima/ultima8/graphics/palette.h"
+
+namespace Ultima {
+namespace Ultima8 {
+
+CycleProcess *CycleProcess::_instance = nullptr;
+
+// Which color to cycle in each of the palette colors 8~14
+static const bool CYCLE_COL_FLAGS[7][3] = {
+ 1, 0, 0,
+ 0, 0, 1,
+ 1, 0, 0,
+ 0, 0, 1,
+ 1, 1, 0,
+ 1, 1, 1,
+ 0, 1, 0
+};
+
+static const uint8 CYCLE_INIT_COLS[7][3] = {0, 0, 0, 0, 0, 0, 124, 0, 0, 0, 0, 124, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+
+static const bool CYCLE_RANDOMIZE[7] = {
+ false, false, false, false, false, false, true
+};
+
+// p_dynamic_class stuff
+DEFINE_RUNTIME_CLASSTYPE_CODE(CycleProcess)
+
+static inline void copyColor(uint8 *dst, const uint8 *src) {
+ dst[0] = src[0];
+ dst[1] = src[1];
+ dst[2] = src[2];
+}
+
+CycleProcess::CycleProcess() : Process(), _running(1) {
+ _instance = this;
+ for (int i = 0; i < 7; i++) {
+ copyColor(_cycleColData[i], CYCLE_INIT_COLS[i]);
+ }
+}
+
+CycleProcess::~CycleProcess(void) {
+ if (_instance == this)
+ _instance = nullptr;
+}
+
+CycleProcess *CycleProcess::get_instance() {
+ return _instance;
+}
+
+static bool cycleColor(uint8 *col, const bool flags[3]) {
+ bool wrapped = false;
+
+ for (int i = 0; i < 3; i++) {
+ if (flags[i]) {
+ col[i] += 8;
+ }
+ if (col[i] > 252) {
+ col[i] = 0;
+ wrapped = true;
+ }
+ }
+ return wrapped;
+}
+
+void CycleProcess::run() {
+ if (!_running)
+ return;
+
+ 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];
+ // tmp copy of color 1
+ copyColor(tmpcol, paldata + 3);
+ for (int i = 1; i < 7; i++) {
+ uint8 *dstptr = paldata + i * 3;
+ const uint8 *srcptr = paldata + (i + 1) * 3;
+ copyColor(dstptr, srcptr);
+ }
+ // move color 1 -> color 7
+ copyColor(paldata + 3 * 7, tmpcol);
+
+ // Step 2: Cycle 7 other colors 8~14 by increasing their value
+ // until they hit max, then reset.
+ for (int i = 0; i < 7; i++) {
+ bool wrapped = cycleColor(_cycleColData[i], CYCLE_COL_FLAGS[i]);
+ if (CYCLE_RANDOMIZE[i] && wrapped) {
+ _cycleColData[i][0] += (getRandom() % 10);
+ _cycleColData[i][1] += (getRandom() % 10);
+ _cycleColData[i][2] += (getRandom() % 10);
+ }
+ uint8 *dstptr = paldata + (i + 8) * 3;
+ copyColor(dstptr, _cycleColData[i]);
+ }
+
+ // Update the cached palette.
+ pm->updatedPalette(PaletteManager::Pal_Game, 16);
+}
+
+void CycleProcess::saveData(Common::WriteStream *ws) {
+ Process::saveData(ws);
+
+ ws->writeByte(_running);
+}
+
+bool CycleProcess::loadData(Common::ReadStream *rs, uint32 version) {
+ if (!Process::loadData(rs, version)) return false;
+
+ _running = rs->readByte();
+ _instance = this; //static
+ return true;
+}
+
+} // End of namespace Ultima8
+} // End of namespace Ultima
diff --git a/engines/ultima/ultima8/graphics/cycle_process.h b/engines/ultima/ultima8/graphics/cycle_process.h
new file mode 100644
index 0000000000..64e7a05137
--- /dev/null
+++ b/engines/ultima/ultima8/graphics/cycle_process.h
@@ -0,0 +1,56 @@
+/* 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 ULTIMA8_GRAPHICS_CYCLEPROCESS_H
+#define ULTIMA8_GRAPHICS_CYCLEPROCESS_H
+
+#include "ultima/ultima8/kernel/process.h"
+#include "ultima/ultima8/graphics/palette_manager.h"
+#include "ultima/ultima8/usecode/intrinsics.h"
+#include "ultima/ultima8/misc/p_dynamic_cast.h"
+
+namespace Ultima {
+namespace Ultima8 {
+
+class CycleProcess : public Process {
+ uint8 _running;
+ uint8 _cycleColData[7][3];
+public:
+ static CycleProcess *_instance;
+
+ // p_dynamic_class stuff
+ ENABLE_RUNTIME_CLASSTYPE()
+ CycleProcess();
+ ~CycleProcess(void) override;
+
+ void run() override;
+
+ static CycleProcess *get_instance();
+
+ bool loadData(Common::ReadStream *rs, uint32 version);
+ void saveData(Common::WriteStream *ws) override;
+};
+
+} // End of namespace Ultima8
+} // End of namespace Ultima
+
+#endif
diff --git a/engines/ultima/ultima8/graphics/fonts/font_manager.cpp b/engines/ultima/ultima8/graphics/fonts/font_manager.cpp
index d18c15fca0..489fad0d1d 100644
--- a/engines/ultima/ultima8/graphics/fonts/font_manager.cpp
+++ b/engines/ultima/ultima8/graphics/fonts/font_manager.cpp
@@ -183,7 +183,7 @@ bool FontManager::addJPOverride(unsigned int fontnum,
pal->_palette[3 * i + 1] = (rgb >> 8) & 0xFF;
pal->_palette[3 * i + 2] = (rgb) & 0xFF;
}
- palman->updatedFont(fontpal);
+ palman->updatedPalette(fontpal);
#ifdef DEBUG
pout << "Added JP override for font " << fontnum << Std::endl;
diff --git a/engines/ultima/ultima8/graphics/palette_manager.cpp b/engines/ultima/ultima8/graphics/palette_manager.cpp
index 6908b68944..d73f66c6c8 100644
--- a/engines/ultima/ultima8/graphics/palette_manager.cpp
+++ b/engines/ultima/ultima8/graphics/palette_manager.cpp
@@ -54,10 +54,10 @@ void PaletteManager::reset() {
_palettes.clear();
}
-void PaletteManager::updatedFont(PalIndex index) {
+void PaletteManager::updatedPalette(PalIndex index, int maxindex) {
Palette *pal = getPalette(index);
if (pal)
- _renderSurface->CreateNativePalette(pal); // convert to native format
+ _renderSurface->CreateNativePalette(pal, maxindex);
}
// Reset all the transforms back to default
diff --git a/engines/ultima/ultima8/graphics/palette_manager.h b/engines/ultima/ultima8/graphics/palette_manager.h
index 1a060ca57c..012f5d1bd9 100644
--- a/engines/ultima/ultima8/graphics/palette_manager.h
+++ b/engines/ultima/ultima8/graphics/palette_manager.h
@@ -57,8 +57,9 @@ public:
void duplicate(PalIndex src, PalIndex dest);
- //! Re-convert a palette to native format after modifying it
- void updatedFont(PalIndex index);
+ //! Re-convert a palette to native format after modifying it. If maxindex is set,
+ //! only recalculate color indexes up to that value.
+ void updatedPalette(PalIndex index, int maxindex = 0);
//! Apply a transform matrix to a palette (-4.11 fixed)
void transformPalette(PalIndex index, int16 matrix[12]);
diff --git a/engines/ultima/ultima8/graphics/render_surface.h b/engines/ultima/ultima8/graphics/render_surface.h
index d28daeb9f4..badd99bb4e 100644
--- a/engines/ultima/ultima8/graphics/render_surface.h
+++ b/engines/ultima/ultima8/graphics/render_surface.h
@@ -147,7 +147,7 @@ public:
// Get The Surface Palette
// TODO: virtual void GetPalette(uint8 palette[768]) = 0;
- virtual void CreateNativePalette(Palette *palette) = 0;
+ virtual void CreateNativePalette(Palette *palette, int maxindex = 0) = 0;
//
diff --git a/engines/ultima/ultima8/ultima8.cpp b/engines/ultima/ultima8/ultima8.cpp
index 5f85340efa..acd40725fa 100644
--- a/engines/ultima/ultima8/ultima8.cpp
+++ b/engines/ultima/ultima8/ultima8.cpp
@@ -80,6 +80,7 @@
#include "ultima/ultima8/world/egg.h"
#include "ultima/ultima8/world/current_map.h"
#include "ultima/ultima8/graphics/inverter_process.h"
+#include "ultima/ultima8/graphics/cycle_process.h"
#include "ultima/ultima8/world/actors/heal_process.h"
#include "ultima/ultima8/world/actors/scheduler_process.h"
#include "ultima/ultima8/world/egg_hatcher_process.h" // for a hack
@@ -284,6 +285,8 @@ void Ultima8Engine::startup() {
ProcessLoader<CruHealerProcess>::load);
_kernel->addProcessLoader("BatteryChargerProcess",
ProcessLoader<BatteryChargerProcess>::load);
+ _kernel->addProcessLoader("CycleProcess",
+ ProcessLoader<CycleProcess>::load);
_objectManager = new ObjectManager();
_mouse = new Mouse();
@@ -1113,6 +1116,7 @@ bool Ultima8Engine::newGame(int saveSlot) {
if (GAME_IS_CRUSADER) {
_kernel->addProcess(new TargetReticleProcess());
+ _kernel->addProcess(new CycleProcess());
}
if (saveSlot == -1)
More information about the Scummvm-git-logs
mailing list