Skip to content

Commit 84555ea

Browse files
palette animations are per tileset not sprite
1 parent a1e596d commit 84555ea

4 files changed

Lines changed: 22 additions & 13 deletions

File tree

CIO/CFile.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,6 @@ bool CFile::read_lbm(FILE* fp, const boost::filesystem::path& filepath)
349349
// fseek(fp, length-20, SEEK_CUR);
350350

351351
const Uint16 tilesetSlot = static_cast<Uint16>(bmpArray - global::bmpArray.data());
352-
int chunkIdx = 0;
353352

354353
/* READ SECOND CHUNK "CMAP" */
355354

@@ -421,7 +420,19 @@ bool CFile::read_lbm(FILE* fp, const boost::filesystem::path& filepath)
421420
anim.currentOffset = 0;
422421
anim.lastAppliedOffset = 0;
423422
anim.lastUpdateTime = SDL_GetTicks();
424-
global::paletteAnimations[tilesetSlot][chunkIdx] = anim;
423+
switch(tilesetSlot)
424+
{
425+
case TILESET_GREENLAND_8BPP:
426+
global::paletteAnimations[MAP_GREENLAND].push_back(anim);
427+
break;
428+
case TILESET_WASTELAND_8BPP:
429+
global::paletteAnimations[MAP_WASTELAND].push_back(anim);
430+
break;
431+
case TILESET_WINTERLAND_8BPP:
432+
global::paletteAnimations[MAP_WINTERLAND].push_back(anim);
433+
break;
434+
default: break;
435+
}
425436
}
426437
if(chunkLen > 8)
427438
{
@@ -445,7 +456,6 @@ bool CFile::read_lbm(FILE* fp, const boost::filesystem::path& filepath)
445456
chunkLen++;
446457
fseek(fp, chunkLen, SEEK_CUR);
447458
}
448-
chunkIdx++;
449459
}
450460
if(feof(fp))
451461
return false;

CSurface.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1515,12 +1515,10 @@ static void rotatePaletteRange(SDL_Palette* pal, uint8_t firstClr, int colorCoun
15151515

15161516
void CSurface::UpdatePaletteAnimations(MapType mapType)
15171517
{
1518-
const auto tilesetIdx8 = tilesetIdxForMapType(mapType, false);
1519-
auto animIt = global::paletteAnimations.find(static_cast<Uint16>(tilesetIdx8));
1520-
if(animIt == global::paletteAnimations.end() || animIt->second.empty())
1518+
if(global::paletteAnimations[mapType].empty())
15211519
return;
15221520

1523-
auto& animMap = animIt->second;
1521+
const auto tilesetIdx8 = tilesetIdxForMapType(mapType, false);
15241522
auto* surf8 = global::bmpArray[tilesetIdx8].surface.get();
15251523
if(!surf8 || !surf8->format->palette)
15261524
return;
@@ -1535,7 +1533,7 @@ void CSurface::UpdatePaletteAnimations(MapType mapType)
15351533
const unsigned now = SDL_GetTicks();
15361534
bool anyUpdate = false;
15371535

1538-
for(auto& [palAnimIdx, anim] : animMap)
1536+
for(auto& anim : global::paletteAnimations[mapType])
15391537
{
15401538
if(anim.rate == 0)
15411539
continue;

globals.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ std::vector<bobBMP> global::bmpArray(MAXBOBBMP);
1212
std::vector<bobSHADOW> global::shadowArray(MAXBOBSHADOW);
1313
// array for all palettes
1414
std::vector<bobPAL> global::palArray(MAXBOBPAL);
15-
// Palette animations keyed by (bmpArray slot of 8-bit tileset) -> (CRNG chunk index).
16-
std::map<Uint16, std::map<int, PaletteAnimation>> global::paletteAnimations;
15+
// Palette animations per tileset, indexed by MapType (0=Greenland, 1=Wasteland, 2=Winterland).
16+
std::array<std::vector<PaletteAnimation>, 3> global::paletteAnimations;
1717
// the game object
1818
CGame* global::s2;
1919

globals.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include "gameData/WorldDescription.h"
99
#include <boost/filesystem/path.hpp>
1010
#include <SDL.h>
11-
#include <map>
11+
#include <array>
1212
#include <vector>
1313

1414
class CGame;
@@ -24,8 +24,9 @@ extern std::vector<bobBMP> bmpArray;
2424
extern std::vector<bobSHADOW> shadowArray;
2525
// array for all palettes
2626
extern std::vector<bobPAL> palArray;
27-
// Palette animations keyed by (bmpArray slot of 8-bit tileset) -> (CRNG chunk index).
28-
extern std::map<Uint16, std::map<int, PaletteAnimation>> paletteAnimations;
27+
// Palette animations per tileset, indexed by MapType (0=Greenland, 1=Wasteland, 2=Winterland).
28+
// Each entry is a list of CRNG chunk animations applied to the whole tileset palette.
29+
extern std::array<std::vector<PaletteAnimation>, 3> paletteAnimations;
2930
// the game object
3031
extern CGame* s2;
3132
// Path to game data (must not be empty!)

0 commit comments

Comments
 (0)