Skip to content

Commit

Permalink
Optimize Animation
Browse files Browse the repository at this point in the history
  • Loading branch information
bilgincoskun committed Aug 10, 2020
1 parent 6bc1ee9 commit 4a794e4
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions app/jni/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@
#define MIN_TILE G_UP_ARROW

typedef struct {
SDL_Texture *c;
double width, height, offset_x, offset_y;
SDL_Texture *c;
boolean animated;
} glyph_cache;

typedef enum{
Expand Down Expand Up @@ -593,6 +594,7 @@ void draw_glyph(enum displayGlyph c, SDL_FRect rect, uint8_t r, uint8_t g, uint8
text = TTF_RenderGlyph_Blended(font, key - TILES_LEN, fc);
}else{
text = TTF_RenderGlyph_Blended(font, key, fc);
font_cache[c].animated = true;
}
lc->width = text->w;
lc->height = text->h;
Expand Down Expand Up @@ -1342,9 +1344,10 @@ boolean TouchScreenPauseForMilliseconds(short milliseconds){

void TouchScreenNextKeyOrMouseEvent(rogueEvent *returnEvent, boolean textInput, boolean colorsDance) {
while(!process_events()){
boolean screen_changed = false;
if (dynamic_colors && colorsDance) {
shuffleTerrainColors(3, true);
commitDraws();
screen_changed = true;
}
if (graphicsEnabled && tiles_animation){
static uint32_t prev_time = 0;
Expand All @@ -1362,12 +1365,20 @@ void TouchScreenNextKeyOrMouseEvent(rogueEvent *returnEvent, boolean textInput,
//Do not refresh screen during zoom change
static double prev_zoom = 0.0;
if(refresh && prev_zoom == zoom_level){
refreshScreen();
for(int i=0; i<COLS; i++ ) {
for(int j=0; j<ROWS; j++ ) {
displayBuffer[i][j].needsUpdate = font_cache[displayBuffer[i][j].character].animated;
}
}
screen_changed = true;
}
prev_zoom = zoom_level;
}else{
tiles_frame = 0;
}
if(screen_changed){
commitDraws();
}
TouchScreenPauseForMilliseconds(FRAME_INTERVAL);

}
Expand Down

0 comments on commit 4a794e4

Please sign in to comment.