@@ -912,11 +912,17 @@ void render_raining_logo(DemoContext *ctx)
912912 }
913913}
914914
915+ /* Helper to calculate spaces generated by SKIP command */
916+ static int calculate_skip_spaces (float skip_screens )
917+ {
918+ return (int )(skip_screens * (WIDTH / 35.0f ));
919+ }
920+
915921/* Build a map of control code positions in the stripped text */
916922typedef struct {
917923 int position ; /* Character position in stripped text */
918924 float pixel_position ; /* Pixel position based on actual glyph widths */
919- char type ; /* P=pause, S=speed, T=style, C=color */
925+ char type ; /* P=pause, S=speed, T=style, C=color, K=skip */
920926 char data [64 ]; /* Parameter data */
921927} ControlCode ;
922928
@@ -963,6 +969,14 @@ static void build_control_map(const char *text)
963969 cc -> type = 'C' ;
964970 strncpy (cc -> data , cmd + 6 , 63 );
965971 num_control_codes ++ ;
972+ } else if (strncmp (cmd , "SKIP:" , 5 ) == 0 ) {
973+ /* SKIP is added to control codes for pixel position calculation */
974+ cc -> type = 'K' ;
975+ strncpy (cc -> data , cmd + 5 , 63 );
976+ num_control_codes ++ ;
977+ /* Advance char_pos by the spaces that SKIP will insert */
978+ float skip_screens = atof (cmd + 5 );
979+ char_pos += calculate_skip_spaces (skip_screens );
966980 }
967981 }
968982 p = end + 1 ;
@@ -1041,11 +1055,25 @@ static void apply_scroll_controls(DemoContext *ctx, float scroll_offset)
10411055 last_offset = scroll_offset ;
10421056
10431057 /* Apply control codes that we've just reached (not yet triggered) */
1044- /* Offset to delay trigger - adjust this value to find the right timing */
1045- const float trigger_offset = 500.0f ; /* Try WIDTH as starting point */
1046-
10471058 for (int i = 0 ; i < num_control_codes ; i ++ ) {
10481059 ControlCode * cc = & control_codes [i ];
1060+ float trigger_offset = 0.0f ;
1061+
1062+ /* Different trigger offsets for different control code types */
1063+ switch (cc -> type ) {
1064+ case 'P' : /* PAUSE */
1065+ trigger_offset = 500.0f ;
1066+ break ;
1067+ case 'S' : /* SPEED */
1068+ trigger_offset = 500.0f ;
1069+ break ;
1070+ case 'T' : /* STYLE */
1071+ trigger_offset = 500.0f ;
1072+ break ;
1073+ case 'C' : /* COLOR */
1074+ trigger_offset = 500.0f ;
1075+ break ;
1076+ }
10491077
10501078 /* Trigger when we pass the pixel position plus offset (only once) */
10511079 if (!triggered [i ] && scroll_offset >= cc -> pixel_position + trigger_offset ) {
@@ -1102,18 +1130,57 @@ static char *strip_control_codes(const char *text)
11021130 if (!text )
11031131 return NULL ;
11041132
1105- int len = strlen (text );
1106- char * result = malloc (len + 1 );
1133+ /* First pass: calculate required size accounting for SKIP expansions */
1134+ int expanded_len = 0 ;
1135+ const char * p = text ;
1136+ while (* p ) {
1137+ if (* p == '{' ) {
1138+ const char * end = strchr (p , '}' );
1139+ if (end ) {
1140+ int cmd_len = end - p - 1 ;
1141+ char cmd [64 ] = {0 };
1142+ if (cmd_len > 0 && cmd_len < 64 ) {
1143+ strncpy (cmd , p + 1 , cmd_len );
1144+ /* Check if this is a SKIP command */
1145+ if (strncmp (cmd , "SKIP:" , 5 ) == 0 ) {
1146+ float skip_screens = atof (cmd + 5 );
1147+ expanded_len += calculate_skip_spaces (skip_screens );
1148+ }
1149+ }
1150+ p = end + 1 ;
1151+ continue ;
1152+ }
1153+ }
1154+ expanded_len ++ ;
1155+ p ++ ;
1156+ }
1157+
1158+ /* Allocate result with room for expansions */
1159+ char * result = malloc (expanded_len + 1 );
11071160 if (!result )
11081161 return NULL ;
11091162
1163+ /* Second pass: copy text and expand SKIP commands */
11101164 const char * src = text ;
11111165 char * dst = result ;
11121166
11131167 while (* src ) {
11141168 if (* src == '{' ) {
11151169 const char * end = strchr (src , '}' );
11161170 if (end ) {
1171+ int cmd_len = end - src - 1 ;
1172+ char cmd [64 ] = {0 };
1173+ if (cmd_len > 0 && cmd_len < 64 ) {
1174+ strncpy (cmd , src + 1 , cmd_len );
1175+ /* Expand SKIP into spaces */
1176+ if (strncmp (cmd , "SKIP:" , 5 ) == 0 ) {
1177+ float skip_screens = atof (cmd + 5 );
1178+ int spaces = calculate_skip_spaces (skip_screens );
1179+ for (int i = 0 ; i < spaces ; i ++ ) {
1180+ * dst ++ = ' ' ;
1181+ }
1182+ }
1183+ }
11171184 src = end + 1 ;
11181185 continue ;
11191186 }
0 commit comments