Optimise tweening by skipping get_sprite() and its assert

This commit is contained in:
Michał Janiszewski 2016-09-15 00:25:37 +02:00 committed by Ted John
parent 560af48f85
commit aa3dd894ee
3 changed files with 16 additions and 11 deletions

View File

@ -75,7 +75,7 @@ EVP_MD_CTX *gHashCTX = NULL;
int _finished;
// Used for object movement tweening
static struct { sint16 x, y, z; } _spritelocations1[MAX_SPRITES], _spritelocations2[MAX_SPRITES];
static rct_xyz16 _spritelocations1[MAX_SPRITES], _spritelocations2[MAX_SPRITES];
static void openrct2_loop();
static void openrct2_setup_rct2_hooks();
@ -405,21 +405,13 @@ static void openrct2_loop()
while (uncapTick <= currentTick && currentTick - uncapTick > 25) {
// Get the original position of each sprite
for (uint16 i = 0; i < MAX_SPRITES; i++) {
_spritelocations1[i].x = get_sprite(i)->unknown.x;
_spritelocations1[i].y = get_sprite(i)->unknown.y;
_spritelocations1[i].z = get_sprite(i)->unknown.z;
}
store_sprite_locations(_spritelocations1);
// Update the game so the sprite positions update
rct2_update();
// Get the next position of each sprite
for (uint16 i = 0; i < MAX_SPRITES; i++) {
_spritelocations2[i].x = get_sprite(i)->unknown.x;
_spritelocations2[i].y = get_sprite(i)->unknown.y;
_spritelocations2[i].z = get_sprite(i)->unknown.z;
}
store_sprite_locations(_spritelocations2);
uncapTick += 25;
}

View File

@ -44,6 +44,18 @@ rct_sprite *get_sprite(size_t sprite_idx)
return &_spriteList[sprite_idx];
}
void store_sprite_locations(rct_xyz16 * sprite_locations)
{
for (uint16 i = 0; i < MAX_SPRITES; i++) {
// skip going through `get_sprite` to not get stalled on assert,
// this can get very expensive for busy parks with uncap FPS option on
const rct_sprite *sprite = &_spriteList[i];
sprite_locations[i].x = sprite->unknown.x;
sprite_locations[i].y = sprite->unknown.y;
sprite_locations[i].z = sprite->unknown.z;
}
}
uint16 sprite_get_first_in_quadrant(int x, int y)
{
int offset = ((x & 0x1FE0) << 3) | (y >> 5);

View File

@ -400,6 +400,7 @@ enum {
};
rct_sprite *get_sprite(size_t sprite_idx);
void store_sprite_locations(rct_xyz16 *sprite_locations);
// rct2: 0x00982708
extern rct_sprite_entry g_sprite_entries[48];