Commit eeae9d2161a5dda469ff7f46444f250525713e97

Thomas de Grivel 2023-12-29T01:29:46

wip types and void

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
diff --git a/libc3/sequence.c b/libc3/sequence.c
index 2d02a0c..a50ea21 100644
--- a/libc3/sequence.c
+++ b/libc3/sequence.c
@@ -21,16 +21,20 @@ void sequence_clean (s_sequence *seq)
 
 s_sequence * sequence_init (s_sequence *seq, f64 duration,
                             const s8 *title, f_sequence load,
-                            f_sequence render, f_sequence unload)
+                            f_sequence render, f_sequence unload,
+                            void *window)
 {
+  s_sequence tmp = {0};
   assert(seq);
-  seq->dt = 0.0;
-  seq->t = 0.0;
-  seq->duration = duration;
-  seq->title = title;
-  seq->load = load;
-  seq->render = render;
-  seq->unload = unload;
-  tag_init_void(&seq->tag);
+  tmp.dt = 0.0;
+  tmp.t = 0.0;
+  tmp.duration = duration;
+  tag_init_void(&tmp.tag);
+  tmp.title = title;
+  tmp.load = load;
+  tmp.render = render;
+  tmp.unload = unload;
+  tmp.window = window;
+  *seq = tmp;
   return seq;
 }
diff --git a/libc3/sequence.h b/libc3/sequence.h
index 1adf186..a869db2 100644
--- a/libc3/sequence.h
+++ b/libc3/sequence.h
@@ -20,6 +20,7 @@
 void         sequence_clean (s_sequence *seq);
 s_sequence * sequence_init (s_sequence *sequence, f64 duration,
                             const s8 *title, f_sequence load,
-                            f_sequence render, f_sequence unload);
+                            f_sequence render, f_sequence unload,
+                            void *window);
 
 #endif /* LIBC3_SEQUENCE_H */
diff --git a/libc3/void.c b/libc3/void.c
index c5c01d1..7abd6ef 100644
--- a/libc3/void.c
+++ b/libc3/void.c
@@ -142,143 +142,86 @@ bool void_clean (const s_sym *type, void *data)
   return false;
 }
 
-bool void_init_copy (const s_sym *type, void *v, const void *src)
+void * void_init_copy (const s_sym *type, void *v, const void *src)
 {
-  if (type == sym_1("Array")) {
-    array_init_copy;
-    return true;
-  }
-  if (type == sym_1("Bool")) {
-    bool_init_copy;
-    return true;
-  }
-  if (type == sym_1("Call")) {
-    call_init_copy;
-    return true;
-  }
-  if (type == sym_1("Cfn")) {
-    cfn_init_copy;
-    return true;
-  }
-  if (type == sym_1("Character")) {
-    character_init_copy;
-    return true;
-  }
-  if (type == sym_1("F32")) {
-    f32_init_copy;
-    return true;
-  }
-  if (type == sym_1("F64")) {
-    f64_init_copy;
-    return true;
-  }
-  if (type == sym_1("Fact")) {
-    fact_init_copy;
-    return true;
-  }
-  if (type == sym_1("Fn")) {
-    fn_init_copy;
-    return true;
-  }
-  if (type == sym_1("Ident")) {
-    ident_init_copy;
-    return true;
-  }
-  if (type == sym_1("Integer")) {
-    integer_init_copy;
-    return true;
-  }
-  if (type == sym_1("List")) {
-    list_init_copy;
-    return true;
-  }
-  if (type == sym_1("Ptag")) {
-    ptag_init_copy;
-    return true;
-  }
-  if (type == sym_1("Ptr")) {
-    ptr_init_copy;
-    return true;
-  }
-  if (type == sym_1("PtrFree")) {
-    ptr_free_init_copy;
-    return true;
-  }
-  if (type == sym_1("Quote")) {
-    quote_init_copy;
-    return true;
-  }
-  if (type == sym_1("S8")) {
-    s8_init_copy;
-    return true;
-  }
-  if (type == sym_1("S16")) {
-    s16_init_copy;
-    return true;
-  }
-  if (type == sym_1("S32")) {
-    s32_init_copy;
-    return true;
-  }
-  if (type == sym_1("S64")) {
-    s64_init_copy;
-    return true;
-  }
-  if (type == sym_1("Str")) {
-    str_init_copy;
-    return true;
-  }
-  if (type == sym_1("Struct")) {
-    struct_init_copy;
-    return true;
-  }
-  if (type == sym_1("Sw")) {
-    sw_init_copy;
-    return true;
-  }
-  if (type == sym_1("Sym")) {
-    sym_init_copy;
-    return true;
-  }
-  if (type == sym_1("Tuple")) {
-    tuple_init_copy;
-    return true;
-  }
-  if (type == sym_1("U8")) {
-    u8_init_copy;
-    return true;
-  }
-  if (type == sym_1("U16")) {
-    u16_init_copy;
-    return true;
-  }
-  if (type == sym_1("U32")) {
-    u32_init_copy;
-    return true;
-  }
-  if (type == sym_1("U64")) {
-    u64_init_copy;
-    return true;
-  }
-  if (type == sym_1("Uw")) {
-    uw_init_copy;
-    return true;
-  }
-  if (type == sym_1("Var")) {
-    *dest = NULL;
-    return true;
-  }
-  if (type == sym_1("Void")) {
-    *dest = NULL;
-    return true;
-  }
+  void *r;
+  if (type == sym_1("Array"))
+    return array_init_copy(v, src);
+  if (type == sym_1("Bool"))
+    return bool_init_copy(v, src);
+  if (type == sym_1("Call"))
+    return call_init_copy(v, src);
+  if (type == sym_1("Cfn"))
+    return cfn_init_copy(v, src);
+  if (type == sym_1("Character"))
+    return character_init_copy(v, src);
+  if (type == sym_1("F32"))
+    return f32_init_copy(v, src);
+  if (type == sym_1("F64"))
+    return f64_init_copy(v, src);
+  if (type == sym_1("Fact"))
+    return fact_init_copy(v, src);
+  if (type == sym_1("Fn"))
+    return fn_init_copy(v, src);
+  if (type == sym_1("Ident"))
+    return ident_init_copy(v, src);
+  if (type == sym_1("Integer"))
+    return integer_init_copy(v, src);
+  if (type == sym_1("List"))
+    return list_init_copy(v, src);
+  if (type == sym_1("Ptag"))
+    return ptag_init_copy(v, src);
+  if (type == sym_1("Ptr"))
+    return ptr_init_copy(v, src);
+  if (type == sym_1("PtrFree"))
+    return ptr_free_init_copy(v, src);
+  if (type == sym_1("Quote"))
+    return quote_init_copy(v, src);
+  if (type == sym_1("S8"))
+    return s8_init_copy(v, src);
+  if (type == sym_1("S16"))
+    return s16_init_copy(v, src);
+  if (type == sym_1("S32"))
+    return s32_init_copy(v, src);
+  if (type == sym_1("S64"))
+    return s64_init_copy(v, src);
+  if (type == sym_1("Str"))
+    return str_init_copy(v, src);
+  if (type == sym_1("Struct"))
+    return struct_init_copy(v, src);
+  if (type == sym_1("Sw"))
+    return sw_init_copy(v, src);
+  if (type == sym_1("Sym"))
+    return sym_init_copy(v, src);
+  if (type == sym_1("Tuple"))
+    return tuple_init_copy(v, src);
+  if (type == sym_1("U8"))
+    return u8_init_copy(v, src);
+  if (type == sym_1("U16"))
+    return u16_init_copy(v, src);
+  if (type == sym_1("U32"))
+    return u32_init_copy(v, src);
+  if (type == sym_1("U64"))
+    return u64_init_copy(v, src);
+  if (type == sym_1("Uw"))
+    return uw_init_copy(v, src);
+  if (type == sym_1("Var"))
+    return v;
+  if (type == sym_1("Void"))
+    return v;
   if (struct_type_exists(type)) {
-    struct_init_copy;
-    return true;
+    s_struct s = {0};
+    s_struct t = {0};
+    struct_init_with_data(&s, type, false, v);
+    struct_init_with_data(&t, type, false, (void *) src);
+    r = struct_init_copy(&s, &t);
+    struct_type_clean(&s.type);
+    struct_type_clean(&t.type);
+    return r;
   }
   err_write_1("void_init_copy: unknown type: ");
   err_inspect_sym(&type);
   err_write_1("\n");
   assert(! "void_init_copy: unknown type");
-  return false;
+  return NULL;
 }
