Pre-emptively reset sprites on export for higher compression ratios (#5668)

The sprites need to be reset anyway before they get used, so reset them
on every export just so they can be compressed better
This commit is contained in:
Michał Janiszewski 2017-06-20 16:34:04 +02:00 committed by GitHub
parent 8b6ecc76d2
commit 9bfc9a91e3
3 changed files with 25 additions and 0 deletions

View File

@ -52,6 +52,7 @@ extern "C"
#include "../world/Climate.h"
#include "../world/map_animation.h"
#include "../world/park.h"
#include "../world/sprite.h"
}
S6Exporter::S6Exporter()
@ -178,6 +179,13 @@ void S6Exporter::Export()
memcpy(_s6.map_elements, gMapElements, sizeof(_s6.map_elements));
_s6.next_free_map_element_pointer_index = gNextFreeMapElementPointerIndex;
// Sprites needs to be reset before they get used.
// Might as well reset them in here to zero out the space and improve
// compression ratios. Especially useful for multiplayer servers that
// use zlib on the sent stream.
{
reset_empty_sprites();
}
for (sint32 i = 0; i < MAX_SPRITES; i++)
{
memcpy(&_s6.sprites[i], get_sprite(i), sizeof(rct_sprite));

View File

@ -289,6 +289,22 @@ static void sprite_reset(rct_unk_sprite *sprite)
sprite->sprite_index = sprite_index;
}
// Resets all sprites in SPRITE_LIST_NULL list
void reset_empty_sprites()
{
uint16 spriteIndex;
spriteIndex = gSpriteListHead[SPRITE_LIST_NULL];
while (spriteIndex != SPRITE_INDEX_NULL)
{
rct_unk_sprite *sprite = &(get_sprite(spriteIndex))->unknown;
spriteIndex = sprite->next;
if (sprite->sprite_identifier == SPRITE_IDENTIFIER_NULL)
{
sprite_reset(sprite);
}
}
}
/*
* rct2: 0x0069EC6B
* bl: if bl & 2 > 0, the sprite ends up in the MISC linked list.

View File

@ -419,6 +419,7 @@ extern uint16 *gSpriteListCount;
extern uint16 gSpriteSpatialIndex[0x10001];
rct_sprite *create_sprite(uint8 bl);
void reset_empty_sprites();
void reset_sprite_list();
void reset_sprite_spatial_index();
void sprite_clear_all_unused();