Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance: optimize car drawing by not recreating dynamic sprite each time when angle changes #1

Open
ivan-mogilko opened this issue Apr 22, 2023 · 0 comments

Comments

@ivan-mogilko
Copy link
Owner

ivan-mogilko commented Apr 22, 2023

Here how it looks now:

// TODO: perhaps cache a number of often-used angles to improve perfomance?
if (this.dSprite == null || angle != this.dSpriteRotation) {
if (this.dSprite != null)
this.dSprite.Delete();
if (angle != 0) {
DynamicSprite *spr = DynamicSprite.CreateFromExistingSprite(this.carSprite, true);
spr.Rotate(angle);
this.dSprite = spr;
this.viewFrame.Graphic = this.dSprite.Graphic;
// HACK: poke AGS to refresh the character cache
DrawingSurface *ds = this.dSprite.GetDrawingSurface();
ds.DrawPixel(-1, -1);
ds.Release();
} else {
this.dSprite = null;
this.viewFrame.Graphic = this.carSprite;
}
this.dSpriteRotation = angle;
}

The problem was that AGS does not provide some kind of "DrawRotated" function, so you have to rotate existing sprite.
Might try this: create a max-sized square sprite and keep drawing on it with necessary offsets; then also use same offsets when locking character's view.

Also if you do that, there will be no need to "poke" the engine by putting a single pixel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant