Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CGame_Render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ void CGame::Render()
// render the map if active
if(MapObj && MapObj->isActive())
{
if(MapObj->getMap())
CSurface::UpdatePaletteAnimations(MapObj->getMap()->type);
if(auto* mapSurf = MapObj->getSurface())
{
std::array<char, 100> textBuffer;
Expand Down
52 changes: 51 additions & 1 deletion CIO/CFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,8 @@ bool CFile::read_lbm(FILE* fp, const boost::filesystem::path& filepath)
// skip unknown data (length - 20 x 1 Byte)
// fseek(fp, length-20, SEEK_CUR);

const Uint16 tilesetSlot = static_cast<Uint16>(bmpArray - global::bmpArray.data());

/* READ SECOND CHUNK "CMAP" */

// chunk-identifier (4 Bytes)
Expand Down Expand Up @@ -392,7 +394,55 @@ bool CFile::read_lbm(FILE* fp, const boost::filesystem::path& filepath)

if(strcmp(chunk_identifier.data(), "BODY") == 0)
break;
else
else if(strcmp(chunk_identifier.data(), "CRNG") == 0)
{
Uint32 chunkLen;
CHECK_READ(libendian::be_read_ui(&chunkLen, fp));
if(chunkLen >= 8)
{
uint16_t padding, rate, flags;
CHECK_READ(libendian::be_read_us(&padding, fp));
CHECK_READ(libendian::be_read_us(&rate, fp));
CHECK_READ(libendian::be_read_us(&flags, fp));
uint8_t firstClr, lastClr;
CHECK_READ(libendian::read(&firstClr, 1, fp));
CHECK_READ(libendian::read(&lastClr, 1, fp));
// Only register valid animations: at least 2 colors and non-zero rate
if(rate > 0 && lastClr > firstClr)
{
PaletteAnimation anim;
anim.moveUp = (flags & 2) != 0;
if(rate)
anim.moveUp = true;
anim.rate = rate;
anim.firstClr = firstClr;
anim.lastClr = lastClr;
anim.currentOffset = 0;
anim.lastAppliedOffset = 0;
anim.lastUpdateTime = SDL_GetTicks();
switch(tilesetSlot)
{
case TILESET_GREENLAND_8BPP: global::paletteAnimations[MAP_GREENLAND].push_back(anim); break;
case TILESET_WASTELAND_8BPP: global::paletteAnimations[MAP_WASTELAND].push_back(anim); break;
case TILESET_WINTERLAND_8BPP: global::paletteAnimations[MAP_WINTERLAND].push_back(anim); break;
default: break;
}
}
if(chunkLen > 8)
{
uint32_t remaining = chunkLen - 8;
if(remaining & 1)
remaining++;
fseek(fp, remaining, SEEK_CUR);
} else if(chunkLen & 1)
fseek(fp, 1, SEEK_CUR);
} else
{
if(chunkLen & 1)
chunkLen++;
fseek(fp, chunkLen, SEEK_CUR);
}
} else
{
Uint32 chunkLen;
CHECK_READ(libendian::be_read_ui(&chunkLen, fp));
Expand Down
7 changes: 7 additions & 0 deletions CMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,13 @@ class CMap
render();
return Surf_Map.get();
}
/// Returns nullptr if the surface is not 8-bit or not created yet
SDL_Palette* getSurfacePalette() const
{
if(!Surf_Map || Surf_Map->format->BytesPerPixel != 1)
return nullptr;
return Surf_Map->format->palette;
}
DisplayRectangle getDisplayRect() { return displayRect; }
void setDisplayRect(const DisplayRectangle& displayRect) { this->displayRect = displayRect; }
auto& getPlayerHQx() { return PlayerHQx; }
Expand Down
Loading