diff --git a/libc3/window/cairo/demo/bg_rect.c b/libc3/window/cairo/demo/bg_rect.c
index 645d4e1..2e73815 100644
--- a/libc3/window/cairo/demo/bg_rect.c
+++ b/libc3/window/cairo/demo/bg_rect.c
@@ -15,18 +15,17 @@
 #include "../types.h"
 #include "bg_rect.h"
 
-bool bg_rect_load (s_sequence *seq, s_window_cairo *window)
+#define BG_RECT_COLOR_MAX 8
+
+bool bg_rect_load (s_sequence *seq)
 {
   (void) seq;
-  (void) window;
   return true;
 }
 
-bool bg_rect_render (s_sequence *seq, s_window_cairo *window,
-                     cairo_t *cr)
+bool bg_rect_render (s_sequence *seq)
 {
-#define C3_WINDOW_CAIRO_DEMO_BG_RECT_COLOR_MAX 8
-  const s_rgb color[C3_WINDOW_CAIRO_DEMO_BG_RECT_COLOR_MAX] = {
+  const s_rgb color[BG_RECT_COLOR_MAX] = {
     {0, 0, 0},
     {1, 0, 0},
     {1, 1, 0},
@@ -38,11 +37,15 @@ bool bg_rect_render (s_sequence *seq, s_window_cairo *window,
   };
   u8 c1;
   u8 c2;
+  cairo_t *cr;
   double p;
   double q;
   s_rgb rgb;
-  c1 = (u8) trunc(seq->t) % C3_WINDOW_CAIRO_DEMO_BG_RECT_COLOR_MAX;
-  c2 = (u8) trunc(seq->t + 1.0) % C3_WINDOW_CAIRO_DEMO_BG_RECT_COLOR_MAX;
+  s_window_cairo *window;
+  window = seq->window;
+  cr = window->cr;
+  c1 = (u8) trunc(seq->t) % BG_RECT_COLOR_MAX;
+  c2 = (u8) trunc(seq->t + 1.0) % BG_RECT_COLOR_MAX;
   p = fmod(seq->t, 1.0);
   q = 1.0 - p;
   rgb.r = color[c1].r * q + color[c2].r * p;
@@ -53,3 +56,9 @@ bool bg_rect_render (s_sequence *seq, s_window_cairo *window,
   cairo_fill(cr);
   return true;
 }
+
+bool bg_rect_unload (s_sequence *seq)
+{
+  (void) seq;
+  return true;
+}
diff --git a/libc3/window/cairo/demo/bg_rect.h b/libc3/window/cairo/demo/bg_rect.h
index cd451fa..74b604b 100644
--- a/libc3/window/cairo/demo/bg_rect.h
+++ b/libc3/window/cairo/demo/bg_rect.h
@@ -15,8 +15,8 @@
 
 #include "../types.h"
 
-bool bg_rect_load (s_sequence *seq, s_window_cairo *window);
-bool bg_rect_render (s_sequence *seq, s_window_cairo *window,
-                     cairo_t *cr);
+bool bg_rect_load (s_sequence *seq);
+bool bg_rect_render (s_sequence *seq);
+bool bg_rect_unload (s_sequence *seq);
 
 #endif /* BG_RECT_H */
diff --git a/libc3/window/cairo/demo/flies.c b/libc3/window/cairo/demo/flies.c
index d1ec38b..c9a74c7 100644
--- a/libc3/window/cairo/demo/flies.c
+++ b/libc3/window/cairo/demo/flies.c
@@ -51,15 +51,13 @@ static void fly_init (s_map *map)
   (*in)++;
 }
 
-bool flies_load (s_sequence *seq,
-                 s_window_cairo *window)
+bool flies_load (s_sequence *seq)
 {
   uw address[2];
   s_array *board;
   uw i;
   uw j;
   s_map *map;
-  (void) window;
   tag_map(&seq->tag, 4);
   map = &seq->tag.data.map;
   tag_init_sym_1( map->key  + 0, "board");
@@ -128,8 +126,7 @@ bool flies_load (s_sequence *seq,
   return true;
 }
 
-bool flies_render (s_sequence *seq, s_window_cairo *window,
-                   cairo_t *cr)
+bool flies_render (s_sequence *seq)
 {
   s8 a[BOARD_SIZE];
   uw address[2];
@@ -141,6 +138,7 @@ bool flies_render (s_sequence *seq, s_window_cairo *window,
   f64 board_item_w;
   f64 board_item_h;
   s_buf buf;
+  cairo_t *cr;
   f64 dead_fly_scale;
   u8   direction;
   u8   direction_prev = 4;
@@ -159,6 +157,9 @@ bool flies_render (s_sequence *seq, s_window_cairo *window,
   cairo_text_extents_t te;
   f64 x;
   f64 y;
+  s_window_cairo *window;
+  window = seq->window;
+  cr = window->cr;
   cairo_set_source_rgb(cr, 0.5, 0.5, 0.5);
   cairo_rectangle(cr, 0, 0, window->w, window->h);
   cairo_fill(cr);
@@ -310,3 +311,9 @@ bool flies_render (s_sequence *seq, s_window_cairo *window,
   }
   return true;
 }
+
+bool flies_unload (s_sequence *seq)
+{
+  (void) seq;
+  return true;
+}
diff --git a/libc3/window/cairo/demo/flies.h b/libc3/window/cairo/demo/flies.h
index 9695712..ee04b5e 100644
--- a/libc3/window/cairo/demo/flies.h
+++ b/libc3/window/cairo/demo/flies.h
@@ -18,8 +18,8 @@
 extern s_cairo_sprite g_sprite_dead_fly;
 extern s_cairo_sprite g_sprite_fly;
 
-bool flies_load (s_sequence *seq, s_window_cairo *window);
-bool flies_render (s_sequence *seq, s_window_cairo *window,
-                      cairo_t *cr);
+bool flies_load (s_sequence *seq);
+bool flies_render (s_sequence *seq);
+bool flies_unload (s_sequence *seq);
 
 #endif /* FLIES_H */
diff --git a/libc3/window/cairo/demo/lightspeed.c b/libc3/window/cairo/demo/lightspeed.c
index 19397dc..a535d91 100644
--- a/libc3/window/cairo/demo/lightspeed.c
+++ b/libc3/window/cairo/demo/lightspeed.c
@@ -53,10 +53,9 @@ static void star_render (s_tag *star, s_window_cairo *window,
     star_init(star);
 }
 
-bool lightspeed_load (s_sequence *seq, s_window_cairo *window)
+bool lightspeed_load (s_sequence *seq)
 {
   uw i;
-  (void) window;
   tag_tuple(&seq->tag, LIGHTSPEED_STARS);
   i = 0;
   while (i < LIGHTSPEED_STARS) {
@@ -66,11 +65,14 @@ bool lightspeed_load (s_sequence *seq, s_window_cairo *window)
   return true;
 }
 
-bool lightspeed_render (s_sequence *seq, s_window_cairo *window,
-                        cairo_t *cr)
+bool lightspeed_render (s_sequence *seq)
 {
+  cairo_t *cr;
   uw i;
   cairo_matrix_t matrix;
+  s_window_cairo *window;
+  window = seq->window;
+  cr = window->cr;
   cairo_get_matrix(cr, &matrix);
   cairo_scale(cr, window->w / 2.0, window->h / 2.0);
   cairo_translate(cr, 1.0, 1.0);
@@ -85,3 +87,9 @@ bool lightspeed_render (s_sequence *seq, s_window_cairo *window,
   cairo_set_matrix(cr, &matrix);
   return true;
 }
+
+bool lightspeed_unload (s_sequence *seq)
+{
+  (void) seq;
+  return true;
+}
diff --git a/libc3/window/cairo/demo/lightspeed.h b/libc3/window/cairo/demo/lightspeed.h
index dc95059..8b89b3b 100644
--- a/libc3/window/cairo/demo/lightspeed.h
+++ b/libc3/window/cairo/demo/lightspeed.h
@@ -17,8 +17,8 @@
 
 #define LIGHTSPEED_STARS 1000
 
-bool lightspeed_load (s_sequence *seq, s_window_cairo *window);
-bool lightspeed_render (s_sequence *seq, s_window_cairo *window,
-                        cairo_t *cr);
+bool lightspeed_load (s_sequence *seq);
+bool lightspeed_render (s_sequence *seq);
+bool lightspeed_unload (s_sequence *seq);
 
 #endif /* LIGHTSPEED_H */
diff --git a/libc3/window/cairo/demo/toasters.c b/libc3/window/cairo/demo/toasters.c
index 13086e1..ea59aac 100644
--- a/libc3/window/cairo/demo/toasters.c
+++ b/libc3/window/cairo/demo/toasters.c
@@ -39,7 +39,6 @@ static s_tag * toast_init (s_tag *toast, f64 x, f64 y)
   return toast;
 }
 
-
 static void toast_render (s_tag *toast, s_window_cairo *window,
                           cairo_t *cr, s_sequence *seq)
 {
@@ -99,11 +98,9 @@ static void toaster_render (s_tag *toaster, s_window_cairo *window,
   }
 }
 
-bool toasters_load (s_sequence *seq,
-                    s_window_cairo *window)
+bool toasters_load (s_sequence *seq)
 {
   s_map *map;
-  (void) window;
   tag_map(&seq->tag, 2);
   map = &seq->tag.data.map;
   tag_init_sym_1( map->key + 0, "toasters");
@@ -113,11 +110,14 @@ bool toasters_load (s_sequence *seq,
   return true;
 }
 
-bool toasters_render (s_sequence *seq, s_window_cairo *window,
-                      cairo_t *cr)
+bool toasters_render (s_sequence *seq)
 {
+  cairo_t *cr;
   s_list **toasters;
   s_list **toasts;
+  s_window_cairo *window;
+  window = seq->window;
+  cr = window->cr;
   cairo_set_source_rgb(cr, 0.7, 0.95, 1.0);
   cairo_rectangle(cr, 0, 0, window->w, window->h);
   cairo_fill(cr);
@@ -234,3 +234,9 @@ bool toasters_render_toasters (s_list **toasters,
   }
   return true;
 }
+
+bool toasters_unload (s_sequence *seq)
+{
+  (void) seq;
+  return true;
+}
diff --git a/libc3/window/cairo/demo/toasters.h b/libc3/window/cairo/demo/toasters.h
index b97b4b9..c476e48 100644
--- a/libc3/window/cairo/demo/toasters.h
+++ b/libc3/window/cairo/demo/toasters.h
@@ -18,8 +18,8 @@
 extern s_cairo_sprite g_sprite_toast;
 extern s_cairo_sprite g_sprite_toaster;
 
-bool toasters_load (s_sequence *seq, s_window_cairo *window);
-bool toasters_render (s_sequence *seq, s_window_cairo *window,
-                      cairo_t *cr);
+bool toasters_load (s_sequence *seq);
+bool toasters_render (s_sequence *seq);
+bool toasters_unload (s_sequence *seq);
 
 #endif /* TOASTERS_H */
diff --git a/libc3/window/cairo/demo/window_cairo_demo.c b/libc3/window/cairo/demo/window_cairo_demo.c
index b8096b9..6c85ac0 100644
--- a/libc3/window/cairo/demo/window_cairo_demo.c
+++ b/libc3/window/cairo/demo/window_cairo_demo.c
@@ -88,30 +88,28 @@ bool window_cairo_demo_load (s_window_cairo *window)
   if (! cairo_font_init(&g_font_courier_new,
                         "fonts/Courier New/Courier New.ttf"))
     return false;
-  window_cairo_sequence_init(window->sequence, 8.0,
-                             "01. Background rectangles",
-                             bg_rect_load, bg_rect_render);
-  window_cairo_sequence_init(window->sequence + 1, 20.0,
-                             "02. Lightspeed",
-                             lightspeed_load, lightspeed_render);
+  sequence_init(window->sequence, 8.0, "01. Background rectangles",
+                bg_rect_load, bg_rect_render, bg_rect_unload, window);
+  sequence_init(window->sequence + 1, 20.0, "02. Lightspeed",
+                lightspeed_load, lightspeed_render, lightspeed_unload,
+                window);
   if (! cairo_sprite_init(&g_sprite_toaster, "img/flaps.png",
                           4, 1, 4))
     return false;
   if (! cairo_sprite_init(&g_sprite_toast, "img/toast.png",
                           1, 1, 1))
     return false;
-  window_cairo_sequence_init(window->sequence + 2, 60.0,
-                             "03. Toasters",
-                             toasters_load, toasters_render);
+  sequence_init(window->sequence + 2, 60.0, "03. Toasters",
+                toasters_load, toasters_render, toasters_unload,
+                window);
   if (! cairo_sprite_init(&g_sprite_fly, "img/fly-noto.png",
                           1, 1, 1))
     return false;
   if (! cairo_sprite_init(&g_sprite_dead_fly, "img/fly-dead.png",
                           1, 1, 1))
     return false;
-  window_cairo_sequence_init(window->sequence + 3, 60.0,
-                             "04. Flies",
-                             flies_load, flies_render);
+  sequence_init(window->sequence + 3, 60.0, "04. Flies",
+                flies_load, flies_render, flies_unload, window);
   window_set_sequence_pos((s_window *) window, 0);
   return true;
 }
@@ -142,17 +140,18 @@ static void render_text (cairo_t *cr, double x, double y,
   cairo_show_text(cr, p);
 }
 
-bool window_cairo_demo_render (s_window_cairo *window,
-                               cairo_t *cr)
+bool window_cairo_demo_render (s_window_cairo *window)
 {
+  cairo_t *cr;
   s_sequence *seq;
   cairo_text_extents_t te;
   assert(window);
+  cr = window->cr;
   assert(cr);
   if (! window_animate((s_window *) window))
     return false;
   seq = window->sequence + window->sequence_pos;
-  if (! seq->render(seq, window, cr))
+  if (! seq->render(seq))
     return false;
   /* text */
   cairo_set_font_size(cr, 20);
diff --git a/libc3/window/cairo/demo/window_cairo_demo.h b/libc3/window/cairo/demo/window_cairo_demo.h
index ab2b69a..32703a6 100644
--- a/libc3/window/cairo/demo/window_cairo_demo.h
+++ b/libc3/window/cairo/demo/window_cairo_demo.h
@@ -24,7 +24,7 @@ bool window_cairo_demo_button (s_window_cairo *window, u8 button,
                                sw x, sw y);
 bool window_cairo_demo_key (s_window_cairo *window, uw keysym);
 bool window_cairo_demo_load (s_window_cairo *window);
-bool window_cairo_demo_render (s_window_cairo *window, cairo_t *cr);
+bool window_cairo_demo_render (s_window_cairo *window);
 bool window_cairo_demo_resize (s_window_cairo *window, uw w, uw h);
 void window_cairo_demo_unload (s_window_cairo *window);
 
diff --git a/libc3/window/cairo/types.h b/libc3/window/cairo/types.h
index f7647fe..7893512 100644
--- a/libc3/window/cairo/types.h
+++ b/libc3/window/cairo/types.h
@@ -47,20 +47,12 @@ typedef bool (*f_window_cairo_motion) (s_window_cairo *window, sw x,
                                        sw y);
 
 /* return false to break event loop */
-typedef bool (*f_window_cairo_render) (s_window_cairo *window,
-                                       cairo_t *cr);
+typedef bool (*f_window_cairo_render) (s_window_cairo *window);
 
 /* return false to break event loop */
 typedef bool (*f_window_cairo_resize) (s_window_cairo *window,
                                        uw w, uw h);
 
-typedef bool (*f_window_cairo_sequence_load) (s_sequence *seq,
-                                              s_window_cairo *window);
-
-typedef bool (*f_window_cairo_sequence_render) (s_sequence *seq,
-                                                s_window_cairo *window,
-                                                cairo_t *cr);
-
 typedef void (*f_window_cairo_unload) (s_window_cairo *window);
 
 struct cairo_font {
@@ -111,6 +103,7 @@ struct window_cairo {
   f_window_cairo_render render;
   cairo_t              *cr;
   f_window_cairo_resize resize;
+  s_sequence           *seq;
   s_sequence           *sequence;
   uw                    sequence_count;
   uw                    sequence_pos;
diff --git a/libc3/window/cairo/window_cairo.c b/libc3/window/cairo/window_cairo.c
index 7d4728d..da4abbd 100644
--- a/libc3/window/cairo/window_cairo.c
+++ b/libc3/window/cairo/window_cairo.c
@@ -92,9 +92,11 @@ bool window_cairo_motion_default (s_window_cairo *window, sw x, sw y)
   return true;
 }
 
-bool window_cairo_render_default (s_window_cairo *window, cairo_t *cr)
+bool window_cairo_render_default (s_window_cairo *window)
 {
+  cairo_t *cr;
   assert(window);
+  cr = window->cr;
   assert(cr);
   cairo_set_source_rgb(cr, 1, 1, 1);
   cairo_rectangle(cr, 0, 0, window->w, window->h);
@@ -112,21 +114,3 @@ bool window_cairo_resize_default (s_window_cairo *window, uw w, uw h)
   printf("window_cairo_resize_default: %lu x %lu\n", w, h);
   return true;
 }
-
-s_sequence * window_cairo_sequence_init
-(s_sequence *seq, f64 duration, const s8 *title,
- f_window_cairo_sequence_load load,
- f_window_cairo_sequence_render render)
-{
-  s_sequence tmp = {0};
-  assert(seq);
-  tmp.dt = 0.0;
-  tmp.t = 0.0;
-  tmp.duration = duration;
-  tmp.title = title;
-  tmp.load = (f_sequence_load) load;
-  tmp.render = (f_sequence_render) render;
-  tag_init_void(&tmp.tag);
-  *seq = tmp;
-  return seq;
-}
diff --git a/libc3/window/cairo/window_cairo.h b/libc3/window/cairo/window_cairo.h
index be868c2..678b198 100644
--- a/libc3/window/cairo/window_cairo.h
+++ b/libc3/window/cairo/window_cairo.h
@@ -29,20 +29,13 @@ s_window_cairo * window_cairo_init (s_window_cairo *window,
                                     uw sequence_count);
 bool             window_cairo_run (s_window_cairo *window);
 
-/* Stack-allocation compatible functions, call sequence_clean
-   after use. */
-s_sequence *     window_cairo_sequence_init
-(s_sequence *sequence, f64 duration, const s8 *title,
- f_window_cairo_sequence_load load,
- f_window_cairo_sequence_render render);
-
 /* Callbacks. */
 bool window_cairo_button_default (s_window_cairo *window, u8 button,
                                   sw x, sw y);
 bool window_cairo_key_default (s_window_cairo *window, uw keysym);
 bool window_cairo_load_default (s_window_cairo *window);
 bool window_cairo_motion_default (s_window_cairo *window, sw x, sw y);
-bool window_cairo_render_default (s_window_cairo *window, cairo_t *cr);
+bool window_cairo_render_default (s_window_cairo *window);
 bool window_cairo_resize_default (s_window_cairo *window, uw w, uw h);
 
 #endif /* LIBC3_WINDOW_CAIRO_H */
diff --git a/libc3/window/cairo/xcb/window_cairo_xcb.c b/libc3/window/cairo/xcb/window_cairo_xcb.c
index 111b940..7867305 100644
--- a/libc3/window/cairo/xcb/window_cairo_xcb.c
+++ b/libc3/window/cairo/xcb/window_cairo_xcb.c
@@ -47,7 +47,7 @@ bool window_cairo_xcb_event (s_window_cairo *window,
       goto ko;
     break;
   case XCB_EXPOSE:
-    if (! window->render(window, window->cr))
+    if (! window->render(window))
       goto ko;
     xcb_gcontext_t gc = xcb_generate_id(conn);
     u32 gc_mask = XCB_GC_GRAPHICS_EXPOSURES;
diff --git a/libc3/window/sdl2/demo/bg_rect.c b/libc3/window/sdl2/demo/bg_rect.c
index dacfce0..a48df2f 100644
--- a/libc3/window/sdl2/demo/bg_rect.c
+++ b/libc3/window/sdl2/demo/bg_rect.c
@@ -15,18 +15,14 @@
 #include "../types.h"
 #include "bg_rect.h"
 
-bool bg_rect_load (s_sequence *seq, s_window_sdl2 *window)
+bool bg_rect_load (s_sequence *seq)
 {
   (void) seq;
-  (void) window;
   return true;
 }
 
-bool bg_rect_render (s_sequence *seq, s_window_sdl2 *window,
-                     SDL_GLContext context)
+bool bg_rect_render (s_sequence *seq)
 {
-  (void) context;
-  (void) window;
 #define BG_RECT_COLOR_MAX 8
   const s_rgb color[BG_RECT_COLOR_MAX] = {
     {0, 0, 0},
@@ -57,3 +53,9 @@ bool bg_rect_render (s_sequence *seq, s_window_sdl2 *window,
   assert(glGetError() == GL_NO_ERROR);
   return true;
 }
+
+bool bg_rect_unload (s_sequence *seq)
+{
+  (void) seq;
+  return true;
+}
diff --git a/libc3/window/sdl2/demo/bg_rect.h b/libc3/window/sdl2/demo/bg_rect.h
index 6bc4a8b..74b604b 100644
--- a/libc3/window/sdl2/demo/bg_rect.h
+++ b/libc3/window/sdl2/demo/bg_rect.h
@@ -15,8 +15,8 @@
 
 #include "../types.h"
 
-bool bg_rect_load (s_sequence *seq, s_window_sdl2 *window);
-bool bg_rect_render (s_sequence *seq, s_window_sdl2 *window,
-                     SDL_GLContext context);
+bool bg_rect_load (s_sequence *seq);
+bool bg_rect_render (s_sequence *seq);
+bool bg_rect_unload (s_sequence *seq);
 
 #endif /* BG_RECT_H */
diff --git a/libc3/window/sdl2/demo/earth.c b/libc3/window/sdl2/demo/earth.c
index 79171b4..891e4d4 100644
--- a/libc3/window/sdl2/demo/earth.c
+++ b/libc3/window/sdl2/demo/earth.c
@@ -24,13 +24,15 @@
 
 s_gl_sprite g_sprite_earth = {0};
 
-bool earth_load (s_sequence *seq,
-                 s_window_sdl2 *window)
+bool earth_load (s_sequence *seq)
 {
   s_map *map;
   s_gl_camera *camera;
   s_gl_sphere *sphere;
-  (void) window;
+  s_window_sdl2 *window;
+  assert(seq);
+  window = seq->window;
+  assert(window);
   camera = gl_camera_new(window->w, window->h);
   if (! camera)
     return false;
@@ -50,17 +52,17 @@ bool earth_load (s_sequence *seq,
   return true;
 }
 
-bool earth_render (s_sequence *seq, s_window_sdl2 *window,
-                   void *context)
+bool earth_render (s_sequence *seq)
 {
   s_gl_camera *camera;
   f64         *camera_rot_x_speed;
   s_map *map;
   s_gl_sphere *sphere;
   f64 sphere_radius;
+  s_window_sdl2 *window;
   assert(seq);
+  window = seq->window;
   assert(window);
-  (void) context;
   if (! seq || seq->tag.type != TAG_MAP ||
       seq->tag.data.map.count != 3) {
     err_puts("earth_render: invalid seq->tag");
@@ -132,3 +134,9 @@ bool earth_render (s_sequence *seq, s_window_sdl2 *window,
   glDisable(GL_LIGHTING);
   return true;
 }
+
+bool earth_unload (s_sequence *seq)
+{
+  (void) seq;
+  return true;
+}
diff --git a/libc3/window/sdl2/demo/earth.h b/libc3/window/sdl2/demo/earth.h
index 0bf6ac4..5f972e3 100644
--- a/libc3/window/sdl2/demo/earth.h
+++ b/libc3/window/sdl2/demo/earth.h
@@ -19,8 +19,8 @@
 extern s_gl_sprite g_sprite_earth;
 extern s_gl_sprite g_sprite_earth_night;
 
-bool earth_load (s_sequence *seq, s_window_sdl2 *window);
-bool earth_render (s_sequence *seq, s_window_sdl2 *window,
-                   void *context);
+bool earth_load (s_sequence *seq);
+bool earth_render (s_sequence *seq);
+bool earth_unload (s_sequence *seq);
 
 #endif /* EARTH_H */
diff --git a/libc3/window/sdl2/demo/flies.c b/libc3/window/sdl2/demo/flies.c
index 8c1db4d..3176666 100644
--- a/libc3/window/sdl2/demo/flies.c
+++ b/libc3/window/sdl2/demo/flies.c
@@ -54,15 +54,13 @@ static void fly_init (s_map *map)
   (*in)++;
 }
 
-bool flies_load (s_sequence *seq,
-                 s_window_sdl2 *window)
+bool flies_load (s_sequence *seq)
 {
   uw address[2];
   s_array *board;
   uw i;
   uw j;
   s_map *map;
-  (void) window;
   tag_map(&seq->tag, 4);
   map = &seq->tag.data.map;
   tag_init_sym_1( map->key  + 0, "board");
@@ -131,8 +129,7 @@ bool flies_load (s_sequence *seq,
   return true;
 }
 
-bool flies_render (s_sequence *seq, s_window_sdl2 *window,
-                   void *context)
+bool flies_render (s_sequence *seq)
 {
   s8 a[BOARD_SIZE];
   uw address[2];
@@ -161,12 +158,10 @@ bool flies_render (s_sequence *seq, s_window_sdl2 *window,
   uw random_bits = 0;
   f64 x;
   f64 y;
-  (void) context;
-  glMatrixMode(GL_PROJECTION);
-  glLoadIdentity();
-  glOrtho(0, window->w, 0, window->h, -1, 1);
-  glMatrixMode(GL_MODELVIEW);
-  glLoadIdentity();
+  s_window_sdl2 *window;
+  assert(seq);
+  window = seq->window;
+  assert(window);
   glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
   glClear(GL_COLOR_BUFFER_BIT);
   /* io_inspect(&seq->tag); */
@@ -323,3 +318,9 @@ bool flies_render (s_sequence *seq, s_window_sdl2 *window,
   } glPopMatrix();
   return true;
 }
+
+bool flies_unload (s_sequence *seq)
+{
+  (void) seq;
+  return true;
+}
diff --git a/libc3/window/sdl2/demo/flies.h b/libc3/window/sdl2/demo/flies.h
index 1de8081..d365b14 100644
--- a/libc3/window/sdl2/demo/flies.h
+++ b/libc3/window/sdl2/demo/flies.h
@@ -20,8 +20,8 @@ extern s_gl_font   g_font_flies;
 extern s_gl_sprite g_sprite_dead_fly;
 extern s_gl_sprite g_sprite_fly;
 
-bool flies_load (s_sequence *seq, s_window_sdl2 *window);
-bool flies_render (s_sequence *seq, s_window_sdl2 *window,
-                   void *context);
+bool flies_load (s_sequence *seq);
+bool flies_render (s_sequence *seq);
+bool flies_unload (s_sequence *seq);
 
 #endif /* FLIES_H */
diff --git a/libc3/window/sdl2/demo/lightspeed.c b/libc3/window/sdl2/demo/lightspeed.c
index 1e9cffc..e9ad16e 100644
--- a/libc3/window/sdl2/demo/lightspeed.c
+++ b/libc3/window/sdl2/demo/lightspeed.c
@@ -61,11 +61,14 @@ static void star_render (s_tag *star, s_sequence *seq, s_gl_vertex *v)
     star_init(star);
 }
 
-bool lightspeed_load (s_sequence *seq, s_window_sdl2 *window)
+bool lightspeed_load (s_sequence *seq)
 {
   uw i;
   uw star_count;
-  (void) window;
+  s_window_sdl2 *window;
+  assert(seq);
+  window = seq->window;
+  assert(window);
   tag_tuple(&seq->tag, LIGHTSPEED_STAR_MAX);
   star_count = window->w * window->h * LIGHTSPEED_STAR_PROBABILITY;
   if (star_count > LIGHTSPEED_STAR_MAX)
@@ -78,14 +81,15 @@ bool lightspeed_load (s_sequence *seq, s_window_sdl2 *window)
   return true;
 }
 
-bool lightspeed_render (s_sequence *seq, s_window_sdl2 *window,
-                        void *context)
+bool lightspeed_render (s_sequence *seq)
 {
   uw i;
   uw star_count;
   s_gl_vertex *v;
-  (void) window;
-  (void) context;
+  s_window_sdl2 *window;
+  assert(seq);
+  window = seq->window;
+  assert(window);
   gl_matrix_4d_init_identity(&g_ortho.model_matrix);
   /*
   gl_matrix_4d_scale(&g_ortho.model_matrix, window->w / 2.0,
@@ -126,3 +130,9 @@ bool lightspeed_render (s_sequence *seq, s_window_sdl2 *window,
   assert(glGetError() == GL_NO_ERROR);
   return true;
 }
+
+bool lightspeed_unload (s_sequence *seq)
+{
+  (void) seq;
+  return true;
+}
diff --git a/libc3/window/sdl2/demo/lightspeed.h b/libc3/window/sdl2/demo/lightspeed.h
index 6a889ad..c099ed2 100644
--- a/libc3/window/sdl2/demo/lightspeed.h
+++ b/libc3/window/sdl2/demo/lightspeed.h
@@ -20,8 +20,8 @@
 
 extern s_gl_lines g_lines_stars;
 
-bool lightspeed_load (s_sequence *seq, s_window_sdl2 *window);
-bool lightspeed_render (s_sequence *seq, s_window_sdl2 *window,
-                        void *context);
+bool lightspeed_load (s_sequence *seq);
+bool lightspeed_render (s_sequence *seq);
+bool lightspeed_unload (s_sequence *seq);
 
 #endif /* LIGHTSPEED_H */
diff --git a/libc3/window/sdl2/demo/toasters.c b/libc3/window/sdl2/demo/toasters.c
index 0491655..21057d2 100644
--- a/libc3/window/sdl2/demo/toasters.c
+++ b/libc3/window/sdl2/demo/toasters.c
@@ -101,11 +101,9 @@ static void toaster_render (s_tag *toaster, s_window_sdl2 *window,
   }
 }
 
-bool toasters_load (s_sequence *seq,
-                    s_window_sdl2 *window)
+bool toasters_load (s_sequence *seq)
 {
   s_map *map;
-  (void) window;
   tag_map(&seq->tag, 2);
   map = &seq->tag.data.map;
   tag_init_sym_1( map->key + 0, "toasters");
@@ -115,12 +113,14 @@ bool toasters_load (s_sequence *seq,
   return true;
 }
 
-bool toasters_render (s_sequence *seq, s_window_sdl2 *window,
-                      void *context)
+bool toasters_render (s_sequence *seq)
 {
   s_list **toasters;
   s_list **toasts;
-  (void) context;
+  s_window_sdl2 *window;
+  assert(seq);
+  window = seq->window;
+  assert(window);
   glClearColor(0.7f, 0.95f, 1.0f, 1.0f);
   glClear(GL_COLOR_BUFFER_BIT);
   glPushMatrix();
@@ -242,3 +242,9 @@ bool toasters_render_toasters (s_list **toasters, s_window_sdl2 *window,
   }
   return true;
 }
+
+bool toasters_unload (s_sequence *seq)
+{
+  (void) seq;
+  return true;
+}
diff --git a/libc3/window/sdl2/demo/toasters.h b/libc3/window/sdl2/demo/toasters.h
index e6c9c15..ea4e3a3 100644
--- a/libc3/window/sdl2/demo/toasters.h
+++ b/libc3/window/sdl2/demo/toasters.h
@@ -18,8 +18,8 @@
 extern s_gl_sprite g_sprite_toast;
 extern s_gl_sprite g_sprite_toaster;
 
-bool toasters_load (s_sequence *seq, s_window_sdl2 *window);
-bool toasters_render (s_sequence *seq, s_window_sdl2 *window,
-                      void *context);
+bool toasters_load (s_sequence *seq);
+bool toasters_render (s_sequence *seq);
+bool toasters_unload (s_sequence *seq);
 
 #endif /* TOASTERS_H */
diff --git a/libc3/window/sdl2/demo/window_sdl2_demo.c b/libc3/window/sdl2/demo/window_sdl2_demo.c
index cd75c40..07814eb 100644
--- a/libc3/window/sdl2/demo/window_sdl2_demo.c
+++ b/libc3/window/sdl2/demo/window_sdl2_demo.c
@@ -42,8 +42,7 @@ static bool window_sdl2_demo_button (s_window_sdl2 *window, u8 button,
 static bool window_sdl2_demo_key (s_window_sdl2 *window,
                                   SDL_Keysym *keysym);
 static bool window_sdl2_demo_load (s_window_sdl2 *window);
-static bool window_sdl2_demo_render (s_window_sdl2 *window,
-                                     void *context);
+static bool window_sdl2_demo_render (s_window_sdl2 *window);
 static bool window_sdl2_demo_resize (s_window_sdl2 *window,
                                      uw w, uw h);
 static void window_sdl2_demo_unload (s_window_sdl2 *window);
@@ -160,24 +159,23 @@ bool window_sdl2_demo_load (s_window_sdl2 *window)
     return false;
   if (! gl_text_init_1(&g_text_fps, &g_font_courier_new, "0.00"))
     return false;
-  window_sdl2_sequence_init(window->sequence, 8.0,
-                            "01. Background rectangles",
-                            bg_rect_load, bg_rect_render);
+  sequence_init(window->sequence, 8.0, "01. Background rectangles",
+                bg_rect_load, bg_rect_render, bg_rect_unload, window);
   if (! gl_lines_init(&g_lines_stars) ||
       ! gl_lines_allocate(&g_lines_stars, LIGHTSPEED_STAR_MAX))
     return false;
-  window_sdl2_sequence_init(window->sequence + 1, 20.0,
-                            "02. Lightspeed",
-                            lightspeed_load, lightspeed_render);
+  sequence_init(window->sequence + 1, 20.0, "02. Lightspeed",
+                lightspeed_load, lightspeed_render, lightspeed_unload,
+                window);
   if (! gl_sprite_init(&g_sprite_toaster, "img/flaps.256.png",
                        4, 1, 4))
     return false;
   if (! gl_sprite_init(&g_sprite_toast, "img/toast.128.png",
                        1, 1, 1))
     return false;
-  window_sdl2_sequence_init(window->sequence + 2, 60.0,
-                            "03. Toasters",
-                            toasters_load, toasters_render);
+  sequence_init(window->sequence + 2, 60.0, "03. Toasters",
+                toasters_load, toasters_render, toasters_unload,
+                window);
   if (! gl_font_init(&g_font_flies,
                      "fonts/Courier New/Courier New.ttf"))
     return false;
@@ -187,9 +185,8 @@ bool window_sdl2_demo_load (s_window_sdl2 *window)
   if (! gl_sprite_init(&g_sprite_dead_fly, "img/fly-dead.png",
                        1, 1, 1))
     return false;
-  window_sdl2_sequence_init(window->sequence + 3, 60.0,
-                            "04. Flies",
-                            flies_load, flies_render);
+  sequence_init(window->sequence + 3, 60.0, "04. Flies",
+                flies_load, flies_render, flies_unload, window);
   if (! gl_sprite_init(&g_sprite_earth, "img/earth.png",
                        1, 1, 1))
     return false;
@@ -197,9 +194,8 @@ bool window_sdl2_demo_load (s_window_sdl2 *window)
   assert(glGetError() == GL_NO_ERROR);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
   assert(glGetError() == GL_NO_ERROR);
-  window_sdl2_sequence_init(window->sequence + 4, 120.0,
-                            "05. Earth",
-                            earth_load, earth_render);
+  sequence_init(window->sequence + 4, 120.0, "05. Earth",
+                earth_load, earth_render, earth_unload, window);
   assert(glGetError() == GL_NO_ERROR);
   window_set_sequence_pos((s_window *) window, 0);
   assert(glGetError() == GL_NO_ERROR);
@@ -253,21 +249,21 @@ static void render_text (s_gl_text *text, f64 x, f64 y)
   assert(glGetError() == GL_NO_ERROR);
 }
 
-bool window_sdl2_demo_render (s_window_sdl2 *window, void *context)
+bool window_sdl2_demo_render (s_window_sdl2 *window)
 {
   s_sequence *seq;
   assert(window);
   assert(glGetError() == GL_NO_ERROR);
   if (! window_animate((s_window *) window))
     return false;
-  seq = window->sequence + window->sequence_pos;
+  seq = window->seq;
   gl_matrix_4d_init_identity(&g_ortho.model_matrix);
   gl_ortho_render(&g_ortho);
   glEnable(GL_BLEND);
   glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,
                       GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
   assert(glGetError() == GL_NO_ERROR);
-  if (! seq->render(seq, window, context))
+  if (! seq->render(seq))
     return false;
   assert(glGetError() == GL_NO_ERROR);
   /* 2D */
diff --git a/libc3/window/sdl2/types.h b/libc3/window/sdl2/types.h
index a4e3630..0f8e9de 100644
--- a/libc3/window/sdl2/types.h
+++ b/libc3/window/sdl2/types.h
@@ -63,8 +63,7 @@ typedef bool (*f_window_sdl2_motion) (s_window_sdl2 *window, sw x,
                                       sw y);
 
 /* return false to break event loop */
-typedef bool (*f_window_sdl2_render) (s_window_sdl2 *window,
-                                      void *context);
+typedef bool (*f_window_sdl2_render) (s_window_sdl2 *window);
 
 /* return false to break event loop */
 typedef bool (*f_window_sdl2_resize) (s_window_sdl2 *window,
@@ -187,6 +186,7 @@ struct window_sdl2 {
   f_window_sdl2_render render;
   SDL_Window          *sdl_window;
   f_window_sdl2_resize resize;
+  s_sequence          *seq;
   s_sequence          *sequence;
   uw                   sequence_count;
   uw                   sequence_pos;
diff --git a/libc3/window/sdl2/window_sdl2.c b/libc3/window/sdl2/window_sdl2.c
index f07c390..48fa5db 100644
--- a/libc3/window/sdl2/window_sdl2.c
+++ b/libc3/window/sdl2/window_sdl2.c
@@ -68,12 +68,10 @@ bool window_sdl2_default_motion_cb (s_window_sdl2 *window, sw x, sw y)
   return true;
 }
 
-bool window_sdl2_default_render_cb (s_window_sdl2 *window,
-                                    void *sdl_window)
+bool window_sdl2_default_render_cb (s_window_sdl2 *window)
 {
-  (void) window;
-  (void) sdl_window;
   assert(window);
+  (void) window;
   printf("window_sdl2_default_render_cb\n");
   return true;
 }
@@ -227,14 +225,14 @@ bool window_sdl2_run (s_window_sdl2 *window)
         break;
       case SDL_KEYDOWN:
         if (! window->key(window, &sdl_event.key.keysym)) {
-          err_puts("window_sdl2_run: window->key -> false");
+          err_puts("window_sdl2_run: window->key => false");
           quit = 1;
         }
         break;
       case SDL_MOUSEBUTTONDOWN:
         if (! window->button(window, sdl_event.button.button,
                              sdl_event.button.x, sdl_event.button.y)) {
-          err_puts("window_sdl2_run: window->button -> false");
+          err_puts("window_sdl2_run: window->button => false");
           quit = 1;
         }
         break;
@@ -243,7 +241,7 @@ bool window_sdl2_run (s_window_sdl2 *window)
         //int relativeY = sdl_event.motion.yrel;
         if (! window->motion(window, sdl_event.motion.x,
                              sdl_event.motion.y)) {
-          err_puts("window_sdl2_run: window->motion -> false");
+          err_puts("window_sdl2_run: window->motion => false");
           quit = 1;
         }
         break;
@@ -251,7 +249,7 @@ bool window_sdl2_run (s_window_sdl2 *window)
         if (sdl_event.window.event == SDL_WINDOWEVENT_RESIZED) {
           if (! window->resize(window, sdl_event.window.data1,
                                sdl_event.window.data2)) {
-            err_puts("window_sdl2_run: window->resize -> false");
+            err_puts("window_sdl2_run: window->resize => false");
             quit = 1;
           }
           assert(glGetError() == GL_NO_ERROR);
@@ -269,8 +267,8 @@ bool window_sdl2_run (s_window_sdl2 *window)
     }
     assert(glGetError() == GL_NO_ERROR);
     //glDrawBuffer(GL_BACK);
-    if (! window->render(window, NULL)) {
-      err_puts("window_sdl2_run: window->render -> false");
+    if (! window->render(window)) {
+      err_puts("window_sdl2_run: window->render => false");
       quit = 1;
     }
     SDL_GL_SwapWindow(sdl_window);
@@ -283,19 +281,3 @@ bool window_sdl2_run (s_window_sdl2 *window)
   SDL_DestroyWindow(sdl_window);
   return false;
 }
-
-s_sequence * window_sdl2_sequence_init
-(s_sequence *seq, f64 duration, const s8 *title,
- f_window_sdl2_sequence_load load,
- f_window_sdl2_sequence_render render)
-{
-  assert(seq);
-  seq->t = 0.0;
-  seq->duration = duration;
-  seq->frame = 0;
-  seq->title = title;
-  seq->load = (f_sequence_load) load;
-  seq->render = (f_sequence_render) render;
-  tag_init_void(&seq->tag);
-  return seq;
-}
diff --git a/libc3/window/sdl2/window_sdl2.h b/libc3/window/sdl2/window_sdl2.h
index b5f1503..e1041f3 100644
--- a/libc3/window/sdl2/window_sdl2.h
+++ b/libc3/window/sdl2/window_sdl2.h
@@ -26,12 +26,6 @@ s_window_sdl2 * window_sdl2_init (s_window_sdl2 *window,
 /* Operators. */
 bool             window_sdl2_run (s_window_sdl2 *window);
 
-/* Sequences. */
-s_sequence *     window_sdl2_sequence_init
-(s_sequence *sequence, f64 duration, const s8 *title,
- f_window_sdl2_sequence_load load,
- f_window_sdl2_sequence_render render);
-
 /* Callbacks. */
 bool window_sdl2_default_button_cb (s_window_sdl2 *window, u8 button,
                                     sw x, sw y);
@@ -39,8 +33,7 @@ bool window_sdl2_default_key_cb (s_window_sdl2 *window,
                                  SDL_Keysym *keysym);
 bool window_sdl2_default_load_cb (s_window_sdl2 *window);
 bool window_sdl2_default_motion_cb (s_window_sdl2 *window, sw x, sw y);
-bool window_sdl2_default_render_cb (s_window_sdl2 *window,
-                                 void *context);
+bool window_sdl2_default_render_cb (s_window_sdl2 *window);
 bool window_sdl2_default_resize_cb (s_window_sdl2 *window, uw w, uw h);
 void window_sdl2_default_unload_cb (s_window_sdl2 *window);
 
diff --git a/libc3/window/types.h b/libc3/window/types.h
index c14b999..91c4ab3 100644
--- a/libc3/window/types.h
+++ b/libc3/window/types.h
@@ -36,8 +36,7 @@ typedef bool (*f_window_load) (s_window *window);
 typedef bool (*f_window_motion) (s_window *window, sw x, sw y);
 
 /* return false to break event loop */
-typedef bool (*f_window_render) (s_window *window,
-                                 void *render_context);
+typedef bool (*f_window_render) (s_window *window);
 
 /* return false to break event loop */
 typedef bool (*f_window_resize) (s_window *window,
@@ -61,6 +60,7 @@ struct window {
   f_window_render render;
   void           *context;
   f_window_resize resize;
+  s_sequence     *seq;
   s_sequence     *sequence;
   uw              sequence_count;
   uw              sequence_pos;
diff --git a/libc3/window/window.c b/libc3/window/window.c
index b4550dd..95b41cc 100644
--- a/libc3/window/window.c
+++ b/libc3/window/window.c
@@ -92,8 +92,12 @@ bool window_set_sequence_pos (s_window *window, uw sequence_pos)
     return false;
   }
   window->sequence_pos = sequence_pos;
+  if (window->seq)
+    if (! window->seq->unload(window->seq))
+      return false;
+  window->seq = seq;
   io_puts(seq->title);
-  if (! seq->load(seq, window))
+  if (! seq->load(seq))
     return false;
   return true;
 }