Bladeren bron

optimize performance of text banner scrolling

ipatix 7 jaren geleden
bovenliggende
commit
219ab42ad9
1 gewijzigde bestanden met toevoegingen van 27 en 18 verwijderingen
  1. 27
    18
      src/overworld/tileset_animation/text_animator.c

+ 27
- 18
src/overworld/tileset_animation/text_animator.c Bestand weergeven

@@ -6,8 +6,8 @@
6 6
 #define CANVAS_X_SECOND (22)
7 7
 #define CANVAS_Y_SECOND (36)
8 8
 
9
-#define CANVAS_FIRST (u8 *)(574 * 0x20 + 0x06000000)
10
-#define CANVAS_SECOND (u8 *)(592 * 0x20 + 0x06000000)
9
+#define CANVAS_FIRST ((u8 *)(574 * 0x20 + 0x06000000))
10
+#define CANVAS_SECOND ((u8 *)(592 * 0x20 + 0x06000000))
11 11
 
12 12
 static const char *map_texts[] = {"--------", "< Carun City", "Route 2 >", NULL};
13 13
 
@@ -68,24 +68,33 @@ void set_pixel(u8 x, u8 y, u16 *start, u16 pixel) {
68 68
 
69 69
 /* TODO: Compile RELEASE Versions of the game with higher optimization flags */
70 70
 
71
+#define TEXT_ANIM_TILE_ROW(c, x, y) (((u32 *)c)[x * 8 + y])
72
+
71 73
 void text_animator(u16 current_frame) {
72 74
     if ((current_frame % ANIMATION_FRAME_SPEED) == 0) {
73
-        u8 outer_pixels[16] = {
74
-            *(CANVAS_FIRST + 0),   *(CANVAS_FIRST + 4),   *(CANVAS_FIRST + 8),   *(CANVAS_FIRST + 12),
75
-            *(CANVAS_FIRST + 16),  *(CANVAS_FIRST + 20),  *(CANVAS_FIRST + 24),  *(CANVAS_FIRST + 28),
76
-            *(CANVAS_SECOND + 0),  *(CANVAS_SECOND + 4),  *(CANVAS_SECOND + 8),  *(CANVAS_SECOND + 12),
77
-            *(CANVAS_SECOND + 16), *(CANVAS_SECOND + 20), *(CANVAS_SECOND + 24), *(CANVAS_SECOND + 28)};
78
-
79
-        for (u8 i = 0; i < 71; ++i) {
80
-            for (u8 j = 0; j < 8; ++j) {
81
-                set_pixel(i, j, (u16 *)CANVAS_FIRST, get_pixel(i + 1, j, (u16 *)CANVAS_FIRST));
82
-                set_pixel(i, j, (u16 *)CANVAS_SECOND, get_pixel(i + 1, j, (u16 *)CANVAS_SECOND));
83
-            }
84
-        }
75
+        for (int y = 0; y < 8; ++y) {
76
+            u32 outer_pixel_upper = CANVAS_FIRST[y * 4];
77
+            u32 outer_pixel_lower = CANVAS_SECOND[y * 4];
78
+
79
+            for (int x = 17; x >= 0; --x) {
80
+                // tile:     AB-CD-EF-GH-|-NX      BC-DE-FG-HN
81
+                // mem:      BA-DC-FE-HG-|-XN ---> CB-ED-GF-NH
82
+                // register: HG-FE-DC-BA           NH-GF-ED-CB
83
+
84
+                u32 upper_row = TEXT_ANIM_TILE_ROW(CANVAS_FIRST, x, y);
85
+                u32 new_outer_pixel_upper = upper_row;
85 86
 
86
-        for (u8 y = 0; y < 8; ++y) {
87
-            set_pixel(71, y, (u16 *)CANVAS_FIRST, outer_pixels[y]);
88
-            set_pixel(71, y, (u16 *)CANVAS_SECOND, outer_pixels[y + 8]);
87
+                upper_row  = (upper_row >> 4) | (outer_pixel_upper << 28);
88
+                TEXT_ANIM_TILE_ROW(CANVAS_FIRST, x, y) = upper_row;
89
+                outer_pixel_upper = new_outer_pixel_upper;
90
+
91
+                u32 lower_row = TEXT_ANIM_TILE_ROW(CANVAS_SECOND, x, y);
92
+                u32 new_outer_pixel_lower = lower_row;
93
+
94
+                lower_row = (lower_row >> 4) | (outer_pixel_lower << 28);
95
+                TEXT_ANIM_TILE_ROW(CANVAS_SECOND, x, y) = lower_row;
96
+                outer_pixel_lower = new_outer_pixel_lower;
97
+            }
89 98
         }
90 99
     }
91 100
 }
@@ -98,4 +107,4 @@ void anim_init_text(void) {
98 107
         draw_text_on_canvas(map_texts[var_8000]);
99 108
         blockset_one_animator = text_animator;
100 109
     }
101
-}
110
+}