aboutsummaryrefslogtreecommitdiff
path: root/engines/mads/palette.cpp
diff options
context:
space:
mode:
authorPaul Gilbert2014-03-16 00:43:08 -0400
committerPaul Gilbert2014-03-16 00:43:08 -0400
commit5e3684b37a5dad7aaf76275f2a84f054e31d6d06 (patch)
treebf41cbe2f815057db7837f16c994ac4245746396 /engines/mads/palette.cpp
parentdfcef632eacc27b4e035e3796550dced425e836d (diff)
downloadscummvm-rg350-5e3684b37a5dad7aaf76275f2a84f054e31d6d06.tar.gz
scummvm-rg350-5e3684b37a5dad7aaf76275f2a84f054e31d6d06.tar.bz2
scummvm-rg350-5e3684b37a5dad7aaf76275f2a84f054e31d6d06.zip
MADS: Simplified code for PaletteUsage::prioritize
Diffstat (limited to 'engines/mads/palette.cpp')
-rw-r--r--engines/mads/palette.cpp77
1 files changed, 13 insertions, 64 deletions
diff --git a/engines/mads/palette.cpp b/engines/mads/palette.cpp
index ba63dd3145..94a3117a5c 100644
--- a/engines/mads/palette.cpp
+++ b/engines/mads/palette.cpp
@@ -49,7 +49,7 @@ void PaletteUsage::load(int count, ...) {
_data.clear();
for (int i = 0; i < count; ++i)
- _data.push_back(va_arg(va, int));
+ _data.push_back(UsageEntry(va_arg(va, int)));
va_end(va);
}
@@ -61,20 +61,22 @@ void PaletteUsage::getKeyEntries(Common::Array<RGB6> &palette) {
for (uint i = 0; i < palette.size(); ++i) {
byte *uPtr = &palette[i]._flags;
if ((*uPtr & 0x10) && _data.size() < 3) {
- _data.push_back(i);
+ _data.push_back(UsageEntry(i));
}
}
}
-void PaletteUsage::prioritize(Common::Array<RGB6> &palette) {
- int lst[3];
+static bool sortHelper(const PaletteUsage::UsageEntry &ue1, const PaletteUsage::UsageEntry &ue2) {
+ return ue1._sortValue < ue2._sortValue;
+}
+void PaletteUsage::prioritize(Common::Array<RGB6> &palette) {
for (uint i = 0; i < _data.size(); ++i) {
- RGB6 &palEntry = palette[_data[i]];
- lst[i] = rgbMerge(palEntry);
+ RGB6 &palEntry = palette[_data[i]._palIndex];
+ _data[i]._sortValue = rgbMerge(palEntry);
}
- prioritizeFromList(lst);
+ Common::sort(_data.begin(), _data.end(), sortHelper);
}
int PaletteUsage::process(Common::Array<RGB6> &palette, uint flags) {
@@ -147,17 +149,17 @@ int PaletteUsage::process(Common::Array<RGB6> &palette, uint flags) {
if (hasUsage && palette[v1]._flags & 0x10) {
for (uint usageIndex = 0; usageIndex < _data.size() && !var48; ++usageIndex) {
- if (_data[usageIndex] == palIndex) {
+ if (_data[usageIndex]._palIndex == palIndex) {
var48 = true;
int dataIndex = MIN(usageIndex, _data.size() - 1);
- var4 = _data[dataIndex];
+ var4 = _data[dataIndex]._palIndex;
}
}
}
if (flag1 && palette[palIndex]._flags & 0x10) {
for (uint usageIndex = 0; usageIndex < _data.size() && !var48; ++usageIndex) {
- if (_data[usageIndex] == palIndex) {
+ if (_data[usageIndex]._palIndex == palIndex) {
var48 = true;
var4 = 0xF0 + usageIndex;
@@ -241,63 +243,10 @@ int PaletteUsage::rgbMerge(RGB6 &palEntry) {
((palEntry.b + 1) / 4 - 1) * 14;
}
-void PaletteUsage::prioritizeFromList(int lst[3]) {
- int idx1 = _data.size() - 1;
- bool continueFlag;
- int count2;
-
- do {
- continueFlag = false;
- count2 = 0;
-
- if (idx1 > 0) {
- int numEntries = _data.size() - 1;
- int usageIndex = 0, lstIndex = 0;
-
- do {
- if (lst[lstIndex] < lst[lstIndex + 1]) {
- int lstVal = lst[lstIndex];
- int usageVal = _data[usageIndex];
-
- if (numEntries > 0) {
- Common::copy(&lst[lstIndex + 1], &lst[lstIndex + numEntries], &lst[lstIndex]);
- _data.remove_at(usageIndex);
- _data.push_back(0);
- }
-
- int newIdx = 0;
- if (idx1 > 0 && !continueFlag) {
- for (newIdx = 0; newIdx <= idx1; ++newIdx) {
- if (lst[newIdx] > lstVal)
- break;
- }
- }
-
- continueFlag = true;
- int idxDiff = _data.size() - newIdx - 1;
- if (idxDiff > 0) {
- Common::copy_backward(&lst[0], &lst[2], &lst[1]);
- _data.remove_at(2);
- _data.insert_at(0, 0);
- }
-
- lst[newIdx] = lstVal;
- _data[newIdx] = usageVal;
- }
-
- ++usageIndex;
- --numEntries;
- ++lstIndex;
- ++count2;
- } while (count2 > idx1 && !continueFlag);
- }
- } while (continueFlag);
-}
-
void PaletteUsage::transform(Common::Array<RGB6> &palette) {
if (!empty()) {
for (uint i = 0; i < _data.size(); ++i) {
- int palIndex = _data[i];
+ int palIndex = _data[i]._palIndex;
_data[i] = palette[palIndex]._palIndex;
}
}