utils: Push/PopTransform functions for easier transforming

This commit is contained in:
Sebastian Krzyszkowiak 2019-02-26 18:14:19 +01:00
parent b84727bff0
commit ae9cf19778
No known key found for this signature in database
GPG key ID: E8F235CF3BDBC3FF
4 changed files with 27 additions and 0 deletions

View file

@ -100,6 +100,9 @@ SYMBOL_EXPORT struct Game* libsuperderpy_init(int argc, char** argv, const char*
game->_priv.speed = ALLEGRO_BPS_TO_SECS(60.0);
game->_priv.transforms = NULL;
game->_priv.transforms_no = 0;
game->_priv.mutex = al_create_mutex();
game->config.fullscreen = strtol(GetConfigOptionDefault(game, "SuperDerpy", "fullscreen", "1"), NULL, 10);
@ -489,6 +492,7 @@ SYMBOL_EXPORT void libsuperderpy_destroy(struct Game* game) {
free(game->_priv.garbage->data);
game->_priv.garbage = game->_priv.garbage->next;
}
free(game->_priv.transforms);
Console_Unload(game);
al_destroy_display(game->display);
al_destroy_user_event_source(&(game->event_source));

View file

@ -248,6 +248,9 @@ struct Game {
ALLEGRO_TRANSFORM projection; /*!< Projection of the game canvas into the actual game window. */
ALLEGRO_TRANSFORM* transforms;
int transforms_no, transforms_alloc;
#ifdef ALLEGRO_MACOSX
char cwd[MAXPATHLEN];
#endif

View file

@ -625,6 +625,23 @@ SYMBOL_EXPORT void ResetClippingRectangle(void) {
al_reset_clipping_rectangle();
}
SYMBOL_EXPORT void PushTransform(struct Game* game, ALLEGRO_TRANSFORM* t) {
ALLEGRO_TRANSFORM transform = *t;
if (game->_priv.transforms_no == game->_priv.transforms_alloc) {
game->_priv.transforms = realloc(game->_priv.transforms, sizeof(ALLEGRO_TRANSFORM) * ++game->_priv.transforms_alloc);
}
game->_priv.transforms[game->_priv.transforms_no++] = *al_get_current_transform();
al_compose_transform(&transform, al_get_current_transform());
al_use_transform(&transform);
}
SYMBOL_EXPORT void PopTransform(struct Game* game) {
al_use_transform(&game->_priv.transforms[--game->_priv.transforms_no]);
}
SYMBOL_EXPORT ALLEGRO_BITMAP* CreateNotPreservedBitmap(int width, int height) {
int flags = al_get_new_bitmap_flags();
//al_set_new_bitmap_depth(24);

View file

@ -77,6 +77,9 @@ void SetFramebufferAsTarget(struct Game* game);
void SetClippingRectangle(int x, int y, int width, int height);
void ResetClippingRectangle(void);
void PushTransform(struct Game* game, ALLEGRO_TRANSFORM* transform);
void PopTransform(struct Game* game);
ALLEGRO_BITMAP* CreateNotPreservedBitmap(int width, int height);
void EnableCompositor(struct Game* game, void compositor(struct Game* game, struct Gamestate* gamestates, ALLEGRO_BITMAP* loading_fb));