Compare commits
831
Commits
1dfde00317
..
ac2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b639bc6c4f | ||
|
|
7ee04c78cd | ||
|
|
7b58addf7e | ||
|
|
ae52be591b | ||
|
|
93ab7690ba | ||
|
|
68c3f88181 | ||
|
|
830864aa8a | ||
|
|
5f34cb34b2 | ||
|
|
b9d2fe60fd | ||
|
|
06bc4fcd55 | ||
|
|
42cb84b610 | ||
|
|
f8607d114c | ||
|
|
56230dd340 | ||
|
|
df9fdf26c8 | ||
|
|
8f8fa8f8d1 | ||
|
|
07f98c119a | ||
|
|
d49194fc4d | ||
|
|
e61914bad4 | ||
|
|
015d90519f | ||
|
|
7b4f0abfb8 | ||
|
|
0667a44e14 | ||
|
|
0852b8463b | ||
|
|
1436fda858 | ||
|
|
0826908068 | ||
|
|
7ceb9e571d | ||
|
|
38c2f6b6f9 | ||
|
|
b9f06fef7a | ||
|
|
373f1c1010 | ||
|
|
e80d693d85 | ||
|
|
ef60ddf6a8 | ||
|
|
de0ff2e263 | ||
|
|
13a435e9c1 | ||
|
|
725338cd5a | ||
|
|
acd14f46a8 | ||
|
|
ef78f023ed | ||
|
|
85b6109792 | ||
|
|
6c5738c863 | ||
|
|
1174e471f6 | ||
|
|
a618ff46fe | ||
|
|
1fa5cd316e | ||
|
|
11e5d37563 | ||
|
|
9f86c20129 | ||
|
|
8fb1c9fb42 | ||
|
|
5f08337726 | ||
|
|
0bc80d5df3 | ||
|
|
2432443ea6 | ||
|
|
fa138971e7 | ||
|
|
d7982599d1 | ||
|
|
f16c80aa0f | ||
|
|
ef5adf8274 | ||
|
|
2ffc65b1b1 | ||
|
|
d4a17bd98d | ||
|
|
dcf5f434c5 | ||
|
|
78cd973a33 | ||
|
|
ca02ee0352 | ||
|
|
fbaa54145e | ||
|
|
28754ffbf2 | ||
|
|
470c0eba7a | ||
|
|
7098dcec43 | ||
|
|
07137f57af | ||
|
|
8b7491a3d3 | ||
|
|
8cfa8ddfeb | ||
|
|
ef284a15a1 | ||
|
|
3723921573 | ||
|
|
195399635e | ||
|
|
46e2a924d3 | ||
|
|
b693ea4102 | ||
|
|
a73f55beb0 | ||
|
|
0bd2491ab7 | ||
|
|
860c797c9c | ||
|
|
38c5080f9f | ||
|
|
fae191d8fe | ||
|
|
d83a953e2d | ||
|
|
2dcf0d0f0d | ||
|
|
6dee37d8c1 | ||
|
|
3bad03afb3 | ||
|
|
6a6d8448f7 | ||
|
|
189babd2cf | ||
|
|
988a0f2294 | ||
|
|
85bf455731 | ||
|
|
589e4224f3 | ||
|
|
bd7fa154b4 | ||
|
|
a292f1992b | ||
|
|
88ddf429b7 | ||
|
|
7a1f6662df | ||
|
|
afc68bccc6 | ||
|
|
b4cdc4a64f | ||
|
|
3ad5afb81c | ||
|
|
bed3f20118 | ||
|
|
de67315178 | ||
|
|
8d5c0c7cad | ||
|
|
a8271e01bd | ||
|
|
900b3f8558 | ||
|
|
fdc4e056f9 | ||
|
|
7b98e40ccf | ||
|
|
01d89cf22c | ||
|
|
503a3c799a | ||
|
|
0b21388844 | ||
|
|
117bdf0c00 | ||
|
|
172dc5d37b | ||
|
|
874c6258ab | ||
|
|
a2d0a12c1a | ||
|
|
38b24e1c3d | ||
|
|
5ecbbe296b | ||
|
|
9d7a769d8f | ||
|
|
9b75e5ed83 | ||
|
|
a9ab8dc1d8 | ||
|
|
a34831aa02 | ||
|
|
84ebaa0751 | ||
|
|
55352805ee | ||
|
|
c0a3f2e16a | ||
|
|
28ff331a28 | ||
|
|
f9a53ec719 | ||
|
|
6a403e6caf | ||
|
|
a6f449bb93 | ||
|
|
0614bfc446 | ||
|
|
bb020c36c1 | ||
|
|
f17b0bfcfb | ||
|
|
2a85c9503f | ||
|
|
182428d6d6 | ||
|
|
8181a28557 | ||
|
|
88aed11d98 | ||
|
|
67010592b8 | ||
|
|
dd22d6424a | ||
|
|
e53775b97f | ||
|
|
d326f6c1ac | ||
|
|
556111c00a | ||
|
|
ebc7110e63 | ||
|
|
af49d1c8bb | ||
|
|
c71dbb1dfc | ||
|
|
432aa3c4fa | ||
|
|
5c93503710 | ||
|
|
0d58050def | ||
|
|
27bb78209a | ||
|
|
3201f5a25b | ||
|
|
d3df8a96d3 | ||
|
|
7ec5266b1f | ||
|
|
e74ff7c805 | ||
|
|
1d5f3c2959 | ||
|
|
469034b223 | ||
|
|
f3a394de21 | ||
|
|
cb23d4c11b | ||
|
|
bbf5b706f0 | ||
|
|
1e890f6d86 | ||
|
|
2fe543a603 | ||
|
|
24631990bd | ||
|
|
0c8c0d24ba | ||
|
|
454b8a91ba | ||
|
|
a74f1568e9 | ||
|
|
3f35d56be4 | ||
|
|
722fe2ccfb | ||
|
|
d85737cc08 | ||
|
|
ce29435831 | ||
|
|
d3715eece8 | ||
|
|
335d79f2c4 | ||
|
|
a9e33660cb | ||
|
|
8faf881399 | ||
|
|
c4969a36cc | ||
|
|
26fcaf6e75 | ||
|
|
a162002af2 | ||
|
|
9810fd51ab | ||
|
|
857c6b3d47 | ||
|
|
e1498f538d | ||
|
|
aa246eff94 | ||
|
|
5be21a21d5 | ||
|
|
8131bcd4d4 | ||
|
|
4ba11e3363 | ||
|
|
acf2be3f66 | ||
|
|
f5df0195e2 | ||
|
|
d26995b48d | ||
|
|
617f8120ae | ||
|
|
06c517c9aa | ||
|
|
593ed6408c | ||
|
|
fb7d3ed122 | ||
|
|
19b88ec858 | ||
|
|
160e65be7f | ||
|
|
079b0d2cf6 | ||
|
|
78f1310f41 | ||
|
|
eb1974c113 | ||
|
|
551409a023 | ||
|
|
a11e14daac | ||
|
|
7441e15e76 | ||
|
|
46506228a6 | ||
|
|
17c49c74cf | ||
|
|
3f8024d4db | ||
|
|
8675e44d28 | ||
|
|
1301d9a718 | ||
|
|
da3db50ca8 | ||
|
|
2ca6780305 | ||
|
|
be68fe5a35 | ||
|
|
dc41c0e302 | ||
|
|
51388c90d5 | ||
|
|
f8c9d33df2 | ||
|
|
ed0420fdce | ||
|
|
47a6f396fa | ||
|
|
9edb2aa0c1 | ||
|
|
003b647d83 | ||
|
|
2849ff8844 | ||
|
|
9f3089742a | ||
|
|
b286a9bbcd | ||
|
|
6204e745ba | ||
|
|
bbe0e48d23 | ||
|
|
79054080c0 | ||
|
|
81024c4c09 | ||
|
|
9068d96130 | ||
|
|
6f47543720 | ||
|
|
5a08384ae1 | ||
|
|
45d8fda0e4 | ||
|
|
a9e664492f | ||
|
|
3c8b6cb2cc | ||
|
|
2b3abbe13b | ||
|
|
241a52b94a | ||
|
|
82c300b077 | ||
|
|
0f8b629e20 | ||
|
|
36f6ac65f2 | ||
|
|
a25871a849 | ||
|
|
57766a9104 | ||
|
|
3770ae1645 | ||
|
|
d73edb403f | ||
|
|
b14196ff0d | ||
|
|
88903fee94 | ||
|
|
1e8311fc04 | ||
|
|
2b78370cb8 | ||
|
|
8f78bba9e9 | ||
|
|
41a4be678e | ||
|
|
8b2b4b7c3d | ||
|
|
1f3a29f89d | ||
|
|
c4c93097cd | ||
|
|
eedb7769e6 | ||
|
|
98db62a4bc | ||
|
|
df48c8e500 | ||
|
|
db9cc0f4c6 | ||
|
|
a79ee429b4 | ||
|
|
6acfca6d48 | ||
|
|
1cd6f4cb72 | ||
|
|
3271e8c7d6 | ||
|
|
0bcde064af | ||
|
|
957980b3c5 | ||
|
|
03eb328d81 | ||
|
|
e1716a741f | ||
|
|
e24707c847 | ||
|
|
7c4b8c307f | ||
|
|
109318aeaf | ||
|
|
1f2657cea0 | ||
|
|
382c435bac | ||
|
|
130fe4ca5d | ||
|
|
31ba3fe127 | ||
|
|
f68b31158f | ||
|
|
653ca9a72d | ||
|
|
ba7857f4df | ||
|
|
23e617ea21 | ||
|
|
cdf5a5229c | ||
|
|
f841a35a53 | ||
|
|
efd31237be | ||
|
|
6502822583 | ||
|
|
a9e6f2b2a5 | ||
|
|
510a94b42c | ||
|
|
d805be47ce | ||
|
|
f9ea8e380a | ||
|
|
5cb05beb30 | ||
|
|
677768e6ab | ||
|
|
ed6c951783 | ||
|
|
54254348b8 | ||
|
|
782fd07a8d | ||
|
|
a8fd55cb38 | ||
|
|
d7f515575a | ||
|
|
bafbf2ec2f | ||
|
|
7415944e0a | ||
|
|
1ff990ff44 | ||
|
|
73e73d8772 | ||
|
|
6d876bb767 | ||
|
|
2be0fe9f06 | ||
|
|
e1fb082927 | ||
|
|
65ca5ae4c4 | ||
|
|
2cea43dc70 | ||
|
|
44a0700800 | ||
|
|
1613a378f1 | ||
|
|
deed98a27d | ||
|
|
9d0cb8fb46 | ||
|
|
d8fe0f6923 | ||
|
|
581dbc2b3c | ||
|
|
7301d2ad76 | ||
|
|
3232a14d1d | ||
|
|
84c1f88d42 | ||
|
|
3695b10e4b | ||
|
|
6da02b25fa | ||
|
|
3bc544fba1 | ||
|
|
368d370f49 | ||
|
|
bb29c0edef | ||
|
|
6edcf75a0c | ||
|
|
31cc186424 | ||
|
|
0e94c1fa6d | ||
|
|
6d9e2dd3e1 | ||
|
|
4a4adeb3c8 | ||
|
|
ff77f8cfa0 | ||
|
|
36db89c36e | ||
|
|
a9948142ad | ||
|
|
8d05510584 | ||
|
|
d373de7a29 | ||
|
|
1efa9a9f7b | ||
|
|
0fb3ba2f91 | ||
|
|
3b4c5b5153 | ||
|
|
9293aeeec8 | ||
|
|
03ae83b119 | ||
|
|
abd63cc6cf | ||
|
|
2e43aa2c44 | ||
|
|
3d984e13c2 | ||
|
|
010900fe21 | ||
|
|
ffed626447 | ||
|
|
61f69af35a | ||
|
|
bd248ee91c | ||
|
|
194255bffe | ||
|
|
52ee627079 | ||
|
|
bd4200e707 | ||
|
|
73e7d6c7f3 | ||
|
|
a41b0e916b | ||
|
|
19f2a2c616 | ||
|
|
998601f722 | ||
|
|
7c3386cf3e | ||
|
|
d161182997 | ||
|
|
1646dc2dbd | ||
|
|
b640295be2 | ||
|
|
b89ae2391b | ||
|
|
a0fad441d0 | ||
|
|
340084dac3 | ||
|
|
c78135aa09 | ||
|
|
d19f8bbd30 | ||
|
|
4205899f5a | ||
|
|
7dd3940770 | ||
|
|
00d94e3015 | ||
|
|
7bacb3ee2b | ||
|
|
8e49be5ac4 | ||
|
|
3b94598d2c | ||
|
|
bddc9af3b6 | ||
|
|
2451d73a7c | ||
|
|
1dd2efa182 | ||
|
|
acea610773 | ||
|
|
8f2f1fd496 | ||
|
|
39c775872a | ||
|
|
bdb3cbd109 | ||
|
|
ff84ce2b04 | ||
|
|
225f405592 | ||
|
|
715ecffa18 | ||
|
|
e51cdc8992 | ||
|
|
133685ea37 | ||
|
|
6aff98d555 | ||
|
|
acdc524284 | ||
|
|
1ee5ec7b43 | ||
|
|
46a5403511 | ||
|
|
87bfb92576 | ||
|
|
c7a3e5601c | ||
|
|
4009130f6e | ||
|
|
c91243f6e9 | ||
|
|
0e3871ac26 | ||
|
|
55baafec8a | ||
|
|
b5a66993ca | ||
|
|
0b570b5fd6 | ||
|
|
378227c377 | ||
|
|
650645eaff | ||
|
|
62c71f3fe6 | ||
|
|
041ec3d710 | ||
|
|
5f2d871bad | ||
|
|
a30b151e4d | ||
|
|
5a651d2d1f | ||
|
|
4b3826edd9 | ||
|
|
bae1ff3759 | ||
|
|
fd82486431 | ||
|
|
c9cd91cbd8 | ||
|
|
c8abd374fe | ||
|
|
2b9ee8f721 | ||
|
|
d02673e04a | ||
|
|
f0117b8e6e | ||
|
|
bb7c41c754 | ||
|
|
efa583c154 | ||
|
|
d16ea13c14 | ||
|
|
673d8e0a18 | ||
|
|
37cfdde1ee | ||
|
|
0778ffb57a | ||
|
|
42099f7241 | ||
|
|
c52e1d22b7 | ||
|
|
0d7b0aadd1 | ||
|
|
4cd3355ef1 | ||
|
|
98d70b96d1 | ||
|
|
64735bdf43 | ||
|
|
7b87347b77 | ||
|
|
b5b29d7061 | ||
|
|
9ec21f85a0 | ||
|
|
da1a5a3f1b | ||
|
|
0885da8d44 | ||
|
|
8af961c6d3 | ||
|
|
ef5febdde3 | ||
|
|
6d7fbd3926 | ||
|
|
2680d373d8 | ||
|
|
2b2ddb3cf2 | ||
|
|
85ff95296b | ||
|
|
314a2de41a | ||
|
|
26fafab47a | ||
|
|
e56ff20e2d | ||
|
|
55d44f229d | ||
|
|
1c5e50cc4d | ||
|
|
ea898da6c2 | ||
|
|
dbb7e9f53c | ||
|
|
cbb68a399d | ||
|
|
0e794f28b1 | ||
|
|
87d2d9123e | ||
|
|
6823a4ddb5 | ||
|
|
20a7c70081 | ||
|
|
9caa33b3bb | ||
|
|
2d7e61460a | ||
|
|
a4b7fb3f44 | ||
|
|
70056cf4ca | ||
|
|
5f4ab71ade | ||
|
|
f3adb3257b | ||
|
|
438edda7fd | ||
|
|
d5b0441e6f | ||
|
|
9ba0ceb000 | ||
|
|
9474a68995 | ||
|
|
09c35f0aa6 | ||
|
|
a2113442cb | ||
|
|
d91808487f | ||
|
|
933949cc19 | ||
|
|
407620387d | ||
|
|
98947dea26 | ||
|
|
ebff7af9b5 | ||
|
|
b23c4b83ae | ||
|
|
c0cff40628 | ||
|
|
97513e354c | ||
|
|
c277ae7aff | ||
|
|
e1835e6282 | ||
|
|
5ac21db997 | ||
|
|
ca0e9fc3b2 | ||
|
|
66ebcb1608 | ||
|
|
ff92a78dda | ||
|
|
7356286fe0 | ||
|
|
54e8e68f86 | ||
|
|
d21cd7f78b | ||
|
|
1d7516982a | ||
|
|
c77a11442c | ||
|
|
5bd43a4643 | ||
|
|
9b87dfa1a9 | ||
|
|
2e3173ea40 | ||
|
|
68eac7cf83 | ||
|
|
6709505630 | ||
|
|
af6e962a5d | ||
|
|
18e6bdabaa | ||
|
|
9743942eae | ||
|
|
23062137a8 | ||
|
|
46f7fb5ccd | ||
|
|
9c90c49a6b | ||
|
|
4517b63557 | ||
|
|
58c239f4b4 | ||
|
|
cc8845ba3e | ||
|
|
6b69ce2901 | ||
|
|
55300ed21c | ||
|
|
7346dd4339 | ||
|
|
2caf3b92ce | ||
|
|
af2cd72a1f | ||
|
|
3d455ec1f8 | ||
|
|
15982d7735 | ||
|
|
5ae3542bd9 | ||
|
|
b1b02ae24b | ||
|
|
f0964e2c92 | ||
|
|
e9661d2998 | ||
|
|
ea6468f2a9 | ||
|
|
a2b38d3b83 | ||
|
|
d67ef02941 | ||
|
|
549ebe25d8 | ||
|
|
9a98348582 | ||
|
|
c5f5b025a6 | ||
|
|
23eaffa3a7 | ||
|
|
c161809248 | ||
|
|
4bf26dc818 | ||
|
|
5dd22fad6c | ||
|
|
2c3fdf7803 | ||
|
|
e984b9f5d7 | ||
|
|
a3c2e37b17 | ||
|
|
edf1b5a0a3 | ||
|
|
8efdf59ebd | ||
|
|
5c4537b2fa | ||
|
|
71e6079054 | ||
|
|
dd048d9b0d | ||
|
|
93074d653e | ||
|
|
9139c4350a | ||
|
|
38ce768168 | ||
|
|
82b3dc576c | ||
|
|
2167889f48 | ||
|
|
e9b02c2acf | ||
|
|
9ee446431b | ||
|
|
df106e3988 | ||
|
|
d0a057e0ee | ||
|
|
8b49902bf6 | ||
|
|
71c1e56564 | ||
|
|
1b12e67de2 | ||
|
|
291bb4bb81 | ||
|
|
342ddb19f8 | ||
|
|
9c9d2d548e | ||
|
|
d7a0bb4509 | ||
|
|
2b1a3323a8 | ||
|
|
99d030003c | ||
|
|
92a753560b | ||
|
|
af9904c892 | ||
|
|
e5e8c49f6c | ||
|
|
b37e5f45ca | ||
|
|
e1f08b07aa | ||
|
|
073ee8dca9 | ||
|
|
a26e51cf46 | ||
|
|
dfed732825 | ||
|
|
87aa70c6d2 | ||
|
|
aa2979ffe7 | ||
|
|
236e16aa6d | ||
|
|
184bb970e6 | ||
|
|
bd54469891 | ||
|
|
2f5dccc3ef | ||
|
|
592edb90a0 | ||
|
|
3db7e6b1b9 | ||
|
|
13c4df0d85 | ||
|
|
ef25fb09da | ||
|
|
03cf4a9efe | ||
|
|
53dd36efdd | ||
|
|
ad9e841a42 | ||
|
|
14f3f464c7 | ||
|
|
cbe51cc8d0 | ||
|
|
efaa3f6eea | ||
|
|
52cce9a3b0 | ||
|
|
b7b390311e | ||
|
|
c1eeddd14b | ||
|
|
1a7a55dfc3 | ||
|
|
fe5927ea6a | ||
|
|
119c794ad7 | ||
|
|
e2076b2c1c | ||
|
|
5208c5148e | ||
|
|
d80660b097 | ||
|
|
b916d0278b | ||
|
|
d51e13e620 | ||
|
|
40ad4326ef | ||
|
|
b8afc1684a | ||
|
|
8348b31ac8 | ||
|
|
411f2dbcce | ||
|
|
ee89c08160 | ||
|
|
357607a89f | ||
|
|
8d6dc2df44 | ||
|
|
5207582ab3 | ||
|
|
71768e6154 | ||
|
|
ecbe235523 | ||
|
|
afef079d1e | ||
|
|
df17696c69 | ||
|
|
065bf0908f | ||
|
|
5b6755e9cf | ||
|
|
b08482acf1 | ||
|
|
80c9c1d389 | ||
|
|
bb7db57bda | ||
|
|
6a83ac767c | ||
|
|
7e47ef9d74 | ||
|
|
e7ec603526 | ||
|
|
2d8ae09bd8 | ||
|
|
b2affbc0a7 | ||
|
|
d50bc61ada | ||
|
|
ec6b032b45 | ||
|
|
bc72f48496 | ||
|
|
dcf06fbd36 | ||
|
|
96311d72c2 | ||
|
|
07938cccc7 | ||
|
|
097c8c00f9 | ||
|
|
aa5b41fe31 | ||
|
|
0d56859d94 | ||
|
|
1af5f238e4 | ||
|
|
dd697d5650 | ||
|
|
5cf299a1c7 | ||
|
|
67bf825cc9 | ||
|
|
56e1696cd4 | ||
|
|
d955fb6430 | ||
|
|
dd910a31aa | ||
|
|
708c4d0ec3 | ||
|
|
ad13d6c6a1 | ||
|
|
1c32158142 | ||
|
|
5cea284906 | ||
|
|
13dba8b604 | ||
|
|
22398ddcef | ||
|
|
94e2cc6210 | ||
|
|
da3513f63d | ||
|
|
2c83e4ba9f | ||
|
|
c862071126 | ||
|
|
fed819e9b2 | ||
|
|
c6f4518684 | ||
|
|
053778a502 | ||
|
|
78e1ae885a | ||
|
|
982d28a3e0 | ||
|
|
c2cad858a5 | ||
|
|
794e0574ad | ||
|
|
c190271565 | ||
|
|
ae8a869f64 | ||
|
|
69d64eb8e4 | ||
|
|
b2f2df650a | ||
|
|
6af570fab2 | ||
|
|
9ed902017c | ||
|
|
32b41c98e1 | ||
|
|
6bdb4ae30d | ||
|
|
25dc97e3cc | ||
|
|
cc85983736 | ||
|
|
6e78ee188d | ||
|
|
9b73f1717f | ||
|
|
c7b9a53535 | ||
|
|
2b9be6675c | ||
|
|
fb93453482 | ||
|
|
81b08b2eba | ||
|
|
d1b03c4cb3 | ||
|
|
9544d15a18 | ||
|
|
0392dd0e7f | ||
|
|
9c25fde548 | ||
|
|
2c9d0c6cff | ||
|
|
9897dbe031 | ||
|
|
e78f117cfd | ||
|
|
07afc3813a | ||
|
|
d788de8637 | ||
|
|
d749ac8a91 | ||
|
|
f71c271c97 | ||
|
|
e1d7b7308f | ||
|
|
26a71a823a | ||
|
|
5e39097faa | ||
|
|
0df7845f2c | ||
|
|
af5bf987c8 | ||
|
|
024ace1078 | ||
|
|
8d00fe9d16 | ||
|
|
ab422b14dd | ||
|
|
95c0690216 | ||
|
|
6cb80e9e23 | ||
|
|
83b799caa8 | ||
|
|
a793ac2ff7 | ||
|
|
aec937b04b | ||
|
|
8ee46fd204 | ||
|
|
726233e55f | ||
|
|
7940f4c487 | ||
|
|
b16dbaceec | ||
|
|
f39b2060a8 | ||
|
|
aed202ebf9 | ||
|
|
a495179e5f | ||
|
|
4e1b404820 | ||
|
|
8c74ee31e0 | ||
|
|
77d3c54ebb | ||
|
|
b5de39926b | ||
|
|
3a8dafbb91 | ||
|
|
6b22f547fe | ||
|
|
de78be3e25 | ||
|
|
9f507be7bc | ||
|
|
9aaf271996 | ||
|
|
b01c0d37b0 | ||
|
|
538079880d | ||
|
|
fe0529d021 | ||
|
|
d068f0f2c3 | ||
|
|
f9a64b8d54 | ||
|
|
01cbfaae95 | ||
|
|
f9006a90d5 | ||
|
|
7daeaee6b5 | ||
|
|
03218ce20f | ||
|
|
6f33522c1c | ||
|
|
3697cc3eef | ||
|
|
51a1077fda | ||
|
|
8740c2b165 | ||
|
|
6ed2bdd4c5 | ||
|
|
c32df89490 | ||
|
|
bd5a67676b | ||
|
|
903dab49e3 | ||
|
|
1668c4b0d2 | ||
|
|
2179a27bf5 | ||
|
|
6e7a0cba76 | ||
|
|
69b37b30bc | ||
|
|
ae941a0fdb | ||
|
|
1b741a81e5 | ||
|
|
edf321515b | ||
|
|
c874e6c197 | ||
|
|
9a59c22288 | ||
|
|
750e8840f0 | ||
|
|
cf59989167 | ||
|
|
7c194ab4b4 | ||
|
|
be422d0a1e | ||
|
|
68b63d3007 | ||
|
|
8525138594 | ||
|
|
7b9f8b190e | ||
|
|
67f62daa9f | ||
|
|
0ec701f30b | ||
|
|
c53439066e | ||
|
|
7278bd0c6f | ||
|
|
b842e5821a | ||
|
|
f7d4cce485 | ||
|
|
4f502b707f | ||
|
|
09f182228f | ||
|
|
69ce48a8b9 | ||
|
|
5c2788efe4 | ||
|
|
768323b5b6 | ||
|
|
e203f225e2 | ||
|
|
ab1e2476a0 | ||
|
|
312f32e786 | ||
|
|
397466f0a8 | ||
|
|
1a773cb8ba | ||
|
|
8441c325fa | ||
|
|
cd4a1afbba | ||
|
|
ae75a932bf | ||
|
|
0fa2beede4 | ||
|
|
8e5d5ca1d7 | ||
|
|
2a68414eec | ||
|
|
3f1c8e28e9 | ||
|
|
348531352e | ||
|
|
6770cc422a | ||
|
|
7c157e22c7 | ||
|
|
0cfc6d0503 | ||
|
|
f7fbd16e57 | ||
|
|
542aeadf0f | ||
|
|
84593867dc | ||
|
|
9f23533069 | ||
|
|
4f8f6a47cb | ||
|
|
7d7a3f30e6 | ||
|
|
d39ed1ea5a | ||
|
|
5c8b314689 | ||
|
|
9953d7d388 | ||
|
|
5adf8a0773 | ||
|
|
26bfb912f1 | ||
|
|
c07d0b32a9 | ||
|
|
562da971e9 | ||
|
|
3eb24da475 | ||
|
|
8977d50992 | ||
|
|
13365dd390 | ||
|
|
aee06f51f0 | ||
|
|
d6c497731f | ||
|
|
f23e26d9da | ||
|
|
ec324e02f2 | ||
|
|
e2ce809762 | ||
|
|
d054cf9e36 | ||
|
|
943e775364 | ||
|
|
b9ec6523d6 | ||
|
|
5206d47b43 | ||
|
|
aaa8622956 | ||
|
|
587d716aae | ||
|
|
5a8710cc76 | ||
|
|
307f3a9dec | ||
|
|
eff5fc3d9a | ||
|
|
5a3004f1d1 | ||
|
|
db589b7d91 | ||
|
|
0a83175b66 | ||
|
|
bc4776f096 | ||
|
|
ab534bb998 | ||
|
|
cf2aacd75b | ||
|
|
9f88374627 | ||
|
|
b7d898b505 | ||
|
|
12c1fb6000 | ||
|
|
1ce1fdff8d | ||
|
|
7c11a7e5bc | ||
|
|
7d46b98310 | ||
|
|
68c4834a62 | ||
|
|
c9608ad7a7 | ||
|
|
6ea4132ff9 | ||
|
|
be79356f42 | ||
|
|
d4a2e059d7 | ||
|
|
f3d985ecbc | ||
|
|
bcba693afb | ||
|
|
b4fb7bf99f | ||
|
|
3ef6205ea3 | ||
|
|
3feb43fdad | ||
|
|
d74226dab1 | ||
|
|
5c3db5d991 | ||
|
|
bcb8bea0fe | ||
|
|
0c0650a2c3 | ||
|
|
2c0fd84c72 | ||
|
|
81cd03e0c3 | ||
|
|
349e6e7c94 | ||
|
|
c4c43b23ad | ||
|
|
7622f81309 | ||
|
|
c31bcf7f6a | ||
|
|
fef31b9102 | ||
|
|
20cf016b06 | ||
|
|
67604eca8d | ||
|
|
46f820690d | ||
|
|
e36256abe3 | ||
|
|
b00ca3d48c | ||
|
|
cf2e6bf382 | ||
|
|
fc52afdb00 | ||
|
|
85434b4edb | ||
|
|
f3a6c8df71 | ||
|
|
6e5c5f61db | ||
|
|
12c31ba9d1 | ||
|
|
ea50d893d4 | ||
|
|
bacd0e6e39 | ||
|
|
c0cd4ead04 | ||
|
|
4b04fc65ad | ||
|
|
83243ba32f | ||
|
|
a734ecaa10 | ||
|
|
22e2f703db | ||
|
|
28174b8dc8 | ||
|
|
061352bcff | ||
|
|
2f40724258 | ||
|
|
a45a2a5bd7 | ||
|
|
08221af3f8 | ||
|
|
f799690d3c | ||
|
|
07ab2b4b02 | ||
|
|
cafeda4368 | ||
|
|
517b39649c | ||
|
|
067b0d2e9f | ||
|
|
9b98181d28 | ||
|
|
46a94ecacd | ||
|
|
964a9f64f2 | ||
|
|
b4d94c2cbe | ||
|
|
268e9ffefd | ||
|
|
c8f8170ec2 | ||
|
|
8b20f0bf31 | ||
|
|
fe9af039fc | ||
|
|
6fad5bef4a | ||
|
|
16a0403fd4 | ||
|
|
e32d1f0900 | ||
|
|
3f37b7cdb5 | ||
|
|
059ccf41b6 | ||
|
|
1af2b8f47b | ||
|
|
87f18d0e13 | ||
|
|
8de12da1ec | ||
|
|
71080682cc | ||
|
|
f915a4208b | ||
|
|
14c41d33a7 | ||
|
|
3e61d6f84d | ||
|
|
4541d5219b | ||
|
|
3ce1566a2e | ||
|
|
368729f0f3 | ||
|
|
127392a1ae | ||
|
|
af1329710d | ||
|
|
30232d1275 | ||
|
|
31fa4948d5 | ||
|
|
6c11096fd2 | ||
|
|
7a90d2d38f | ||
|
|
a543bc7c00 | ||
|
|
8af2f044ed | ||
|
|
947f21cac7 | ||
|
|
479aad2f06 | ||
|
|
329925ea54 | ||
|
|
c8a3ebfcec |
@@ -0,0 +1,49 @@
|
||||
name: Setup devkitPro
|
||||
description: Install devkitPro with GameCube/Wii packages on an Ubuntu runner
|
||||
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
- name: Install apt dependencies
|
||||
shell: bash
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y \
|
||||
cmake \
|
||||
python3 \
|
||||
python3-pip \
|
||||
python3-polib \
|
||||
python3-pil \
|
||||
python3-dotenv \
|
||||
python3-pyqt5 \
|
||||
python3-opengl \
|
||||
xorriso
|
||||
- name: Install devkitPro pacman
|
||||
shell: bash
|
||||
run: |
|
||||
sudo ln -sf /proc/self/mounts /etc/mtab
|
||||
wget https://apt.devkitpro.org/install-devkitpro-pacman \
|
||||
-O /tmp/install-devkitpro-pacman
|
||||
echo "=== installer script contents ==="
|
||||
cat /tmp/install-devkitpro-pacman
|
||||
echo "================================="
|
||||
chmod +x /tmp/install-devkitpro-pacman
|
||||
sudo /tmp/install-devkitpro-pacman
|
||||
echo "DEVKITPRO=/opt/devkitpro" >> $GITHUB_ENV
|
||||
echo "DEVKITPPC=/opt/devkitpro/devkitPPC" >> $GITHUB_ENV
|
||||
echo "/opt/devkitpro/tools/bin" >> $GITHUB_PATH
|
||||
echo "/opt/devkitpro/devkitPPC/bin" >> $GITHUB_PATH
|
||||
- name: Install devkitPro GameCube/Wii packages
|
||||
shell: bash
|
||||
run: |
|
||||
sudo dkp-pacman -S --needed --noconfirm \
|
||||
gamecube-dev \
|
||||
gamecube-sdl2 \
|
||||
ppc-liblzma \
|
||||
ppc-libzip \
|
||||
libogc2 \
|
||||
gamecube-tools \
|
||||
ppc-libmad \
|
||||
ppc-zlib-ng \
|
||||
ppc-bzip2 \
|
||||
ppc-zstd
|
||||
@@ -0,0 +1,20 @@
|
||||
name: Setup pspdev
|
||||
description: Install the pspdev PSP toolchain on an Ubuntu runner
|
||||
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
- name: Install dependencies
|
||||
shell: bash
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y cmake python3 python3-pip python3-dotenv
|
||||
- name: Install pspdev toolchain
|
||||
shell: bash
|
||||
run: |
|
||||
wget -q \
|
||||
https://github.com/pspdev/pspdev/releases/latest/download/pspdev-ubuntu-latest-x86_64.tar.gz \
|
||||
-O /tmp/pspdev.tar.gz
|
||||
sudo tar -xzf /tmp/pspdev.tar.gz -C /usr/local
|
||||
echo "PSPDEV=/usr/local/pspdev" >> $GITHUB_ENV
|
||||
echo "/usr/local/pspdev/bin" >> $GITHUB_PATH
|
||||
@@ -0,0 +1,247 @@
|
||||
name: Build Dusk
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- '*'
|
||||
jobs:
|
||||
build-linux:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y \
|
||||
build-essential \
|
||||
cmake \
|
||||
python3 \
|
||||
python3-pip \
|
||||
python3-polib \
|
||||
python3-pil \
|
||||
libsdl2-dev \
|
||||
libgl1-mesa-dev \
|
||||
libzip-dev \
|
||||
python3-dotenv \
|
||||
python3-pyqt5 \
|
||||
python3-opengl \
|
||||
xz-utils \
|
||||
liblzma-dev \
|
||||
libbz2-dev \
|
||||
zlib1g-dev \
|
||||
git \
|
||||
libssl-dev
|
||||
- name: Build Linux
|
||||
run: ./scripts/build-linux.sh
|
||||
- name: Upload Linux binary
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: dusk-linux
|
||||
path: build-linux/Dusk
|
||||
if-no-files-found: error
|
||||
|
||||
build-psp:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
- name: Setup pspdev
|
||||
uses: ./.github/actions/setup-pspdev
|
||||
- name: Build PSP
|
||||
run: ./scripts/build-psp.sh
|
||||
- name: Move EBOOT.PBP to Dusk subfolder
|
||||
run: |
|
||||
mkdir -p ./git-artifcats/Dusk/PSP/GAME/Dusk
|
||||
cp build-psp/EBOOT.PBP ./git-artifcats/Dusk/PSP/GAME/Dusk/EBOOT.PBP
|
||||
- name: Upload PSP binary
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: dusk-psp
|
||||
path: ./git-artifcats/Dusk
|
||||
if-no-files-found: error
|
||||
|
||||
build-knulli:
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: debian:trixie
|
||||
steps:
|
||||
- name: Install Node.js
|
||||
run: apt-get update && apt-get install -y nodejs
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
dpkg --add-architecture arm64
|
||||
apt-get update
|
||||
apt-get install -y --no-install-recommends \
|
||||
crossbuild-essential-arm64 \
|
||||
ca-certificates \
|
||||
pkg-config \
|
||||
cmake \
|
||||
make \
|
||||
ninja-build \
|
||||
git \
|
||||
file \
|
||||
python3 \
|
||||
python3-pip \
|
||||
python3-polib \
|
||||
python3-pil \
|
||||
python3-dotenv \
|
||||
python3-pyqt5 \
|
||||
python3-opengl \
|
||||
liblua5.4-dev:arm64 \
|
||||
xz-utils:arm64 \
|
||||
libbz2-dev:arm64 \
|
||||
zlib1g-dev:arm64 \
|
||||
libzip-dev:arm64 \
|
||||
libssl-dev:arm64 \
|
||||
libsdl2-dev:arm64 \
|
||||
liblzma-dev:arm64 \
|
||||
libopengl0:arm64 \
|
||||
libgl1:arm64 \
|
||||
libegl1:arm64 \
|
||||
libgles2:arm64 \
|
||||
libgl1-mesa-dev:arm64
|
||||
- name: Build Knulli
|
||||
run: ./scripts/build-knulli.sh
|
||||
- name: Move output to Dusk subfolder
|
||||
run: |
|
||||
mkdir -p ./git-artifcats/Dusk
|
||||
cp -r build-knulli/dusk ./git-artifcats/Dusk
|
||||
- name: Upload Knulli binary
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: dusk-knulli
|
||||
path: ./git-artifcats/Dusk
|
||||
if-no-files-found: error
|
||||
|
||||
build-gamecube:
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ghcr.io/extremscorner/libogc2:latest
|
||||
steps:
|
||||
- name: Install Node.js
|
||||
run: apt-get update && apt-get install -y nodejs
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
- name: Install additional dependencies
|
||||
run: |
|
||||
apt-get install -y \
|
||||
python3-pip python3-polib python3-pil \
|
||||
python3-dotenv python3-pyqt5 python3-opengl
|
||||
dkp-pacman -Syu --noconfirm
|
||||
dkp-pacman -S --needed --noconfirm \
|
||||
gamecube-sdl2 ppc-liblzma ppc-libzip \
|
||||
gamecube-tools ppc-libmad ppc-zlib-ng ppc-bzip2 ppc-zstd
|
||||
- name: Build GameCube
|
||||
run: ./scripts/build-gamecube.sh
|
||||
- name: Copy output files
|
||||
run: |
|
||||
mkdir -p ./git-artifcats/Dusk
|
||||
cp build-gamecube/Dusk.dol ./git-artifcats/Dusk/Dusk.dol
|
||||
cp build-gamecube/dusk.dsk ./git-artifcats/Dusk/dusk.dsk
|
||||
- name: Upload GameCube binary
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: dusk-gamecube
|
||||
path: ./git-artifcats/Dusk
|
||||
if-no-files-found: error
|
||||
|
||||
build-gamecube-iso:
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ghcr.io/extremscorner/libogc2:latest
|
||||
steps:
|
||||
- name: Install Node.js
|
||||
run: apt-get update && apt-get install -y nodejs
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
- name: Install additional dependencies
|
||||
run: |
|
||||
apt-get install -y \
|
||||
python3-pip python3-polib python3-pil \
|
||||
python3-dotenv python3-pyqt5 python3-opengl xorriso
|
||||
dkp-pacman -Syu --noconfirm
|
||||
dkp-pacman -S --needed --noconfirm \
|
||||
gamecube-sdl2 ppc-liblzma ppc-libzip \
|
||||
gamecube-tools ppc-libmad ppc-zlib-ng ppc-bzip2 ppc-zstd
|
||||
- name: Build GameCube ISO
|
||||
run: ./scripts/build-gamecube-iso.sh
|
||||
- name: Copy output files
|
||||
run: |
|
||||
mkdir -p ./git-artifcats/Dusk
|
||||
cp build-gamecube-iso/Dusk-NTSC-J.iso ./git-artifcats/Dusk/Dusk-NTSC-J.iso
|
||||
cp build-gamecube-iso/Dusk-NTSC-U.iso ./git-artifcats/Dusk/Dusk-NTSC-U.iso
|
||||
cp build-gamecube-iso/Dusk-PAL.iso ./git-artifcats/Dusk/Dusk-PAL.iso
|
||||
- name: Upload GameCube ISO
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: dusk-gamecube-iso
|
||||
path: ./git-artifcats/Dusk
|
||||
if-no-files-found: error
|
||||
|
||||
build-wii:
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ghcr.io/extremscorner/libogc2:latest
|
||||
steps:
|
||||
- name: Install Node.js
|
||||
run: apt-get update && apt-get install -y nodejs
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
- name: Install additional dependencies
|
||||
run: |
|
||||
apt-get install -y \
|
||||
python3-pip python3-polib python3-pil \
|
||||
python3-dotenv python3-pyqt5 python3-opengl
|
||||
dkp-pacman -Syu --noconfirm
|
||||
dkp-pacman -S --needed --noconfirm \
|
||||
gamecube-sdl2 ppc-liblzma ppc-libzip \
|
||||
gamecube-tools ppc-libmad ppc-zlib-ng ppc-bzip2 ppc-zstd
|
||||
- name: Build Wii
|
||||
run: ./scripts/build-wii.sh
|
||||
- name: Copy output files
|
||||
run: |
|
||||
mkdir -p ./git-artifcats/Dusk/apps/Dusk
|
||||
cp build-wii/boot.dol ./git-artifcats/Dusk/apps/Dusk/boot.dol
|
||||
cp build-wii/dusk.dsk ./git-artifcats/Dusk/apps/Dusk/dusk.dsk
|
||||
cp build-wii/meta.xml ./git-artifcats/Dusk/apps/Dusk/meta.xml
|
||||
- name: Upload Wii binary
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: dusk-wii
|
||||
path: ./git-artifcats/Dusk
|
||||
if-no-files-found: error
|
||||
|
||||
build-wii-iso:
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ghcr.io/extremscorner/libogc2:latest
|
||||
steps:
|
||||
- name: Install Node.js
|
||||
run: apt-get update && apt-get install -y nodejs
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
- name: Install additional dependencies
|
||||
run: |
|
||||
apt-get install -y \
|
||||
python3-pip python3-polib python3-pil \
|
||||
python3-dotenv python3-pyqt5 python3-opengl xorriso
|
||||
dkp-pacman -Syu --noconfirm
|
||||
dkp-pacman -S --needed --noconfirm \
|
||||
gamecube-sdl2 ppc-liblzma ppc-libzip \
|
||||
gamecube-tools ppc-libmad ppc-zlib-ng ppc-bzip2 ppc-zstd
|
||||
- name: Build Wii ISO
|
||||
run: ./scripts/build-wii-iso.sh
|
||||
- name: Copy output files
|
||||
run: |
|
||||
mkdir -p ./git-artifcats/Dusk
|
||||
cp build-wii-iso/Dusk-NTSC-J.iso ./git-artifcats/Dusk/Dusk-NTSC-J.iso
|
||||
cp build-wii-iso/Dusk-NTSC-U.iso ./git-artifcats/Dusk/Dusk-NTSC-U.iso
|
||||
cp build-wii-iso/Dusk-PAL.iso ./git-artifcats/Dusk/Dusk-PAL.iso
|
||||
- name: Upload Wii ISO
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: dusk-wii-iso
|
||||
path: ./git-artifcats/Dusk
|
||||
if-no-files-found: error
|
||||
@@ -0,0 +1,106 @@
|
||||
name: Test Dusk
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
jobs:
|
||||
run-tests:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y \
|
||||
build-essential \
|
||||
cmake \
|
||||
python3 \
|
||||
python3-pip \
|
||||
python3-polib \
|
||||
python3-pil \
|
||||
libsdl2-dev \
|
||||
libgl1-mesa-dev \
|
||||
libzip-dev \
|
||||
python3-dotenv \
|
||||
python3-pyqt5 \
|
||||
python3-opengl \
|
||||
xz-utils \
|
||||
liblzma-dev \
|
||||
libbz2-dev \
|
||||
zlib1g-dev \
|
||||
git \
|
||||
libssl-dev
|
||||
- name: Run tests
|
||||
run: ./scripts/test-linux.sh
|
||||
|
||||
# Emulator smoke tests: boot the built disc/EBOOT for a fixed window and
|
||||
# confirm the emulator doesn't crash. Not yet verified against a real
|
||||
# runner (no CI run has exercised these) -- continue-on-error so a
|
||||
# flaky/broken emulator step doesn't block the required Linux test job.
|
||||
run-tests-gamecube-dolphin:
|
||||
runs-on: ubuntu-latest
|
||||
continue-on-error: true
|
||||
container:
|
||||
image: ghcr.io/extremscorner/libogc2:latest
|
||||
steps:
|
||||
- name: Install Node.js
|
||||
run: apt-get update && apt-get install -y nodejs
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
- name: Install additional dependencies
|
||||
run: |
|
||||
apt-get install -y \
|
||||
python3-pip python3-polib python3-pil \
|
||||
python3-dotenv python3-pyqt5 python3-opengl xorriso \
|
||||
dolphin-emu xvfb
|
||||
dkp-pacman -Syu --noconfirm
|
||||
dkp-pacman -S --needed --noconfirm \
|
||||
gamecube-sdl2 ppc-liblzma ppc-libzip \
|
||||
gamecube-tools ppc-libmad ppc-zlib-ng ppc-bzip2 ppc-zstd
|
||||
- name: Build GameCube ISO and boot it in Dolphin
|
||||
run: ./scripts/test-gamecube-dolphin.sh
|
||||
|
||||
run-tests-wii-dolphin:
|
||||
runs-on: ubuntu-latest
|
||||
continue-on-error: true
|
||||
container:
|
||||
image: ghcr.io/extremscorner/libogc2:latest
|
||||
steps:
|
||||
- name: Install Node.js
|
||||
run: apt-get update && apt-get install -y nodejs
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
- name: Install additional dependencies
|
||||
run: |
|
||||
apt-get install -y \
|
||||
python3-pip python3-polib python3-pil \
|
||||
python3-dotenv python3-pyqt5 python3-opengl xorriso \
|
||||
dolphin-emu xvfb
|
||||
dkp-pacman -Syu --noconfirm
|
||||
dkp-pacman -S --needed --noconfirm \
|
||||
gamecube-sdl2 ppc-liblzma ppc-libzip \
|
||||
gamecube-tools ppc-libmad ppc-zlib-ng ppc-bzip2 ppc-zstd
|
||||
- name: Build Wii ISO and boot it in Dolphin
|
||||
run: ./scripts/test-wii-dolphin.sh
|
||||
|
||||
run-tests-psp-ppsspp:
|
||||
runs-on: ubuntu-latest
|
||||
continue-on-error: true
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
- name: Setup pspdev
|
||||
uses: ./.github/actions/setup-pspdev
|
||||
- name: Install PPSSPPHeadless build dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y git cmake ninja-build libsdl2-dev zlib1g-dev
|
||||
- name: Build PPSSPPHeadless
|
||||
run: |
|
||||
git clone --recursive --depth 1 https://github.com/hrydgard/ppsspp.git /tmp/ppsspp
|
||||
cmake -S /tmp/ppsspp -B /tmp/ppsspp/build -DCMAKE_BUILD_TYPE=Release
|
||||
cmake --build /tmp/ppsspp/build --target PPSSPPHeadless -- -j$(nproc)
|
||||
echo "PPSSPP_HEADLESS_BIN=/tmp/ppsspp/build/PPSSPPHeadless" >> "$GITHUB_ENV"
|
||||
- name: Build PSP EBOOT and boot it in PPSSPPHeadless
|
||||
run: ./scripts/test-psp-ppsspp.sh
|
||||
+13
-1
@@ -83,7 +83,6 @@ assets/borrowed
|
||||
.VSCode*
|
||||
|
||||
/vita
|
||||
|
||||
._*
|
||||
|
||||
*~
|
||||
@@ -95,3 +94,16 @@ assets/borrowed
|
||||
# /archive
|
||||
|
||||
__pycache__
|
||||
|
||||
package-lock.json
|
||||
yarn-error.log
|
||||
yarn.lock
|
||||
|
||||
.editor
|
||||
.venv
|
||||
|
||||
/build2
|
||||
/build*
|
||||
/assets/test
|
||||
/tools_old
|
||||
/assets/test.png
|
||||
+99
-54
@@ -5,14 +5,20 @@
|
||||
|
||||
# Setup
|
||||
cmake_minimum_required(VERSION 3.13)
|
||||
set(CMAKE_C_STANDARD 99)
|
||||
|
||||
set(CMAKE_C_STANDARD 11)
|
||||
set(CMAKE_C_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)
|
||||
cmake_policy(SET CMP0079 NEW)
|
||||
# set(FETCHCONTENT_UPDATES_DISCONNECTED ON)
|
||||
|
||||
if(NOT DEFINED DUSK_TARGET_SYSTEM)
|
||||
set(DUSK_TARGET_SYSTEM "linux")
|
||||
# set(DUSK_TARGET_SYSTEM "psp")
|
||||
endif()
|
||||
option(DUSK_BUILD_TESTS "Enable tests" OFF)
|
||||
option(DUSK_NETWORKING "Enable networking support" OFF)
|
||||
|
||||
set(DUSK_GAME_NAME "Dusk" CACHE STRING "Game display name")
|
||||
set(DUSK_GAME_AUTHOR "YourWishes" CACHE STRING "Game author / coder")
|
||||
set(DUSK_GAME_SHORT_DESCRIPTION "Dusk game" CACHE STRING "One-line description")
|
||||
set(DUSK_GAME_LONG_DESCRIPTION "No description yet." CACHE STRING "Full description")
|
||||
|
||||
# Prep cache
|
||||
set(DUSK_CACHE_TARGET "dusk-target")
|
||||
@@ -21,76 +27,115 @@ set(DUSK_CACHE_TARGET "dusk-target")
|
||||
set(DUSK_ROOT_DIR "${CMAKE_SOURCE_DIR}")
|
||||
set(DUSK_BUILD_DIR "${CMAKE_BINARY_DIR}")
|
||||
set(DUSK_SOURCES_DIR "${DUSK_ROOT_DIR}/src")
|
||||
set(DUSK_TEST_DIR "${DUSK_ROOT_DIR}/test")
|
||||
set(DUSK_TEMP_DIR "${DUSK_BUILD_DIR}/temp")
|
||||
set(DUSK_TOOLS_DIR "${DUSK_ROOT_DIR}/tools")
|
||||
set(DUSK_DATA_DIR "${DUSK_ROOT_DIR}/data")
|
||||
set(DUSK_ASSETS_DIR "${DUSK_ROOT_DIR}/assets")
|
||||
set(DUSK_BUILT_ASSETS_DIR "${DUSK_BUILD_DIR}/built_assets" CACHE INTERNAL ${DUSK_CACHE_TARGET})
|
||||
set(DUSK_GENERATED_HEADERS_DIR "${DUSK_BUILD_DIR}/generated")
|
||||
set(DUSK_TARGET_NAME "Dusk" CACHE INTERNAL ${DUSK_CACHE_TARGET})
|
||||
set(DUSK_BUILD_BINARY ${DUSK_BUILD_DIR}/Dusk CACHE INTERNAL ${DUSK_CACHE_TARGET})
|
||||
set(DUSK_ASSETS "" CACHE INTERNAL ${DUSK_CACHE_TARGET})
|
||||
set(DUSK_LIBRARY_TARGET_NAME "DuskCore" CACHE INTERNAL ${DUSK_CACHE_TARGET})
|
||||
set(DUSK_BINARY_TARGET_NAME "Dusk" CACHE INTERNAL ${DUSK_CACHE_TARGET})
|
||||
set(DUSK_ASSETS_ZIP "${DUSK_BUILD_DIR}/dusk.dsk" CACHE INTERNAL ${DUSK_CACHE_TARGET})
|
||||
|
||||
# Toolchain
|
||||
if(NOT DEFINED DUSK_TARGET_SYSTEM)
|
||||
set(DUSK_TARGET_SYSTEM "linux")
|
||||
endif()
|
||||
|
||||
# Create directories
|
||||
file(MAKE_DIRECTORY ${DUSK_GENERATED_HEADERS_DIR})
|
||||
file(MAKE_DIRECTORY ${DUSK_ASSETS_BUILD_DIR})
|
||||
file(MAKE_DIRECTORY ${DUSK_TEMP_DIR})
|
||||
file(MAKE_DIRECTORY ${DUSK_BUILT_ASSETS_DIR})
|
||||
|
||||
# Compilers
|
||||
if(DUSK_TARGET_SYSTEM STREQUAL "psp")
|
||||
find_package(pspsdk REQUIRED)
|
||||
endif()
|
||||
# Required build packages
|
||||
find_package(Python3 COMPONENTS Interpreter REQUIRED)
|
||||
|
||||
# Init Project
|
||||
project(${DUSK_TARGET_NAME}
|
||||
# Init Project.
|
||||
project(${DUSK_LIBRARY_TARGET_NAME}
|
||||
VERSION 1.0.0
|
||||
LANGUAGES C
|
||||
)
|
||||
|
||||
# Executable
|
||||
add_executable(${DUSK_TARGET_NAME})
|
||||
# Either, create library and binary separately (used for tests), or make them
|
||||
# one in the same so all code is in the binary only.
|
||||
# Binary Executable
|
||||
add_executable(${DUSK_BINARY_TARGET_NAME} ${DUSK_SOURCES_DIR}/dusk/null.c)
|
||||
|
||||
if(DUSK_BUILD_TESTS)
|
||||
# MainLibrary
|
||||
add_library(${DUSK_LIBRARY_TARGET_NAME} STATIC)
|
||||
|
||||
# Link library to binary
|
||||
target_link_libraries(${DUSK_BINARY_TARGET_NAME}
|
||||
PUBLIC
|
||||
${DUSK_LIBRARY_TARGET_NAME}
|
||||
)
|
||||
else()
|
||||
set(DUSK_LIBRARY_TARGET_NAME "${DUSK_BINARY_TARGET_NAME}" CACHE INTERNAL ${DUSK_CACHE_TARGET})
|
||||
endif()
|
||||
|
||||
if(NOT DEFINED DUSK_VERSION)
|
||||
string(TIMESTAMP DUSK_VERSION "debug-%y%m%d%H%M%S")
|
||||
endif()
|
||||
|
||||
# Definitions
|
||||
target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME}
|
||||
PUBLIC
|
||||
DUSK_TARGET_SYSTEM="${DUSK_TARGET_SYSTEM}"
|
||||
DUSK_GAME_NAME="${DUSK_GAME_NAME}"
|
||||
DUSK_GAME_AUTHOR="${DUSK_GAME_AUTHOR}"
|
||||
DUSK_GAME_SHORT_DESCRIPTION="${DUSK_GAME_SHORT_DESCRIPTION}"
|
||||
DUSK_GAME_LONG_DESCRIPTION="${DUSK_GAME_LONG_DESCRIPTION}"
|
||||
DUSK_VERSION="${DUSK_VERSION}"
|
||||
)
|
||||
|
||||
if(DUSK_NETWORKING)
|
||||
target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
||||
DUSK_NETWORKING
|
||||
)
|
||||
endif()
|
||||
|
||||
# Toolchains
|
||||
include(cmake/targets/${DUSK_TARGET_SYSTEM}.cmake)
|
||||
|
||||
# Add tools
|
||||
add_subdirectory(tools)
|
||||
|
||||
# Add libraries
|
||||
if(DUSK_TARGET_SYSTEM STREQUAL "linux")
|
||||
find_package(SDL2 REQUIRED)
|
||||
find_package(OpenGL REQUIRED)
|
||||
target_link_libraries(${DUSK_TARGET_NAME} PRIVATE
|
||||
SDL2::SDL2
|
||||
OpenGL::GL
|
||||
GL
|
||||
)
|
||||
|
||||
elseif(DUSK_TARGET_SYSTEM STREQUAL "psp")
|
||||
find_package(SDL2 REQUIRED)
|
||||
target_link_libraries(${DUSK_TARGET_NAME}
|
||||
PRIVATE
|
||||
# pspsdk
|
||||
${SDL2_LIBRARIES}
|
||||
)
|
||||
target_include_directories(${DUSK_TARGET_NAME}
|
||||
PRIVATE
|
||||
${SDL2_INCLUDE_DIRS}
|
||||
)
|
||||
endif()
|
||||
|
||||
# Add code
|
||||
add_subdirectory(src)
|
||||
|
||||
# Include generated headers
|
||||
target_include_directories(${DUSK_TARGET_NAME} PUBLIC
|
||||
# Include generated headers from tools.
|
||||
target_include_directories(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
||||
${DUSK_GENERATED_HEADERS_DIR}
|
||||
)
|
||||
|
||||
# Postbuild, create PBP file for PSP.
|
||||
if(DUSK_TARGET_SYSTEM STREQUAL "psp")
|
||||
create_pbp_file(
|
||||
TARGET "${DUSK_TARGET_NAME}"
|
||||
ICON_PATH NULL
|
||||
BACKGROUND_PATH NULL
|
||||
PREVIEW_PATH NULL
|
||||
TITLE "${DUSK_TARGET_NAME}"
|
||||
VERSION 01.00
|
||||
)
|
||||
# Add main code
|
||||
add_subdirectory(${DUSK_SOURCES_DIR})
|
||||
|
||||
# Include generated headers
|
||||
target_include_directories(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
||||
${DUSK_GENERATED_HEADERS_DIR}
|
||||
)
|
||||
|
||||
# Handle tests
|
||||
if(DUSK_BUILD_TESTS)
|
||||
enable_testing()
|
||||
add_subdirectory(test)
|
||||
endif()
|
||||
|
||||
# Build assets
|
||||
# Deliberately not CONFIGURE_DEPENDS: that reruns the full CMake configure
|
||||
# step (which invalidates generated headers and forces a huge rebuild) on
|
||||
# every single asset edit. Re-run cmake manually when assets are added or
|
||||
# removed.
|
||||
file(GLOB_RECURSE DUSK_ASSET_FILES "${DUSK_ASSETS_DIR}/*")
|
||||
add_custom_command(
|
||||
OUTPUT "${DUSK_ASSETS_ZIP}"
|
||||
COMMAND ${CMAKE_COMMAND} -E make_directory "${DUSK_ASSETS_DIR}"
|
||||
COMMAND ${CMAKE_COMMAND} -E rm -f "${DUSK_ASSETS_ZIP}"
|
||||
COMMAND ${CMAKE_COMMAND} -E tar "cf" "${DUSK_ASSETS_ZIP}" --format=zip -- .
|
||||
WORKING_DIRECTORY "${DUSK_ASSETS_DIR}"
|
||||
DEPENDS ${DUSK_ASSET_FILES}
|
||||
VERBATIM
|
||||
)
|
||||
add_custom_target(DUSK_ASSETS_BUILT DEPENDS "${DUSK_ASSETS_ZIP}")
|
||||
add_dependencies(${DUSK_LIBRARY_TARGET_NAME} DUSK_ASSETS_BUILT)
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
# Dusk
|
||||
RPG Game Project, small and able to run on a PSP.
|
||||
|
||||
# Building
|
||||
Each build target has different requirements. You can take a look at the git
|
||||
workflow to see how the builds are done for each target. In addition, for
|
||||
accessing the editor and building the game on your host system, install the
|
||||
following packages, depending on your system;
|
||||
|
||||
Fedora;
|
||||
```
|
||||
sudo dnf install git make gcc cmake python python-polib python3-pillow python3-dotenv python3-numpy python-qt5 python3-pyopengl SDL2-devel zlib-devel libzip-devel bzip2-devel openssl-devel lzma-sdk-devel xz xz-devel lua-devel
|
||||
```
|
||||
|
||||
Ubuntu;
|
||||
```
|
||||
sudo apt-get install git build-essential gcc python python-polib python3-pillow python3-dotenv python3-numpy python3-pyqt5 python3-opengl
|
||||
```
|
||||
|
||||
Arch Linux;
|
||||
```
|
||||
sudo pacman -S git base-devel gcc python python-polib python-pillow python-dotenv python-numpy python-pyqt5 python-opengl
|
||||
```
|
||||
@@ -1,37 +0,0 @@
|
||||
# Copyright (c) 2025 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Libs
|
||||
target_link_libraries(${DUSK_TARGET_NAME}
|
||||
PUBLIC
|
||||
m
|
||||
)
|
||||
|
||||
# Includes
|
||||
target_include_directories(${DUSK_TARGET_NAME}
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
|
||||
# Sources
|
||||
target_sources(${DUSK_TARGET_NAME}
|
||||
PRIVATE
|
||||
game.c
|
||||
input.c
|
||||
time.c
|
||||
)
|
||||
|
||||
# Subdirs
|
||||
add_subdirectory(assert)
|
||||
add_subdirectory(console)
|
||||
add_subdirectory(display)
|
||||
add_subdirectory(error)
|
||||
add_subdirectory(entity)
|
||||
add_subdirectory(event)
|
||||
add_subdirectory(item)
|
||||
add_subdirectory(locale)
|
||||
add_subdirectory(ui)
|
||||
add_subdirectory(util)
|
||||
add_subdirectory(world)
|
||||
@@ -1,85 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2023 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "assert.h"
|
||||
|
||||
#ifndef ASSERTIONS_FAKED
|
||||
void assertTrueImpl(
|
||||
const char *file,
|
||||
const int32_t line,
|
||||
const bool x,
|
||||
const char *message
|
||||
) {
|
||||
if(x != true) {
|
||||
fprintf(
|
||||
stderr,
|
||||
"Assertion Failed in %s:%i\n\n%s\n",
|
||||
file,
|
||||
line,
|
||||
message
|
||||
);
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
void assertFalseImpl(
|
||||
const char *file,
|
||||
const int32_t line,
|
||||
bool x,
|
||||
const char *message
|
||||
) {
|
||||
assertTrueImpl(file, line, !x, message);
|
||||
}
|
||||
|
||||
void assertUnreachableImpl(
|
||||
const char *file,
|
||||
const int32_t line,
|
||||
const char *message
|
||||
) {
|
||||
assertTrueImpl(file, line, false, message);
|
||||
}
|
||||
|
||||
void assertNotNullImpl(
|
||||
const char *file,
|
||||
const int32_t line,
|
||||
const void *pointer,
|
||||
const char *message
|
||||
) {
|
||||
assertTrueImpl(
|
||||
file,
|
||||
line,
|
||||
pointer != NULL,
|
||||
message
|
||||
);
|
||||
|
||||
// Ensure we can touch it
|
||||
volatile char temp;
|
||||
temp = *((char*)pointer);
|
||||
}
|
||||
|
||||
void assertNullImpl(
|
||||
const char *file,
|
||||
const int32_t line,
|
||||
const void *pointer,
|
||||
const char *message
|
||||
) {
|
||||
assertTrueImpl(
|
||||
file,
|
||||
line,
|
||||
pointer == NULL,
|
||||
message
|
||||
);
|
||||
}
|
||||
|
||||
void assertDeprecatedImpl(
|
||||
const char *file,
|
||||
const int32_t line,
|
||||
const char *message
|
||||
) {
|
||||
assertUnreachableImpl(file, line, message);
|
||||
}
|
||||
#endif
|
||||
@@ -1,143 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2023 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "dusk.h"
|
||||
|
||||
#ifndef ASSERTIONS_FAKED
|
||||
/**
|
||||
* Assert a given value to be true.
|
||||
*
|
||||
* @param file File that the assertion is being made from.
|
||||
* @param line Line that the assertion is being made from.
|
||||
* @param x Value to assert as true.
|
||||
* @param message Message to throw against assertion failure.
|
||||
*/
|
||||
void assertTrueImpl(
|
||||
const char *file,
|
||||
const int32_t line,
|
||||
const bool_t x,
|
||||
const char *message
|
||||
);
|
||||
|
||||
/**
|
||||
* Asserts a given statement to be false.
|
||||
*
|
||||
* @param file File that the assertion is being made from.
|
||||
* @param line Line that the assertion is being made from.
|
||||
* @param x Value to assert as false.
|
||||
* @param message Message to throw against assertion failure.
|
||||
*/
|
||||
void assertFalseImpl(
|
||||
const char *file,
|
||||
const int32_t line,
|
||||
const bool_t x,
|
||||
const char *message
|
||||
);
|
||||
|
||||
/**
|
||||
* Asserts that a given line of code is unreachable. Essentially a forced
|
||||
* assertion failure, good for "edge cases"
|
||||
*
|
||||
* @param file File that the assertion is being made from.
|
||||
* @param line Line that the assertion is being made from.
|
||||
* @param message Message to throw against assertion failure.
|
||||
*/
|
||||
void assertUnreachableImpl(
|
||||
const char *file,
|
||||
const int32_t line,
|
||||
const char *message
|
||||
);
|
||||
|
||||
/**
|
||||
* Assert a given pointer to not point to a null pointer.
|
||||
*
|
||||
* @param file File that the assertion is being made from.
|
||||
* @param line Line that the assertion is being made from.
|
||||
* @param pointer Pointer to assert is not a null pointer.
|
||||
* @param message Message to throw against assertion failure.
|
||||
*/
|
||||
void assertNotNullImpl(
|
||||
const char *file,
|
||||
const int32_t line,
|
||||
const void *pointer,
|
||||
const char *message
|
||||
);
|
||||
|
||||
/**
|
||||
* Asserts a given pointer to be a nullptr.
|
||||
*
|
||||
* @param file File that the assertion is being made from.
|
||||
* @param line Line that the assertion is being made from.
|
||||
* @param pointer Pointer to assert is nullptr.
|
||||
* @param message Message to throw against assertion failure.
|
||||
*/
|
||||
void assertNullImpl(
|
||||
const char *file,
|
||||
const int32_t line,
|
||||
const void *pointer,
|
||||
const char *message
|
||||
);
|
||||
|
||||
/**
|
||||
* Asserts a function as being deprecated.
|
||||
*
|
||||
* @param file File that the assertion is being made from.
|
||||
* @param line Line that the assertion is being made from.
|
||||
* @param message Message to throw against assertion failure.
|
||||
*/
|
||||
void assertDeprecatedImpl(
|
||||
const char *file,
|
||||
const int32_t line,
|
||||
const char *message
|
||||
);
|
||||
|
||||
void assertMemoryRangeMatchesImpl(
|
||||
const char *file,
|
||||
const int32_t line,
|
||||
const void *start,
|
||||
const void *end,
|
||||
const size_t size,
|
||||
const char *message
|
||||
);
|
||||
|
||||
#define assertTrue(x, message) \
|
||||
assertTrueImpl(__FILE__, __LINE__, x, message)
|
||||
|
||||
#define assertFalse(x, message) \
|
||||
assertFalseImpl(__FILE__, __LINE__, x, message)
|
||||
|
||||
#define assertUnreachable(message) \
|
||||
assertUnreachableImpl(__FILE__, __LINE__, message)
|
||||
|
||||
#define assertNotNull(pointer, message) \
|
||||
assertNotNullImpl(__FILE__, __LINE__, pointer, message)
|
||||
|
||||
#define assertNull(pointer, message) \
|
||||
assertNullImpl(__FILE__, __LINE__, pointer, message)
|
||||
|
||||
#define assertDeprecated(message) \
|
||||
assertDeprecatedImpl(__FILE__, __LINE__, message)
|
||||
|
||||
#define assertStrLenMax(str, len, message) \
|
||||
assertTrue(strlen(str) < len, message)
|
||||
|
||||
#define assertStrLenMin(str, len, message) \
|
||||
assertTrue(strlen(str) >= len, message)
|
||||
|
||||
#else
|
||||
// If assertions are faked, we define the macros to do nothing.
|
||||
#define assertTrue(x, message) ((void)0)
|
||||
#define assertFalse(x, message) ((void)0)
|
||||
#define assertUnreachable(message) ((void)0)
|
||||
#define assertNotNull(pointer, message) ((void)0)
|
||||
#define assertNull(pointer, message) ((void)0)
|
||||
#define assertDeprecated(message) ((void)0)
|
||||
#define assertStrLenMax(str, len, message) ((void)0)
|
||||
#define assertStrLenMin(str, len, message) ((void)0)
|
||||
|
||||
#endif
|
||||
@@ -1,15 +0,0 @@
|
||||
# Copyright (c) 2025 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Sources
|
||||
target_sources(${DUSK_TARGET_NAME}
|
||||
PRIVATE
|
||||
console.c
|
||||
consolecmd.c
|
||||
consolevar.c
|
||||
)
|
||||
|
||||
# Subdirectories
|
||||
add_subdirectory(cmd)
|
||||
@@ -1,18 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "console/console.h"
|
||||
|
||||
void cmdEcho(const consolecmdexec_t *exec) {
|
||||
assertTrue(
|
||||
exec->argc >= 1,
|
||||
"echo command requires 1 argument."
|
||||
);
|
||||
|
||||
consolePrint("%s", exec->argv[0]);
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "console/console.h"
|
||||
|
||||
void cmdGet(const consolecmdexec_t *exec) {
|
||||
assertTrue(
|
||||
exec->argc >= 1,
|
||||
"Get command requires 1 argument."
|
||||
);
|
||||
|
||||
for(uint32_t i = 0; i < CONSOLE.variableCount; i++) {
|
||||
consolevar_t *var = &CONSOLE.variables[i];
|
||||
if(stringCompare(var->name, exec->argv[0]) != 0) continue;
|
||||
consolePrint("%s", var->value);
|
||||
return;
|
||||
}
|
||||
|
||||
consolePrint("Error: Variable '%s' not found.", exec->argv[0]);
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "console/console.h"
|
||||
#include "game.h"
|
||||
|
||||
void cmdQuit(const consolecmdexec_t *exec) {
|
||||
consolePrint("Quitting application...");
|
||||
GAME.running = false;
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "console/console.h"
|
||||
|
||||
void cmdSet(const consolecmdexec_t *exec) {
|
||||
assertTrue(exec->argc >= 2, "set command requires 2 arguments.");
|
||||
|
||||
for(uint32_t i = 0; i < CONSOLE.variableCount; i++) {
|
||||
consolevar_t *var = &CONSOLE.variables[i];
|
||||
if(stringCompare(var->name, exec->argv[0]) != 0) continue;
|
||||
consoleVarSetValue(var, exec->argv[1]);
|
||||
consolePrint("%s %s", var->name, var->value);
|
||||
for(i = 0; i < var->eventCount; i++) {
|
||||
assertNotNull(var->events[i], "Event is NULL");
|
||||
var->events[i](var);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
consolePrint("Error: Variable '%s' not found.", exec->argv[0]);
|
||||
}
|
||||
@@ -1,329 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "console.h"
|
||||
#include "assert/assert.h"
|
||||
#include "util/memory.h"
|
||||
#include "util/string.h"
|
||||
#include "console/cmd/cmdquit.h"
|
||||
#include "console/cmd/cmdecho.h"
|
||||
#include "console/cmd/cmdset.h"
|
||||
#include "console/cmd/cmdget.h"
|
||||
|
||||
#include "input.h"
|
||||
|
||||
console_t CONSOLE;
|
||||
|
||||
void consoleInit() {
|
||||
memoryZero(&CONSOLE, sizeof(console_t));
|
||||
|
||||
// Register the get and set command.
|
||||
CONSOLE.cmdGet = consoleRegCmd("get", cmdGet);
|
||||
CONSOLE.cmdSet = consoleRegCmd("set", cmdSet);
|
||||
consoleRegCmd("quit", cmdQuit);
|
||||
consoleRegCmd("echo", cmdEcho);
|
||||
|
||||
consolePrint(" = Dawn Console = ");
|
||||
}
|
||||
|
||||
consolecmd_t * consoleRegCmd(const char_t *name, consolecmdfunc_t function) {
|
||||
consolecmd_t *cmd = &CONSOLE.commands[CONSOLE.commandCount++];
|
||||
consoleCmdInit(cmd, name, function);
|
||||
return cmd;
|
||||
}
|
||||
|
||||
consolevar_t * consoleRegVar(
|
||||
const char_t *name,
|
||||
const char_t *value,
|
||||
consolevarchanged_t event
|
||||
) {
|
||||
consolevar_t *var = &CONSOLE.variables[CONSOLE.variableCount++];
|
||||
consoleVarInitListener(var, name, value, event);
|
||||
return var;
|
||||
}
|
||||
|
||||
void consolePrint(const char_t *message, ...) {
|
||||
char_t buffer[CONSOLE_LINE_MAX];
|
||||
|
||||
va_list args;
|
||||
va_start(args, message);
|
||||
int32_t len = stringFormatVA(buffer, CONSOLE_LINE_MAX, message, args);
|
||||
va_end(args);
|
||||
|
||||
// Move all lines back
|
||||
memoryMove(
|
||||
CONSOLE.line[0],
|
||||
CONSOLE.line[1],
|
||||
(CONSOLE_HISTORY_MAX - 1) * CONSOLE_LINE_MAX
|
||||
);
|
||||
|
||||
// Copy the new line
|
||||
memoryCopy(
|
||||
CONSOLE.line[CONSOLE_HISTORY_MAX - 1],
|
||||
buffer,
|
||||
len + 1
|
||||
);
|
||||
printf("%s\n", buffer);
|
||||
}
|
||||
|
||||
void consoleExec(const char_t *line) {
|
||||
assertNotNull(line, "line must not be NULL");
|
||||
assertTrue(
|
||||
CONSOLE.execBufferCount < CONSOLE_EXEC_BUFFER_MAX,
|
||||
"Too many commands in the buffer."
|
||||
);
|
||||
|
||||
char_t buffer[CONSOLE_LINE_MAX];
|
||||
size_t i = 0, j = 0;
|
||||
char_t c;
|
||||
consoleexecstate_t state = CONSOLE_EXEC_STATE_INITIAL;
|
||||
consolecmdexec_t *exec = NULL;
|
||||
|
||||
while(state != CONSOLE_EXEC_STATE_FULLY_PARSED) {
|
||||
c = line[i];
|
||||
|
||||
switch(state) {
|
||||
case CONSOLE_EXEC_STATE_INITIAL:
|
||||
assertTrue(j == 0, "Buffer not empty?");
|
||||
|
||||
if(c == '\0') {
|
||||
state = CONSOLE_EXEC_STATE_FULLY_PARSED;
|
||||
break;
|
||||
}
|
||||
|
||||
if(stringIsWhitespace(c) || c == ';') {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
state = CONSOLE_EXEC_STATE_PARSE_CMD;
|
||||
break;
|
||||
|
||||
case CONSOLE_EXEC_STATE_PARSE_CMD:
|
||||
if(stringIsWhitespace(c) || c == '\0' || c == ';') {
|
||||
state = CONSOLE_EXEC_STATE_CMD_PARSED;
|
||||
continue;
|
||||
}
|
||||
|
||||
if(c == '"') {
|
||||
// Can't handle quotes within the command.
|
||||
consolePrint("Invalid command");
|
||||
while(c != '\0' && c != ';') c = line[++i];
|
||||
continue;
|
||||
}
|
||||
|
||||
buffer[j++] = c;
|
||||
i++;
|
||||
|
||||
if(j >= CONSOLE_LINE_MAX) {
|
||||
consolePrint("Command too long");
|
||||
state = CONSOLE_EXEC_STATE_FULLY_PARSED;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
|
||||
case CONSOLE_EXEC_STATE_CMD_PARSED:
|
||||
if(j == 0) {
|
||||
state = CONSOLE_EXEC_STATE_INITIAL;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Create exec
|
||||
assertNull(exec, "Existing command parsing?");
|
||||
|
||||
exec = &CONSOLE.execBuffer[CONSOLE.execBufferCount];
|
||||
memoryZero(exec, sizeof(consolecmdexec_t));
|
||||
|
||||
buffer[j] = '\0';
|
||||
stringCopy(exec->command, buffer, CONSOLE_LINE_MAX);
|
||||
state = CONSOLE_EXEC_STATE_FIND_ARG;
|
||||
|
||||
j = 0;// Free up buffer
|
||||
break;
|
||||
|
||||
case CONSOLE_EXEC_STATE_FIND_ARG:
|
||||
if(c == '\0' || c == ';') {
|
||||
state = CONSOLE_EXEC_STATE_CMD_FINISHED;
|
||||
continue;
|
||||
}
|
||||
|
||||
if(stringIsWhitespace(c)) {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if(c == '"') {
|
||||
state = CONSOLE_EXEC_STATE_PARSE_ARG_QUOTED;
|
||||
i++;
|
||||
} else {
|
||||
state = CONSOLE_EXEC_STATE_PARSE_ARG;
|
||||
}
|
||||
break;
|
||||
|
||||
case CONSOLE_EXEC_STATE_PARSE_ARG:
|
||||
if(stringIsWhitespace(c) || c == '\0' || c == ';') {
|
||||
state = CONSOLE_EXEC_STATE_ARG_PARSED;
|
||||
continue;
|
||||
}
|
||||
|
||||
buffer[j++] = c;
|
||||
i++;
|
||||
|
||||
if(j >= CONSOLE_LINE_MAX) {
|
||||
consolePrint("Arg too long");
|
||||
state = CONSOLE_EXEC_STATE_FULLY_PARSED;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
|
||||
case CONSOLE_EXEC_STATE_PARSE_ARG_QUOTED:
|
||||
if(c == '"') {
|
||||
state = CONSOLE_EXEC_STATE_ARG_PARSED;
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if(c == '\0' || c == ';') {
|
||||
consolePrint("Unterminated quote");
|
||||
state = CONSOLE_EXEC_STATE_FULLY_PARSED;
|
||||
continue;
|
||||
}
|
||||
|
||||
if(c == '\\') {
|
||||
c = line[++i];
|
||||
|
||||
if(c == '\0' || c == ';') {
|
||||
consolePrint("Unterminated quote");
|
||||
state = CONSOLE_EXEC_STATE_FULLY_PARSED;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
buffer[j++] = c;
|
||||
i++;
|
||||
|
||||
if(j >= CONSOLE_LINE_MAX) {
|
||||
consolePrint("Arg too long");
|
||||
state = CONSOLE_EXEC_STATE_FULLY_PARSED;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
|
||||
case CONSOLE_EXEC_STATE_ARG_PARSED:
|
||||
buffer[j] = '\0';
|
||||
stringCopy(exec->argv[exec->argc++], buffer, CONSOLE_LINE_MAX);
|
||||
state = CONSOLE_EXEC_STATE_FIND_ARG;
|
||||
j = 0;// Free up buffer
|
||||
break;
|
||||
|
||||
case CONSOLE_EXEC_STATE_CMD_FINISHED:
|
||||
assertNotNull(exec, "No command found?");
|
||||
|
||||
// Now, is there a command that matches?
|
||||
for(uint32_t k = 0; k < CONSOLE.commandCount; k++) {
|
||||
consolecmd_t *cmd = &CONSOLE.commands[k];
|
||||
if(stringCompare(cmd->name, exec->command) != 0) continue;
|
||||
exec->cmd = cmd;
|
||||
break;
|
||||
}
|
||||
|
||||
if(exec->cmd == NULL) {
|
||||
// Command wasn't found, is there a variable that matches?
|
||||
for(uint32_t k = 0; k < CONSOLE.variableCount; k++) {
|
||||
consolevar_t *var = &CONSOLE.variables[k];
|
||||
if(stringCompare(var->name, exec->command) != 0) continue;
|
||||
|
||||
// Matching variable found, is this a GET or a SET?
|
||||
if(exec->argc == 0) {
|
||||
exec->cmd = CONSOLE.cmdGet;
|
||||
stringCopy(exec->argv[0], exec->command, CONSOLE_LINE_MAX);
|
||||
exec->argc = 1;
|
||||
} else {
|
||||
exec->cmd = CONSOLE.cmdSet;
|
||||
stringCopy(exec->argv[1], exec->argv[0], CONSOLE_LINE_MAX);
|
||||
stringCopy(exec->argv[0], exec->command, CONSOLE_LINE_MAX);
|
||||
exec->argc = 2;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if(exec->cmd == NULL) {
|
||||
consolePrint("Command not found", exec->command);
|
||||
exec = NULL;
|
||||
state = CONSOLE_EXEC_STATE_INITIAL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Prep for next command.
|
||||
exec = NULL;
|
||||
state = CONSOLE_EXEC_STATE_INITIAL;
|
||||
CONSOLE.execBufferCount++;
|
||||
break;
|
||||
|
||||
default:
|
||||
assertUnreachable("Invalid state.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// May move these later
|
||||
void consoleUpdate() {
|
||||
if(inputPressed(INPUT_BIND_CONSOLE)) {
|
||||
CONSOLE.visible = !CONSOLE.visible;
|
||||
if(CONSOLE.visible) {
|
||||
consolePrint("Console opened.");
|
||||
} else {
|
||||
consolePrint("Console closed.");
|
||||
}
|
||||
}
|
||||
|
||||
for(uint32_t i = 0; i < CONSOLE.execBufferCount; i++) {
|
||||
consolecmdexec_t *exec = &CONSOLE.execBuffer[i];
|
||||
assertNotNull(exec->cmd, "Command execution has no command.");
|
||||
exec->cmd->function(exec);
|
||||
}
|
||||
|
||||
// #if KEYBOARD_SUPPORT == 1
|
||||
// uint8_t key;
|
||||
// while((key = inputKeyboardPop()) != 0) {
|
||||
// printf("Key pressed: %c\n", key);
|
||||
// switch(key) {
|
||||
// case 0:
|
||||
// break;
|
||||
|
||||
// case INPUT_KEY_ENTER:
|
||||
// consoleExec(CONSOLE.inputBuffer);
|
||||
// CONSOLE.inputIndex = 0;
|
||||
// CONSOLE.inputBuffer[0] = '\0';
|
||||
// break;
|
||||
|
||||
// case INPUT_KEY_BACKSPACE:
|
||||
// if(CONSOLE.inputIndex > 0) {
|
||||
// CONSOLE.inputIndex--;
|
||||
// CONSOLE.inputBuffer[CONSOLE.inputIndex] = '\0';
|
||||
// }
|
||||
// break;
|
||||
|
||||
// default:
|
||||
// if(
|
||||
// key >= INPUT_KEY_ASCII_START && key <= INPUT_KEY_ASCII_END &&
|
||||
// CONSOLE.inputIndex < CONSOLE_LINE_MAX - 1
|
||||
// ) {
|
||||
// CONSOLE.inputBuffer[CONSOLE.inputIndex++] = key;
|
||||
// CONSOLE.inputBuffer[CONSOLE.inputIndex] = '\0';
|
||||
// }
|
||||
// break;
|
||||
|
||||
// }
|
||||
// }
|
||||
// #endif
|
||||
|
||||
// Clear the exec buffer
|
||||
CONSOLE.execBufferCount = 0;
|
||||
}
|
||||
@@ -1,106 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "consolevar.h"
|
||||
#include "consolecmd.h"
|
||||
|
||||
typedef enum {
|
||||
CONSOLE_EXEC_STATE_INITIAL,
|
||||
CONSOLE_EXEC_STATE_PARSE_CMD,
|
||||
CONSOLE_EXEC_STATE_CMD_PARSED,
|
||||
|
||||
CONSOLE_EXEC_STATE_FIND_ARG,
|
||||
CONSOLE_EXEC_STATE_PARSE_ARG,
|
||||
CONSOLE_EXEC_STATE_PARSE_ARG_QUOTED,
|
||||
CONSOLE_EXEC_STATE_ARG_PARSED,
|
||||
|
||||
CONSOLE_EXEC_STATE_CMD_FINISHED,
|
||||
CONSOLE_EXEC_STATE_FULLY_PARSED
|
||||
} consoleexecstate_t;
|
||||
|
||||
typedef struct {
|
||||
consolecmd_t commands[CONSOLE_COMMANDS_MAX];
|
||||
uint32_t commandCount;
|
||||
|
||||
consolevar_t variables[CONSOLE_VARIABLES_MAX];
|
||||
uint32_t variableCount;
|
||||
|
||||
char_t line[CONSOLE_HISTORY_MAX][CONSOLE_LINE_MAX];
|
||||
|
||||
consolecmdexec_t execBuffer[CONSOLE_EXEC_BUFFER_MAX];
|
||||
uint32_t execBufferCount;
|
||||
|
||||
consolecmd_t *cmdGet;
|
||||
consolecmd_t *cmdSet;
|
||||
|
||||
bool_t visible;
|
||||
|
||||
// May move these later
|
||||
// #if KEYBOARD_SUPPORT == 1
|
||||
// char_t inputBuffer[CONSOLE_LINE_MAX];
|
||||
// int32_t inputIndex;
|
||||
// #endif
|
||||
} console_t;
|
||||
|
||||
extern console_t CONSOLE;
|
||||
|
||||
/**
|
||||
* Initializes the console.
|
||||
*/
|
||||
void consoleInit();
|
||||
|
||||
/**
|
||||
* Registers a console command.
|
||||
*
|
||||
* @param name The name of the command.
|
||||
* @param function The function to execute when the command is called.
|
||||
* @return The registered command.
|
||||
*/
|
||||
consolecmd_t * consoleRegCmd(const char_t *name, consolecmdfunc_t function);
|
||||
|
||||
/**
|
||||
* Registers a console variable.
|
||||
*
|
||||
* @param name The name of the variable.
|
||||
* @param value The initial value of the variable.
|
||||
* @param event The event to register.
|
||||
* @return The registered variable.
|
||||
*/
|
||||
consolevar_t * consoleRegVar(
|
||||
const char_t *name,
|
||||
const char_t *value,
|
||||
consolevarchanged_t event
|
||||
);
|
||||
|
||||
/**
|
||||
* Sets the value of a console variable.
|
||||
*
|
||||
* @param name The name of the variable.
|
||||
* @param value The new value of the variable.
|
||||
*/
|
||||
void consolePrint(
|
||||
const char_t *message,
|
||||
...
|
||||
);
|
||||
|
||||
/**
|
||||
* Executes a console command.
|
||||
*
|
||||
* @param line The line to execute.
|
||||
*/
|
||||
void consoleExec(const char_t *line);
|
||||
|
||||
/**
|
||||
* Processes the console's pending commands.
|
||||
*/
|
||||
void consoleUpdate();
|
||||
|
||||
void cmdGet(const consolecmdexec_t *exec);
|
||||
void cmdSet(const consolecmdexec_t *exec);
|
||||
void cmdEcho(const consolecmdexec_t *exec);
|
||||
void cmdQuit(const consolecmdexec_t *exec);
|
||||
@@ -1,27 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "consolecmd.h"
|
||||
#include "assert/assert.h"
|
||||
#include "util/memory.h"
|
||||
#include "util/string.h"
|
||||
|
||||
void consoleCmdInit(
|
||||
consolecmd_t *cmd,
|
||||
const char_t *name,
|
||||
consolecmdfunc_t function
|
||||
) {
|
||||
assertNotNull(cmd, "Command is NULL.");
|
||||
assertNotNull(name, "Name is NULL.");
|
||||
assertNotNull(function, "Function is NULL.");
|
||||
assertStrLenMin(name, 1, "Name is empty.");
|
||||
assertStrLenMax(name, CONSOLE_CMD_NAME_MAX, "Name is too long.");
|
||||
|
||||
memoryZero(cmd, sizeof(consolecmd_t));
|
||||
stringCopy(cmd->name, name, CONSOLE_CMD_NAME_MAX);
|
||||
cmd->function = function;
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "dusk.h"
|
||||
#include "consoledefs.h"
|
||||
|
||||
typedef struct consolecmd_s consolecmd_t;
|
||||
|
||||
typedef struct {
|
||||
consolecmd_t *cmd;
|
||||
char_t command[CONSOLE_LINE_MAX];
|
||||
char_t argv[CONSOLE_CMD_ARGC_MAX][CONSOLE_LINE_MAX];
|
||||
uint32_t argc;
|
||||
} consolecmdexec_t;
|
||||
|
||||
typedef void (*consolecmdfunc_t)(const consolecmdexec_t *exec);
|
||||
|
||||
typedef struct consolecmd_s {
|
||||
char_t name[CONSOLE_CMD_NAME_MAX];
|
||||
consolecmdfunc_t function;
|
||||
} consolecmd_t;
|
||||
|
||||
/**
|
||||
* Initializes a console command.
|
||||
*
|
||||
* @param cmd Pointer to the console command.
|
||||
* @param name The name of the command.
|
||||
* @param function The function to execute when the command is called.
|
||||
*/
|
||||
void consoleCmdInit(
|
||||
consolecmd_t *cmd,
|
||||
const char_t *name,
|
||||
consolecmdfunc_t function
|
||||
);
|
||||
@@ -1,21 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#define CONSOLE_CMD_NAME_MAX 32
|
||||
#define CONSOLE_CMD_ARGC_MAX 16
|
||||
|
||||
#define CONSOLE_COMMANDS_MAX 128
|
||||
#define CONSOLE_VARIABLES_MAX 128
|
||||
#define CONSOLE_LINE_MAX 256
|
||||
#define CONSOLE_HISTORY_MAX 32
|
||||
#define CONSOLE_EXEC_BUFFER_MAX 16
|
||||
|
||||
#define CONSOLE_VAR_NAME_MAX 32
|
||||
#define CONSOLE_VAR_VALUE_MAX 128
|
||||
#define CONSOLE_VAR_EVENTS_MAX 8
|
||||
@@ -1,64 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "consolevar.h"
|
||||
#include "assert/assert.h"
|
||||
#include "util/memory.h"
|
||||
#include "util/string.h"
|
||||
|
||||
void consoleVarInit(
|
||||
consolevar_t *var,
|
||||
const char_t *name,
|
||||
const char_t *value
|
||||
) {
|
||||
assertNotNull(var, "var must not be NULL");
|
||||
assertNotNull(name, "name must not be NULL");
|
||||
assertNotNull(value, "value must not be NULL");
|
||||
|
||||
assertStrLenMin(name, 1, "name must not be empty");
|
||||
assertStrLenMax(name, CONSOLE_VAR_NAME_MAX, "name is too long");
|
||||
assertStrLenMax(value, CONSOLE_VAR_VALUE_MAX, "value is too long");
|
||||
|
||||
memoryZero(var, sizeof(consolevar_t));
|
||||
stringCopy(var->name, name, CONSOLE_VAR_NAME_MAX);
|
||||
stringCopy(var->value, value, CONSOLE_VAR_VALUE_MAX);
|
||||
}
|
||||
|
||||
void consoleVarInitListener(
|
||||
consolevar_t *var,
|
||||
const char_t *name,
|
||||
const char_t *value,
|
||||
consolevarchanged_t event
|
||||
) {
|
||||
consoleVarInit(var, name, value);
|
||||
if(event) consoleVarListen(var, event);
|
||||
}
|
||||
|
||||
void consoleVarSetValue(consolevar_t *var, const char_t *value) {
|
||||
assertNotNull(var, "var must not be NULL");
|
||||
assertNotNull(value, "value must not be NULL");
|
||||
assertStrLenMax(value, CONSOLE_VAR_VALUE_MAX, "value is too long");
|
||||
|
||||
stringCopy(var->value, value, CONSOLE_VAR_VALUE_MAX);
|
||||
|
||||
uint8_t i = 0;
|
||||
while (i < var->eventCount) {
|
||||
var->events[i](var);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
void consoleVarListen(consolevar_t *var, consolevarchanged_t event) {
|
||||
assertNotNull(var, "var must not be NULL");
|
||||
assertNotNull(event, "event must not be NULL");
|
||||
assertTrue(
|
||||
var->eventCount < CONSOLE_VAR_EVENTS_MAX,
|
||||
"Event count is too high"
|
||||
);
|
||||
var->events[var->eventCount++] = event;
|
||||
}
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "dusk.h"
|
||||
#include "consoledefs.h"
|
||||
|
||||
typedef struct consolevar_s consolevar_t;
|
||||
|
||||
typedef void (*consolevarchanged_t)(const consolevar_t *var);
|
||||
|
||||
typedef struct consolevar_s {
|
||||
char_t name[CONSOLE_VAR_NAME_MAX];
|
||||
char_t value[CONSOLE_VAR_VALUE_MAX];
|
||||
consolevarchanged_t events[CONSOLE_VAR_EVENTS_MAX];
|
||||
uint8_t eventCount;
|
||||
} consolevar_t;
|
||||
|
||||
/**
|
||||
* Initializes a console variable.
|
||||
*
|
||||
* @param var Pointer to the console variable.
|
||||
* @param name The name of the variable.
|
||||
* @param value The initial value of the variable.
|
||||
*/
|
||||
void consoleVarInit(
|
||||
consolevar_t *var,
|
||||
const char_t *name,
|
||||
const char_t *value
|
||||
);
|
||||
|
||||
/**
|
||||
* Initializes a console variable with a listener.
|
||||
*
|
||||
* @param var Pointer to the console variable.
|
||||
* @param name The name of the variable.
|
||||
* @param value The initial value of the variable.
|
||||
* @param event The event to register.
|
||||
*/
|
||||
void consoleVarInitListener(
|
||||
consolevar_t *var,
|
||||
const char_t *name,
|
||||
const char_t *value,
|
||||
consolevarchanged_t event
|
||||
);
|
||||
|
||||
/**
|
||||
* Sets the value of a console variable.
|
||||
*
|
||||
* @param var Pointer to the console variable.
|
||||
* @param value The new value of the variable.
|
||||
*/
|
||||
void consoleVarSetValue(consolevar_t *var, const char_t *value);
|
||||
|
||||
/**
|
||||
* Registers an event to be called when the value of a console variable changes.
|
||||
*
|
||||
* @param var Pointer to the console variable.
|
||||
* @param event The event to register.
|
||||
*/
|
||||
void consoleVarListen(consolevar_t *var, consolevarchanged_t event);
|
||||
@@ -1,31 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "error/error.h"
|
||||
|
||||
#ifndef RENDER_WIDTH
|
||||
#define RENDER_WIDTH 320
|
||||
#endif
|
||||
#ifndef RENDER_HEIGHT
|
||||
#define RENDER_HEIGHT 240
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Initializes the rendering system.
|
||||
*/
|
||||
errorret_t renderInit(void);
|
||||
|
||||
/**
|
||||
* Tells the rendering system to actually draw the frame.
|
||||
*/
|
||||
errorret_t renderDraw(void);
|
||||
|
||||
/**
|
||||
* Disposes of the rendering system.
|
||||
*/
|
||||
errorret_t renderDispose(void);
|
||||
@@ -1,51 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "scene.h"
|
||||
#include "world/overworld.h"
|
||||
|
||||
scene_t SCENE_CURRENT;
|
||||
scenecallback_t SCENE_CALLBACKS[SCENE_COUNT] = {
|
||||
[SCENE_INITIAL] = {
|
||||
.init = NULL,
|
||||
.update = NULL
|
||||
},
|
||||
|
||||
[SCENE_OVERWORLD] = {
|
||||
.init = overworldInit,
|
||||
.update = overworldUpdate,
|
||||
.dispose = NULL
|
||||
}
|
||||
};
|
||||
|
||||
void sceneInit(void) {
|
||||
for(uint8_t i = 0; i < SCENE_COUNT; i++) {
|
||||
if(SCENE_CALLBACKS[i].init) {
|
||||
SCENE_CALLBACKS[i].init();
|
||||
}
|
||||
}
|
||||
|
||||
SCENE_CURRENT = SCENE_OVERWORLD;
|
||||
}
|
||||
|
||||
void sceneSet(const scene_t scene) {
|
||||
SCENE_CURRENT = scene;
|
||||
}
|
||||
|
||||
void sceneUpdate(void) {
|
||||
if(SCENE_CALLBACKS[SCENE_CURRENT].update) {
|
||||
SCENE_CALLBACKS[SCENE_CURRENT].update();
|
||||
}
|
||||
}
|
||||
|
||||
void sceneDispose(void) {
|
||||
for(uint8_t i = 0; i < SCENE_COUNT; i++) {
|
||||
if(SCENE_CALLBACKS[i].dispose) {
|
||||
SCENE_CALLBACKS[i].dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "dusk.h"
|
||||
|
||||
typedef enum {
|
||||
SCENE_INITIAL,
|
||||
SCENE_OVERWORLD,
|
||||
|
||||
SCENE_COUNT
|
||||
} scene_t;
|
||||
|
||||
typedef struct {
|
||||
void (*init)(void);
|
||||
void (*update)(void);
|
||||
void (*dispose)(void);
|
||||
} scenecallback_t;
|
||||
|
||||
extern scene_t SCENE_CURRENT;
|
||||
extern scenecallback_t SCENE_CALLBACKS[SCENE_COUNT];
|
||||
|
||||
/**
|
||||
* Initializes the scene module.
|
||||
*/
|
||||
void sceneInit(void);
|
||||
|
||||
/**
|
||||
* Sets the current scene.
|
||||
*
|
||||
* @param scene The scene to set.
|
||||
*/
|
||||
void sceneSet(const scene_t scene);
|
||||
|
||||
/**
|
||||
* Updates the current scene.
|
||||
*/
|
||||
void sceneUpdate(void);
|
||||
|
||||
/**
|
||||
* Disposes of the current scene.
|
||||
*/
|
||||
void sceneDispose(void);
|
||||
@@ -1,23 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <errno.h>
|
||||
#include <ctype.h>
|
||||
#include <stdarg.h>
|
||||
#include <float.h>
|
||||
|
||||
typedef bool bool_t;
|
||||
typedef int int_t;
|
||||
typedef float float_t;
|
||||
typedef char char_t;
|
||||
@@ -1,13 +0,0 @@
|
||||
# Copyright (c) 2025 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Sources
|
||||
target_sources(${DUSK_TARGET_NAME}
|
||||
PRIVATE
|
||||
direction.c
|
||||
entity.c
|
||||
player.c
|
||||
npc.c
|
||||
)
|
||||
@@ -1,53 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "direction.h"
|
||||
#include "assert/assert.h"
|
||||
|
||||
float_t directionToAngle(const direction_t dir) {
|
||||
switch(dir) {
|
||||
case DIRECTION_NORTH: return (M_PI_2);
|
||||
case DIRECTION_SOUTH: return -(M_PI_2);
|
||||
case DIRECTION_EAST: return 0;
|
||||
case DIRECTION_WEST: return (M_PI);
|
||||
default: return 0; // Should never happen
|
||||
}
|
||||
}
|
||||
|
||||
void directionGetCoordinates(
|
||||
const direction_t dir,
|
||||
int8_t *x, int8_t *y
|
||||
) {
|
||||
assertNotNull(x, "X coordinate pointer cannot be NULL");
|
||||
assertNotNull(y, "Y coordinate pointer cannot be NULL");
|
||||
|
||||
switch(dir) {
|
||||
case DIRECTION_NORTH:
|
||||
*x = 0;
|
||||
*y = -1;
|
||||
break;
|
||||
|
||||
case DIRECTION_SOUTH:
|
||||
*x = 0;
|
||||
*y = 1;
|
||||
break;
|
||||
|
||||
case DIRECTION_EAST:
|
||||
*x = 1;
|
||||
*y = 0;
|
||||
break;
|
||||
|
||||
case DIRECTION_WEST:
|
||||
*x = -1;
|
||||
*y = 0;
|
||||
break;
|
||||
|
||||
default:
|
||||
assertUnreachable("Invalid direction");
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "dusk.h"
|
||||
|
||||
typedef enum {
|
||||
DIRECTION_SOUTH = 0,
|
||||
DIRECTION_EAST = 1,
|
||||
DIRECTION_WEST = 2,
|
||||
DIRECTION_NORTH = 3,
|
||||
|
||||
DIRECTION_UP = DIRECTION_NORTH,
|
||||
DIRECTION_DOWN = DIRECTION_SOUTH,
|
||||
DIRECTION_LEFT = DIRECTION_WEST,
|
||||
DIRECTION_RIGHT = DIRECTION_EAST,
|
||||
} direction_t;
|
||||
|
||||
/**
|
||||
* Converts a direction to an angle in float_t format.
|
||||
*
|
||||
* @param dir The direction to convert.
|
||||
* @return The angle corresponding to the direction.
|
||||
*/
|
||||
float_t directionToAngle(const direction_t dir);
|
||||
|
||||
/**
|
||||
* Gets the relative coordinates for a given direction.
|
||||
*
|
||||
* @param dir The direction to get coordinates for.
|
||||
* @param x Pointer to store the x coordinate.
|
||||
* @param y Pointer to store the y coordinate.
|
||||
*/
|
||||
void directionGetCoordinates(
|
||||
const direction_t dir,
|
||||
int8_t *x, int8_t *y
|
||||
);
|
||||
@@ -1,131 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "entity.h"
|
||||
#include "assert/assert.h"
|
||||
#include "util/memory.h"
|
||||
#include "world/world.h"
|
||||
#include "world/tiledata.h"
|
||||
#include "time.h"
|
||||
|
||||
entity_t ENTITIES[ENTITY_COUNT_MAX] = {0};
|
||||
|
||||
entitycallback_t ENTITY_CALLBACKS[ENTITY_TYPE_COUNT] = {
|
||||
{NULL}, // ENTITY_TYPE_NULL
|
||||
{
|
||||
.load = playerEntityLoad,
|
||||
.update = playerEntityUpdate,
|
||||
},
|
||||
{
|
||||
.load = npcLoad,
|
||||
.update = npcUpdate,
|
||||
.interact = npcInteract,
|
||||
},
|
||||
};
|
||||
|
||||
void entityLoad(entity_t *entity, const entity_t *source) {
|
||||
assertNotNull(entity, "Entity pointer cannot be NULL");
|
||||
assertNotNull(source, "Source entity pointer cannot be NULL");
|
||||
assertTrue(source->type != ENTITY_TYPE_NULL, "Source entity type NULL");
|
||||
assertTrue(source->type < ENTITY_TYPE_COUNT, "Source entity type bad");
|
||||
assertNotNull(
|
||||
ENTITY_CALLBACKS[source->type].load,
|
||||
"Entity type has no i nit callback"
|
||||
);
|
||||
|
||||
memoryZero(entity, sizeof(entity_t));
|
||||
|
||||
entity->type = source->type;
|
||||
entity->x = source->x;
|
||||
entity->y = source->y;
|
||||
entity->dir = source->dir;
|
||||
entity->id = source->id;
|
||||
|
||||
ENTITY_CALLBACKS[entity->type].load(entity, source);
|
||||
}
|
||||
|
||||
void entityUpdate(entity_t *entity) {
|
||||
assertNotNull(entity, "Entity pointer cannot be NULL");
|
||||
assertTrue(entity->type != ENTITY_TYPE_NULL, "Entity type NULL");
|
||||
assertTrue(entity->type < ENTITY_TYPE_COUNT, "Entity type out of bounds");
|
||||
assertNotNull(
|
||||
ENTITY_CALLBACKS[entity->type].update,
|
||||
"Entity type has no update callback"
|
||||
);
|
||||
|
||||
ENTITY_CALLBACKS[entity->type].update(entity);
|
||||
|
||||
if(entity->subX > 0) {
|
||||
entity->subX -= entity->moveSpeed;
|
||||
} else if(entity->subX < 0) {
|
||||
entity->subX += entity->moveSpeed;
|
||||
}
|
||||
|
||||
if(entity->subY > 0) {
|
||||
entity->subY -= entity->moveSpeed;
|
||||
} else if(entity->subY < 0) {
|
||||
entity->subY += entity->moveSpeed;
|
||||
}
|
||||
}
|
||||
|
||||
void entityMove(entity_t *entity, const uint8_t moveSpeed) {
|
||||
assertNotNull(entity, "Entity pointer cannot be NULL");
|
||||
assertTrue(entity->type != ENTITY_TYPE_NULL, "Entity type NULL");
|
||||
assertTrue(entity->type < ENTITY_TYPE_COUNT, "Entity type out of bounds");
|
||||
assertFalse(
|
||||
entityIsMoving(entity),
|
||||
"Entity is already moving, cannot move again"
|
||||
);
|
||||
|
||||
int8_t x = 0, y = 0;
|
||||
directionGetCoordinates(entity->dir, &x, &y);
|
||||
|
||||
// entity in way?
|
||||
entity_t *ent = entityGetAt(entity->x + x, entity->y + y);
|
||||
if(ent != NULL) return;
|
||||
|
||||
entity->x += x;
|
||||
entity->y += y;
|
||||
entity->subX = TILE_WIDTH_HEIGHT * -x;
|
||||
entity->subY = TILE_WIDTH_HEIGHT * -y;
|
||||
entity->moveSpeed = moveSpeed;
|
||||
}
|
||||
|
||||
void entityTurn(entity_t *entity, const direction_t dir) {
|
||||
assertNotNull(entity, "Entity pointer cannot be NULL");
|
||||
assertTrue(entity->type != ENTITY_TYPE_NULL, "Entity type NULL");
|
||||
assertTrue(entity->type < ENTITY_TYPE_COUNT, "Entity type out of bounds");
|
||||
assertTrue(
|
||||
dir >= DIRECTION_SOUTH && dir <= DIRECTION_NORTH, "Invalid direction"
|
||||
);
|
||||
assertFalse(
|
||||
entityIsMoving(entity), "Entity is already moving, cannot turn"
|
||||
);
|
||||
|
||||
entity->dir = dir;
|
||||
}
|
||||
|
||||
bool_t entityIsMoving(const entity_t *entity) {
|
||||
assertNotNull(entity, "Entity pointer cannot be NULL");
|
||||
assertTrue(entity->type != ENTITY_TYPE_NULL, "Entity type NULL");
|
||||
assertTrue(entity->type < ENTITY_TYPE_COUNT, "Entity type out of bounds");
|
||||
return entity->subX != 0 || entity->subY != 0;
|
||||
}
|
||||
|
||||
entity_t * entityGetAt(
|
||||
const uint32_t tileX,
|
||||
const uint32_t tileY
|
||||
) {
|
||||
entity_t *entity = ENTITIES;
|
||||
|
||||
do {
|
||||
if(entity->type == ENTITY_TYPE_NULL) continue;
|
||||
if(entity->x == tileX && entity->y == tileY) return entity;
|
||||
} while((entity++) < &ENTITIES[ENTITY_COUNT_MAX - 1]);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@@ -1,99 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "direction.h"
|
||||
#include "player.h"
|
||||
#include "npc.h"
|
||||
|
||||
#define ENTITY_COUNT_MAX 32
|
||||
#define ENTITY_TURN_DURATION 0.075f // Duration for turning in seconds
|
||||
#define ENTITY_MOVE_DURATION 0.1f // Duration for moving 1 tile, in seconds.
|
||||
|
||||
typedef enum {
|
||||
ENTITY_TYPE_NULL = 0,
|
||||
ENTITY_TYPE_PLAYER = 1,
|
||||
ENTITY_TYPE_NPC = 2,
|
||||
} entitytype_t;
|
||||
#define ENTITY_TYPE_COUNT 3
|
||||
|
||||
typedef struct _entity_t {
|
||||
uint32_t id;// Completely unique ID for this entity.
|
||||
uint32_t x, y;
|
||||
int8_t subX, subY;
|
||||
uint8_t moveSpeed;
|
||||
|
||||
entitytype_t type;
|
||||
direction_t dir;
|
||||
|
||||
|
||||
union {
|
||||
npc_t npc;
|
||||
playerentity_t player;
|
||||
};
|
||||
} entity_t;
|
||||
|
||||
typedef struct {
|
||||
void (*load) (entity_t *entity, const entity_t *source);
|
||||
void (*update) (entity_t *entity);
|
||||
void (*interact)(entity_t *player, entity_t *self);
|
||||
} entitycallback_t;
|
||||
|
||||
extern entity_t ENTITIES[ENTITY_COUNT_MAX];
|
||||
extern entitycallback_t ENTITY_CALLBACKS[ENTITY_TYPE_COUNT];
|
||||
|
||||
/**
|
||||
* Loads an entity from the generated entity data.
|
||||
*
|
||||
* @param entity Pointer to the entity to initialize.
|
||||
* @param source Pointer to the source entity data.
|
||||
*/
|
||||
void entityLoad(entity_t *entity, const entity_t *source);
|
||||
|
||||
/**
|
||||
* Updates the entity's state.
|
||||
*
|
||||
* @param entity Pointer to the entity to update.
|
||||
*/
|
||||
void entityUpdate(entity_t *entity);
|
||||
|
||||
/**
|
||||
* Moves the entity by the specified x and y offsets.
|
||||
*
|
||||
* @param entity Pointer to the entity to move.
|
||||
* @param moveSpeed The speed at which to move the entity.
|
||||
*/
|
||||
void entityMove(entity_t *entity, const uint8_t moveSpeed);
|
||||
|
||||
/**
|
||||
* Turns the entity to face the specified direction.
|
||||
*
|
||||
* @param entity Pointer to the entity to turn.
|
||||
* @param dir The direction to turn the entity to.
|
||||
*/
|
||||
void entityTurn(entity_t *entity, const direction_t dir);
|
||||
|
||||
/**
|
||||
* Returns whether or not an entity is currently moving.
|
||||
*
|
||||
* @param entity Pointer to the entity to check.
|
||||
* @return True if the entity is moving, false otherwise.
|
||||
*/
|
||||
bool_t entityIsMoving(const entity_t *entity);
|
||||
|
||||
/**
|
||||
* Gets the entity at the specified tile coordinates.
|
||||
*
|
||||
* @param tileX The x coordinate of the tile to get the entity from.
|
||||
* @param tileY The y coordinate of the tile to get the entity from.
|
||||
* @return Pointer to the entity at the specified coordinates, or NULL if no
|
||||
* entity exists there.
|
||||
*/
|
||||
entity_t *entityGetAt(
|
||||
const uint32_t tileX,
|
||||
const uint32_t tileY
|
||||
);
|
||||
@@ -1,45 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "entity.h"
|
||||
#include "ui/uitextbox.h"
|
||||
#include "locale/language.h"
|
||||
#include "assert/assert.h"
|
||||
|
||||
void npcLoad(entity_t *entity, const entity_t *source) {
|
||||
assertNotNull(entity, "Entity pointer cannot be NULL");
|
||||
assertNotNull(source, "Source entity pointer cannot be NULL");
|
||||
assertTrue(source->type == ENTITY_TYPE_NPC, "Source entity type must be NPC");
|
||||
|
||||
entity->npc = source->npc;
|
||||
}
|
||||
|
||||
void npcUpdate(entity_t *entity) {
|
||||
}
|
||||
|
||||
void npcInteract(entity_t *player, entity_t *self) {
|
||||
assertTrue(self->type == ENTITY_TYPE_NPC, "Entity must be of type NPC");
|
||||
|
||||
switch(self->npc.interactType) {
|
||||
case NPC_INTERACT_TYPE_NONE:
|
||||
break;
|
||||
|
||||
case NPC_INTERACT_TYPE_TEXT:
|
||||
uiTextboxSetText(languageGet(self->npc.text));
|
||||
break;
|
||||
|
||||
case NPC_INTERACT_TYPE_CONVO:
|
||||
break;
|
||||
|
||||
case NPC_INTERACT_TYPE_EVENT:
|
||||
eventSetActive(self->npc.eventData);
|
||||
break;
|
||||
|
||||
default:
|
||||
assertUnreachable("Unknown NPC interaction type");
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
|
||||
#pragma once
|
||||
#include "event/eventlist.h"
|
||||
|
||||
typedef struct _entity_t entity_t;
|
||||
|
||||
typedef enum {
|
||||
NPC_INTERACT_TYPE_NONE = 0,
|
||||
NPC_INTERACT_TYPE_TEXT = 1,
|
||||
NPC_INTERACT_TYPE_CONVO = 2,
|
||||
NPC_INTERACT_TYPE_EVENT = 3,
|
||||
} npcinteracttype_t;
|
||||
|
||||
typedef struct {
|
||||
npcinteracttype_t interactType;
|
||||
|
||||
union {
|
||||
const char_t* text;
|
||||
const eventdata_t *eventData;
|
||||
};
|
||||
} npc_t;
|
||||
|
||||
/**
|
||||
* Initializes the NPC entity.
|
||||
*
|
||||
* @param entity The entity to initialize.
|
||||
* @param source The source entity to copy data from.
|
||||
*/
|
||||
void npcLoad(entity_t *entity, const entity_t *source);
|
||||
|
||||
/**
|
||||
* Updates the NPC entity.
|
||||
*
|
||||
* @param entity The entity to update.
|
||||
*/
|
||||
void npcUpdate(entity_t *entity);
|
||||
|
||||
/**
|
||||
* Handles interaction between the player and the NPC.
|
||||
*
|
||||
* @param player The player entity interacting with the NPC.
|
||||
* @param self The NPC entity being interacted with.
|
||||
*/
|
||||
void npcInteract(entity_t *player, entity_t *self);
|
||||
@@ -1,94 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "entity.h"
|
||||
#include "assert/assert.h"
|
||||
#include "input.h"
|
||||
#include "display/render.h"
|
||||
#include "world/world.h"
|
||||
|
||||
#include "ui/uitextbox.h"
|
||||
|
||||
inventory_t PLAYER_INVENTORY;
|
||||
|
||||
void playerInit() {
|
||||
entity_t *ent = &ENTITIES[0];
|
||||
|
||||
entity_t playerEntityData = {
|
||||
.id = PLAYER_ENTITY_ID,
|
||||
.type = ENTITY_TYPE_PLAYER,
|
||||
.x = WORLD_PLAYER_SPAWN_X,
|
||||
.y = WORLD_PLAYER_SPAWN_Y,
|
||||
};
|
||||
|
||||
entityLoad(ent, &playerEntityData);
|
||||
inventoryInit(&PLAYER_INVENTORY, INVENTORY_SIZE_MAX);
|
||||
}
|
||||
|
||||
void playerEntityLoad(entity_t *entity, const entity_t *source) {
|
||||
assertNotNull(entity, "Entity pointer cannot be NULL");
|
||||
assertNotNull(source, "Source entity pointer cannot be NULL");
|
||||
assertTrue(entity->type == ENTITY_TYPE_PLAYER, "Entity type must be PLAYER");
|
||||
assertTrue(source->type == entity->type, "Source/Entity type mismatch");
|
||||
}
|
||||
|
||||
void playerEntityUpdate(entity_t *entity) {
|
||||
assertNotNull(entity, "Entity pointer cannot be NULL");
|
||||
assertTrue(entity->type == ENTITY_TYPE_PLAYER, "Entity type must be PLAYER");
|
||||
|
||||
// TODO: make this just a method somewhere.
|
||||
if(UI_TEXTBOX.visible) return;
|
||||
if(entityIsMoving(entity)) return;
|
||||
|
||||
const uint8_t moveSpeed = inputIsDown(INPUT_BIND_CANCEL) ? PLAYER_SPEED_RUN : PLAYER_SPEED_WALK;
|
||||
|
||||
if(inputIsDown(INPUT_BIND_UP)) {
|
||||
if(entity->dir != DIRECTION_NORTH) {
|
||||
entityTurn(entity, DIRECTION_NORTH);
|
||||
return;
|
||||
}
|
||||
entityMove(entity, moveSpeed);
|
||||
return;
|
||||
|
||||
} else if(inputIsDown(INPUT_BIND_DOWN)) {
|
||||
if(entity->dir != DIRECTION_SOUTH) {
|
||||
entityTurn(entity, DIRECTION_SOUTH);
|
||||
return;
|
||||
}
|
||||
|
||||
entityMove(entity, moveSpeed);
|
||||
return;
|
||||
} else if(inputIsDown(INPUT_BIND_LEFT)) {
|
||||
if(entity->dir != DIRECTION_WEST) {
|
||||
entityTurn(entity, DIRECTION_WEST);
|
||||
return;
|
||||
}
|
||||
entityMove(entity, moveSpeed);
|
||||
return;
|
||||
|
||||
} else if(inputIsDown(INPUT_BIND_RIGHT)) {
|
||||
if(entity->dir != DIRECTION_EAST) {
|
||||
entityTurn(entity, DIRECTION_EAST);
|
||||
return;
|
||||
}
|
||||
|
||||
entityMove(entity, moveSpeed);
|
||||
return;
|
||||
}
|
||||
|
||||
// Interact
|
||||
if(inputPressed(INPUT_BIND_ACTION)) {
|
||||
int8_t x, y;
|
||||
directionGetCoordinates(entity->dir, &x, &y);
|
||||
entity_t *ent = entityGetAt(entity->x + x, entity->y + y);
|
||||
|
||||
if(ent != NULL && ENTITY_CALLBACKS[ent->type].interact != NULL) {
|
||||
assertTrue(ent->type < ENTITY_TYPE_COUNT, "Entity type out of bounds");
|
||||
ENTITY_CALLBACKS[ent->type].interact(entity, ent);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "dusk.h"
|
||||
#include "item/inventory.h"
|
||||
|
||||
#define PLAYER_SPEED_WALK 1
|
||||
#define PLAYER_SPEED_RUN 2
|
||||
|
||||
typedef struct _entity_t entity_t;
|
||||
|
||||
typedef struct {
|
||||
uint32_t nothing;
|
||||
} playerentity_t;
|
||||
|
||||
#define PLAYER_ENTITY_ID (UINT32_MAX-1)
|
||||
|
||||
extern inventory_t PLAYER_INVENTORY;
|
||||
|
||||
/**
|
||||
* Initializes the player and all player-related entities.
|
||||
*/
|
||||
void playerInit(void);
|
||||
|
||||
/**
|
||||
* Loads the player entity.
|
||||
*
|
||||
* @param entity The entity to initialize.
|
||||
* @param source The source entity to copy data from.
|
||||
*/
|
||||
void playerEntityLoad(entity_t *entity, const entity_t *source);
|
||||
|
||||
/**
|
||||
* Updates the player entity.
|
||||
*
|
||||
* @param entity The entity to update.
|
||||
*/
|
||||
void playerEntityUpdate(entity_t *entity);
|
||||
@@ -1,125 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "assert/assert.h"
|
||||
#include "error.h"
|
||||
#include "util/memory.h"
|
||||
#include "util/string.h"
|
||||
|
||||
errorret_t errorThrowImpl(
|
||||
errorstate_t *state,
|
||||
errorcode_t code,
|
||||
const char_t *file,
|
||||
const char_t *function,
|
||||
const int32_t line,
|
||||
const char_t *message,
|
||||
...
|
||||
) {
|
||||
assertNotNull(state, "Error state cannot be NULL");
|
||||
assertTrue(code != ERROR_OK, "Error code must not be OK");
|
||||
assertNotNull(file, "File cannot be NULL");
|
||||
assertNotNull(function, "Function cannot be NULL");
|
||||
assertTrue(line >= 0, "File pointer must be valid");
|
||||
assertNotNull(message, "Message cannot be NULL");
|
||||
|
||||
memoryZero(state, sizeof(errorstate_t));
|
||||
state->code = code;
|
||||
|
||||
// Format args.
|
||||
va_list args;
|
||||
va_start(args, message);
|
||||
|
||||
// Get length of formatted message
|
||||
va_list argsCopy;
|
||||
va_copy(argsCopy, args);
|
||||
int32_t len = stringFormatVA(NULL, 0, message, argsCopy);
|
||||
va_end(argsCopy);
|
||||
|
||||
// Create string to hold the formatted message
|
||||
state->message = (char_t *)memoryAllocate(len + 1);
|
||||
stringFormatVA(state->message, len + 1, message, args);
|
||||
va_end(args);
|
||||
|
||||
// Format lines
|
||||
len = stringFormat(NULL, 0, ERROR_LINE_FORMAT, file, line, function);
|
||||
assertTrue(len >= 0, "Line formatting failed");
|
||||
state->lines = (char_t *)memoryAllocate(len + 1);
|
||||
stringFormat(state->lines, len + 1, ERROR_LINE_FORMAT, file, line, function);
|
||||
|
||||
return (errorret_t) {
|
||||
.code = code,
|
||||
.state = state
|
||||
};
|
||||
}
|
||||
|
||||
errorret_t errorOkImpl() {
|
||||
return (errorret_t) {
|
||||
.code = ERROR_OK,
|
||||
.state = NULL
|
||||
};
|
||||
}
|
||||
|
||||
errorret_t errorChainImpl(
|
||||
const errorret_t retval,
|
||||
const char_t *file,
|
||||
const char_t *function,
|
||||
const int32_t line
|
||||
) {
|
||||
if (retval.code == ERROR_OK) return retval;
|
||||
|
||||
assertNotNull(retval.state, "Error state cannot be NULL");
|
||||
assertNotNull(retval.state->message, "Message cannot be NULL");
|
||||
|
||||
// Create a new line string.
|
||||
int32_t newLineLen = snprintf(NULL, 0, ERROR_LINE_FORMAT, file, line, function);
|
||||
assertTrue(newLineLen >= 0, "Line formatting failed");
|
||||
char_t *newLine = (char_t *)memoryAllocate(newLineLen + 1);
|
||||
snprintf(newLine, newLineLen + 1, ERROR_LINE_FORMAT, file, line, function);
|
||||
|
||||
// Resize the existing lines to accommodate the new line
|
||||
size_t existingLen = strlen(retval.state->lines);
|
||||
memoryResize(
|
||||
(void**)&retval.state->lines,
|
||||
existingLen,
|
||||
existingLen + newLineLen + 1
|
||||
);
|
||||
|
||||
// Now append the new line to the existing lines
|
||||
memoryCopy(
|
||||
retval.state->lines + existingLen,
|
||||
newLine,
|
||||
newLineLen + 1
|
||||
);
|
||||
|
||||
// Cleanup the temporary new line
|
||||
memoryFree(newLine);
|
||||
return retval;
|
||||
}
|
||||
|
||||
void errorCatch(const errorret_t retval) {
|
||||
if (retval.code == ERROR_OK) return;
|
||||
|
||||
assertNotNull(retval.state, "Error state cannot be NULL");
|
||||
assertNotNull(retval.state->message, "Message cannot be NULL");
|
||||
|
||||
memoryFree((void*)retval.state->message);
|
||||
}
|
||||
|
||||
errorret_t errorPrint(const errorret_t retval) {
|
||||
if (retval.code == ERROR_OK) return retval;
|
||||
|
||||
assertNotNull(retval.state, "Error state cannot be NULL");
|
||||
assertNotNull(retval.state->message, "Message cannot be NULL");
|
||||
|
||||
printf(
|
||||
ERROR_PRINT_FORMAT,
|
||||
retval.state->code,
|
||||
retval.state->message,
|
||||
retval.state->lines
|
||||
);
|
||||
return retval;
|
||||
}
|
||||
@@ -1,137 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "dusk.h"
|
||||
|
||||
typedef uint8_t errorcode_t;
|
||||
|
||||
typedef struct {
|
||||
errorcode_t code;
|
||||
char_t *message;
|
||||
char_t *lines;
|
||||
} errorstate_t;
|
||||
|
||||
typedef struct {
|
||||
errorcode_t code;
|
||||
errorstate_t *state;
|
||||
} errorret_t;
|
||||
|
||||
static const errorcode_t ERROR_OK = 0;
|
||||
static const errorcode_t ERROR_NOT_OK = 1;
|
||||
static const char_t *ERROR_PRINT_FORMAT = "Error (%d): %s\n%s";
|
||||
static const char_t *ERROR_LINE_FORMAT = " at %s:%d in function %s\n";
|
||||
static errorstate_t ERROR_STATE = {
|
||||
.code = ERROR_OK,
|
||||
.message = NULL,
|
||||
.lines = NULL
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets the error state with the provided code and message.
|
||||
*
|
||||
* @param state The error state to initialize.
|
||||
* @param code The error code to set.
|
||||
* @param file The file where the error occurred.
|
||||
* @param function The function where the error occurred.
|
||||
* @param line The line number where the error occurred.
|
||||
* @param message The error message.
|
||||
* @param args The arguments for the error message.
|
||||
* @return The error code.
|
||||
*/
|
||||
errorret_t errorThrowImpl(
|
||||
errorstate_t *state,
|
||||
errorcode_t code,
|
||||
const char_t *file,
|
||||
const char_t *function,
|
||||
const int32_t line,
|
||||
const char_t *message,
|
||||
...
|
||||
);
|
||||
|
||||
/**
|
||||
* Returns an error state with no error.
|
||||
*
|
||||
* @return An error state with code ERROR_OK.
|
||||
*/
|
||||
errorret_t errorOkImpl();
|
||||
|
||||
/**
|
||||
* Chains an error state, allowing for error propagation.
|
||||
*
|
||||
* @param retval The return value containing the error state.
|
||||
* @param file The file where the error occurred.
|
||||
* @param function The function where the error occurred.
|
||||
* @param line The line number where the error occurred.
|
||||
* @return The error code if an error occurred, otherwise continues execution.
|
||||
*/
|
||||
errorret_t errorChainImpl(
|
||||
const errorret_t retval,
|
||||
const char_t *file,
|
||||
const char_t *function,
|
||||
const int32_t line
|
||||
);
|
||||
|
||||
/**
|
||||
* Catches an error and handles it.
|
||||
*
|
||||
* @param retval The return value containing the error state.
|
||||
*/
|
||||
void errorCatch(const errorret_t retval);
|
||||
|
||||
/**
|
||||
* Prints the error state to the console.
|
||||
*
|
||||
* @param retval The return value containing the error state.
|
||||
* @return Passed retval for chaining.
|
||||
*/
|
||||
errorret_t errorPrint(const errorret_t retval);
|
||||
|
||||
/**
|
||||
* Throws an error with a formatted message.
|
||||
*
|
||||
* @param code The error code to throw.
|
||||
* @param message The format string for the error message.
|
||||
* @param ... Additional arguments for the format string.
|
||||
* @return The error code.
|
||||
*/
|
||||
#define errorThrowWithCode(code, message, ... ) \
|
||||
return errorThrowImpl(\
|
||||
&ERROR_STATE, (code), __FILE__, __func__, __LINE__, (message), \
|
||||
__VA_ARGS__ \
|
||||
)
|
||||
|
||||
/**
|
||||
* Throws an error with a default error code of ERROR_NOT_OK.
|
||||
*
|
||||
* @param message The format string for the error message.
|
||||
* @param ... Additional arguments for the format string.
|
||||
* @return The error code.
|
||||
*/
|
||||
#define errorThrow(message, ...) \
|
||||
return errorThrowImpl(\
|
||||
&ERROR_STATE, ERROR_NOT_OK, __FILE__, __func__, __LINE__, (message), \
|
||||
__VA_ARGS__ \
|
||||
)
|
||||
|
||||
/**
|
||||
* Checks if a child method errored, and if it did, then send it up the chain.
|
||||
* @param retval The return value containing the error state.
|
||||
* @return The error code if an error occurred, otherwise continues execution.
|
||||
*/
|
||||
#define errorChain(retval) \
|
||||
if ((retval).code != ERROR_OK) { \
|
||||
return errorChainImpl(retval, __FILE__, __func__, __LINE__); \
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns without an error.
|
||||
*/
|
||||
#define errorOk() \
|
||||
return errorOkImpl()
|
||||
|
||||
// EOF
|
||||
@@ -1,11 +0,0 @@
|
||||
# Copyright (c) 2025 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Sources
|
||||
target_sources(${DUSK_TARGET_NAME}
|
||||
PRIVATE
|
||||
event.c
|
||||
eventtext.c
|
||||
)
|
||||
@@ -1,73 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "event.h"
|
||||
#include "util/memory.h"
|
||||
#include "assert/assert.h"
|
||||
|
||||
eventcallback_t EVENT_CALLBACKS[] = {
|
||||
[EVENT_TYPE_NULL] = { NULL, NULL },
|
||||
[EVENT_TYPE_TEXT] = { eventTextStart, eventTextUpdate },
|
||||
};
|
||||
|
||||
event_t EVENT;
|
||||
|
||||
void eventInit() {
|
||||
memoryZero(&EVENT, sizeof(event_t));
|
||||
}
|
||||
|
||||
void eventUpdate() {
|
||||
if(EVENT.active == NULL) {
|
||||
return; // No active event to update
|
||||
}
|
||||
|
||||
const eventitem_t *item = &EVENT.active->items[EVENT.item];
|
||||
assertNotNull(
|
||||
EVENT_CALLBACKS[item->type].update,
|
||||
"Event type does not have an update callback"
|
||||
);
|
||||
|
||||
EVENT_CALLBACKS[item->type].update(item);
|
||||
}
|
||||
|
||||
void eventSetActive(const eventdata_t *event) {
|
||||
assertNotNull(event, "Event data cannot be NULL");
|
||||
assertTrue(
|
||||
event->itemCount <= EVENT_ITEM_COUNT_MAX,
|
||||
"Event count too high"
|
||||
);
|
||||
assertTrue(event->itemCount > 0, "Event must have at least one item");
|
||||
|
||||
EVENT.active = event;
|
||||
EVENT.item = 0;
|
||||
|
||||
const eventitem_t *firstItem = &EVENT.active->items[EVENT.item];
|
||||
|
||||
assertNotNull(
|
||||
EVENT_CALLBACKS[firstItem->type].start,
|
||||
"Event type does not have a start callback"
|
||||
);
|
||||
EVENT_CALLBACKS[firstItem->type].start(firstItem);
|
||||
}
|
||||
|
||||
void eventNext() {
|
||||
assertNotNull(EVENT.active, "No active event to proceed with");
|
||||
assertTrue(EVENT.item < EVENT.active->itemCount, "No more items in the event");
|
||||
|
||||
EVENT.item++;
|
||||
if (EVENT.item >= EVENT.active->itemCount) {
|
||||
EVENT.active = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
const eventitem_t *nextItem = &EVENT.active->items[EVENT.item];
|
||||
assertNotNull(
|
||||
EVENT_CALLBACKS[nextItem->type].start,
|
||||
"Event type does not have a start callback"
|
||||
);
|
||||
EVENT_CALLBACKS[nextItem->type].start(nextItem);
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "eventdata.h"
|
||||
|
||||
typedef struct {
|
||||
eventdata_t data;
|
||||
const eventdata_t *active;
|
||||
uint8_t item;
|
||||
} event_t;
|
||||
|
||||
typedef struct {
|
||||
void (*start)(const eventitem_t *item);
|
||||
void (*update)(const eventitem_t *item);
|
||||
} eventcallback_t;
|
||||
|
||||
extern eventcallback_t EVENT_CALLBACKS[EVENT_TYPE_COUNT];
|
||||
extern event_t EVENT;
|
||||
|
||||
/**
|
||||
* Initializes the event system.
|
||||
*/
|
||||
void eventInit();
|
||||
|
||||
/**
|
||||
* Updates the active event.
|
||||
*/
|
||||
void eventUpdate();
|
||||
|
||||
/**
|
||||
* Sets the active event.
|
||||
*
|
||||
* @param event The event to set as active.
|
||||
*/
|
||||
void eventSetActive(const eventdata_t *eventData);
|
||||
|
||||
/**
|
||||
* Goes to the next item in the active event. Only meant to be called by
|
||||
* event items.
|
||||
*/
|
||||
void eventNext();
|
||||
@@ -1,14 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "eventitem.h"
|
||||
|
||||
typedef struct {
|
||||
uint8_t itemCount;
|
||||
eventitem_t items[EVENT_ITEM_COUNT_MAX];
|
||||
} eventdata_t;
|
||||
@@ -1,26 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma ocne
|
||||
#include "eventtext.h"
|
||||
|
||||
typedef enum {
|
||||
EVENT_TYPE_NULL = 0,
|
||||
EVENT_TYPE_TEXT,
|
||||
} eventtype_t;
|
||||
|
||||
#define EVENT_TYPE_COUNT 2
|
||||
|
||||
typedef struct _eventitem_t {
|
||||
eventtype_t type;
|
||||
|
||||
union {
|
||||
eventtext_t text;
|
||||
};
|
||||
} eventitem_t;
|
||||
|
||||
#define EVENT_ITEM_COUNT_MAX 32
|
||||
@@ -1,26 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "event.h"
|
||||
#include "ui/uitextbox.h"
|
||||
#include "assert/assert.h"
|
||||
|
||||
void eventTextStart(const eventitem_t *item) {
|
||||
assertNotNull(item, "Event item cannot be NULL");
|
||||
assertTrue(item->type == EVENT_TYPE_TEXT, "Event item must be of type TEXT");
|
||||
assertNotNull(item->text, "Event item must have at least one text");
|
||||
uiTextboxSetText(item->text);
|
||||
}
|
||||
|
||||
void eventTextUpdate(const eventitem_t *item) {
|
||||
assertNotNull(item, "Event item cannot be NULL");
|
||||
assertTrue(item->type == EVENT_TYPE_TEXT, "Event item must be of type TEXT");
|
||||
|
||||
if(!UI_TEXTBOX.visible) {
|
||||
eventNext();
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "dusk.h"
|
||||
|
||||
typedef struct _eventitem_t eventitem_t;
|
||||
|
||||
#define EVENT_TEXT_STRING_COUNT_MAX 8
|
||||
|
||||
typedef const char_t* eventtext_t;
|
||||
|
||||
/**
|
||||
* Starts the text event for the given item.
|
||||
*
|
||||
* @param item The event item to start.
|
||||
*/
|
||||
void eventTextStart(const eventitem_t *item);
|
||||
|
||||
/**
|
||||
* Updates the text event for the given item.
|
||||
*
|
||||
* @param item The event item to update.
|
||||
*/
|
||||
void eventTextUpdate(const eventitem_t *item);
|
||||
|
||||
/**
|
||||
* Query whether the text event is done or not.
|
||||
*
|
||||
* @param item The event item to check.
|
||||
*/
|
||||
bool_t eventTextIsDone(const eventitem_t *item);
|
||||
@@ -1,57 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "game.h"
|
||||
#include "util/memory.h"
|
||||
#include "world/chunk.h"
|
||||
#include "display/scene.h"
|
||||
#include "world/overworld.h"
|
||||
#include "input.h"
|
||||
#include "event/event.h"
|
||||
#include "ui/uitextbox.h"
|
||||
#include "console/console.h"
|
||||
#include "util/memory.h"
|
||||
#include "time.h"
|
||||
|
||||
game_t GAME;
|
||||
|
||||
void gameInit(void) {
|
||||
memoryZero(&GAME, sizeof(game_t));
|
||||
GAME.running = true;
|
||||
|
||||
timeInit();
|
||||
consoleInit();
|
||||
inputInit();
|
||||
eventInit();
|
||||
uiTextboxInit();
|
||||
sceneInit();
|
||||
}
|
||||
|
||||
void gameUpdate(void) {
|
||||
timeUpdate();
|
||||
|
||||
// Game logic is tied to 60FPS for now, saves me a lot of hassle with float
|
||||
// issues
|
||||
float_t timeSinceLastTick = TIME.time - TIME.lastTick;
|
||||
while(timeSinceLastTick >= TIME_STEP) {
|
||||
|
||||
sceneUpdate();
|
||||
uiTextboxUpdate();
|
||||
eventUpdate();
|
||||
inputUpdate();
|
||||
|
||||
timeSinceLastTick -= TIME_STEP;
|
||||
TIME.lastTick = TIME.time;
|
||||
}
|
||||
|
||||
if(inputPressed(INPUT_BIND_QUIT)) consoleExec("quit");
|
||||
consoleUpdate();
|
||||
}
|
||||
|
||||
void gameDispose(void) {
|
||||
sceneDispose();
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "dusk.h"
|
||||
|
||||
typedef struct {
|
||||
bool_t running;
|
||||
} game_t;
|
||||
|
||||
extern game_t GAME;
|
||||
|
||||
/**
|
||||
* Initializes the game, this should be called before any other game functions.
|
||||
* This should be called by the parent platform at a time that it deems
|
||||
* appropriate. Any game systems cannot be used until this function has
|
||||
* been called.
|
||||
*
|
||||
* By the point this is called, we expect;
|
||||
* - Rendering has initialized and is ready to draw.
|
||||
* - Input has been initialized and is ready to be read.
|
||||
* - If your system handles time dynamically, it should be ready to be used.
|
||||
*
|
||||
* The systems called (in order) are;
|
||||
* - Console.
|
||||
* - Input system (Not the platforms input, but the game's input system).
|
||||
* - Time system (if applicable).
|
||||
* - Event System
|
||||
* - UI Systems.
|
||||
* - Gameplay systems.
|
||||
*/
|
||||
void gameInit(void);
|
||||
|
||||
/**
|
||||
* Asks the game to update, this will not do any drawing and should be called
|
||||
* in the main loop of the system, ideally either after or before the rendering
|
||||
* has occured.
|
||||
*/
|
||||
void gameUpdate(void);
|
||||
|
||||
/**
|
||||
* Cleans up resources used by the game, rendering really should still be
|
||||
* available at this point because we want to cleanup nicely.
|
||||
*/
|
||||
void gameDispose(void);
|
||||
@@ -1,39 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "input.h"
|
||||
#include "assert/assert.h"
|
||||
#include "util/memory.h"
|
||||
|
||||
input_t INPUT;
|
||||
|
||||
void inputInit(void) {
|
||||
memoryZero(&INPUT, sizeof(input_t));
|
||||
}
|
||||
|
||||
void inputUpdate(void) {
|
||||
INPUT.previous = INPUT.current;
|
||||
INPUT.current = inputStateGet();
|
||||
}
|
||||
|
||||
bool_t inputIsDown(const inputbind_t bind) {
|
||||
assertTrue(bind < INPUT_BIND_COUNT, "Input bind out of bounds");
|
||||
return (INPUT.current & bind) != 0;
|
||||
}
|
||||
|
||||
bool_t inputWasDown(const inputbind_t bind) {
|
||||
assertTrue(bind < INPUT_BIND_COUNT, "Input bind out of bounds");
|
||||
return (INPUT.previous & bind) != 0;
|
||||
}
|
||||
|
||||
bool_t inputPressed(const inputbind_t bind) {
|
||||
return inputIsDown(bind) && !inputWasDown(bind);
|
||||
}
|
||||
|
||||
bool_t inputReleased(const inputbind_t bind) {
|
||||
return !inputIsDown(bind) && inputWasDown(bind);
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "dusk.h"
|
||||
|
||||
typedef uint8_t inputbind_t;
|
||||
typedef inputbind_t inputstate_t;
|
||||
|
||||
#define INPUT_BIND_UP (1 << 0)
|
||||
#define INPUT_BIND_DOWN (1 << 1)
|
||||
#define INPUT_BIND_LEFT (1 << 2)
|
||||
#define INPUT_BIND_RIGHT (1 << 3)
|
||||
#define INPUT_BIND_ACTION (1 << 4)
|
||||
#define INPUT_BIND_CANCEL (1 << 5)
|
||||
#define INPUT_BIND_CONSOLE (1 << 6)
|
||||
#define INPUT_BIND_QUIT (1 << 7)
|
||||
|
||||
#define INPUT_BIND_COUNT (INPUT_BIND_QUIT + 1)
|
||||
|
||||
typedef struct {
|
||||
uint8_t current;
|
||||
uint8_t previous;
|
||||
} input_t;
|
||||
|
||||
extern input_t INPUT;
|
||||
|
||||
/**
|
||||
* Initialize the input system.
|
||||
*/
|
||||
void inputInit(void);
|
||||
|
||||
/**
|
||||
* Updates the input state.
|
||||
*/
|
||||
void inputUpdate(void);
|
||||
|
||||
/**
|
||||
* Gets the current input state as a bitmask.
|
||||
*
|
||||
* @return The current input state as a bitmask.
|
||||
*/
|
||||
inputstate_t inputStateGet(void);
|
||||
|
||||
/**
|
||||
* Checks if a specific input bind is currently pressed.
|
||||
*
|
||||
* @param bind The input bind to check.
|
||||
* @return true if the bind is currently pressed, false otherwise.
|
||||
*/
|
||||
bool_t inputIsDown(const inputbind_t bind);
|
||||
|
||||
/**
|
||||
* Checks if a specific input bind was pressed in the last update.
|
||||
*
|
||||
* @param bind The input bind to check.
|
||||
* @return true if the bind was pressed in the last update, false otherwise.
|
||||
*/
|
||||
bool_t inputWasDown(const inputbind_t bind);
|
||||
|
||||
/**
|
||||
* Checks if a specific input bind was down this frame but not in the the
|
||||
* previous frame.
|
||||
*
|
||||
* @param bind The input bind to check.
|
||||
* @return true if the bind is currently pressed, false otherwise.
|
||||
*/
|
||||
bool_t inputPressed(const inputbind_t bind);
|
||||
|
||||
/**
|
||||
* Checks if a specific input bind was released this frame.
|
||||
*
|
||||
* @param bind The input bind to check.
|
||||
* @return true if the bind was released this frame, false otherwise.
|
||||
*/
|
||||
bool_t inputReleased(const inputbind_t bind);
|
||||
@@ -1,68 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "inventory.h"
|
||||
#include "util/memory.h"
|
||||
#include "assert/assert.h"
|
||||
|
||||
void inventoryInit(inventory_t *inventory, const uint8_t size) {
|
||||
assertNotNull(inventory, "inventory must not be NULL");
|
||||
assertTrue(size <= INVENTORY_SIZE_MAX, "size exceeding INVENTORY_SIZE_MAX");
|
||||
assertTrue(size > 0, "size must be greater than 0");
|
||||
|
||||
memoryZero(inventory, sizeof(inventory_t));
|
||||
inventory->size = size;
|
||||
}
|
||||
|
||||
uint8_t inventoryItemIndexByType(
|
||||
const inventory_t *inventory,
|
||||
const itemtype_t type
|
||||
) {
|
||||
assertNotNull(inventory, "inventory must not be NULL");
|
||||
assertTrue(type > ITEM_TYPE_NULL, "type must be greater than ITEM_TYPE_NULL");
|
||||
|
||||
uint8_t item = inventory->itemCount;
|
||||
while(item--) {
|
||||
if(inventory->items[item].type == type) return item;
|
||||
}
|
||||
return INVENTORY_SIZE_MAX;
|
||||
}
|
||||
|
||||
uint8_t inventoryItemCount(
|
||||
const inventory_t *inventory,
|
||||
const itemtype_t type
|
||||
) {
|
||||
assertNotNull(inventory, "inventory must not be NULL");
|
||||
assertTrue(type > ITEM_TYPE_NULL, "type must be greater than ITEM_TYPE_NULL");
|
||||
|
||||
const uint8_t index = inventoryItemIndexByType(inventory, type);
|
||||
if(index == INVENTORY_SIZE_MAX) return 0;
|
||||
return inventory->items[index].count;
|
||||
}
|
||||
|
||||
void inventoryItemSet(
|
||||
inventory_t *inventory,
|
||||
const itemtype_t type,
|
||||
const uint8_t count
|
||||
) {
|
||||
assertNotNull(inventory, "inventory must not be NULL");
|
||||
assertTrue(type > ITEM_TYPE_NULL, "type must be greater than ITEM_TYPE_NULL");
|
||||
assertTrue(count > 0, "count must be greater than 0");
|
||||
|
||||
const uint8_t index = inventoryItemIndexByType(inventory, type);
|
||||
|
||||
if(index == INVENTORY_SIZE_MAX) {
|
||||
// Item does not exist, add it
|
||||
assertTrue(inventory->itemCount < inventory->size, "inventory is full");
|
||||
inventory->items[inventory->itemCount].type = type;
|
||||
inventory->items[inventory->itemCount].count = count;
|
||||
inventory->itemCount++;
|
||||
} else {
|
||||
// Item exists, update the count
|
||||
inventory->items[index].count = count;
|
||||
}
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "itemstack.h"
|
||||
|
||||
#define INVENTORY_SIZE_MAX UINT8_MAX
|
||||
|
||||
typedef struct {
|
||||
itemstack_t items[INVENTORY_SIZE_MAX];
|
||||
uint8_t itemCount;
|
||||
uint8_t size;
|
||||
} inventory_t;
|
||||
|
||||
/**
|
||||
* Initializes an inventory with a specified size.
|
||||
*
|
||||
* @param inventory Pointer to the inventory to initialize.
|
||||
* @param size The size of the inventory (maximum is INVENTORY_SIZE_MAX).
|
||||
*/
|
||||
void inventoryInit(inventory_t *inventory, const uint8_t size);
|
||||
|
||||
/**
|
||||
* Finds the index of the item of a specified type in the inventory.
|
||||
*
|
||||
* @param inventory Pointer to the inventory to search.
|
||||
* @param type The type of item to find.
|
||||
* @return The index of the item, or INVENTORY_SIZE_MAX if not found.
|
||||
*/
|
||||
uint8_t inventoryItemIndexByType(
|
||||
const inventory_t *inventory,
|
||||
const itemtype_t type
|
||||
);
|
||||
|
||||
/**
|
||||
* Gets the count of items of a specified type in the inventory.
|
||||
*
|
||||
* @param inventory Pointer to the inventory to check.
|
||||
* @param type The type of item to count.
|
||||
* @return The count of items of the specified type.
|
||||
*/
|
||||
uint8_t inventoryItemCount(
|
||||
const inventory_t *inventory,
|
||||
const itemtype_t type
|
||||
);
|
||||
|
||||
/**
|
||||
* Sets the count of items of a specified type in the inventory.
|
||||
* If the item does not exist, it will be added.
|
||||
*
|
||||
* @param inventory Pointer to the inventory to modify.
|
||||
* @param type The type of item to set.
|
||||
* @param count The count of items to set.
|
||||
*/
|
||||
void inventoryItemSet(
|
||||
inventory_t *inventory,
|
||||
const itemtype_t type,
|
||||
const uint8_t count
|
||||
);
|
||||
@@ -1,24 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "dusk.h"
|
||||
|
||||
typedef enum {
|
||||
ITEM_TYPE_NULL = 0,
|
||||
|
||||
// MEDICINE
|
||||
ITEM_TYPE_POTION,
|
||||
|
||||
// INGREDIENTS
|
||||
ITEM_TYPE_ONION,
|
||||
ITEM_TYPE_SWEET_POTATO,
|
||||
ITEM_TYPE_CARROT,
|
||||
|
||||
// COOKED FOOD
|
||||
ITEM_TYPE_BAKED_SWEET_POTATO,
|
||||
} itemtype_t;
|
||||
@@ -1,145 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "language.h"
|
||||
#include "assert/assert.h"
|
||||
|
||||
language_t LANGUAGE;
|
||||
|
||||
void languageInit(void) {
|
||||
LANGUAGE.current = LANGUAGE_EN;
|
||||
}
|
||||
|
||||
const char_t * languageGet(const char_t *key) {
|
||||
assertNotNull(key, "Key cannot be NULL");
|
||||
assertTrue(LANGUAGE.current < LANGUAGE_COUNT, "Invalid language index");
|
||||
|
||||
int16_t keyIndex = -1;
|
||||
for(uint16_t i = 0; i < LANGUAGE_COUNTS[LANGUAGE.current]; i++) {
|
||||
if(strcmp(LANGUAGE_KEYS[LANGUAGE.current][i], key) != 0) continue;
|
||||
keyIndex = i;
|
||||
break;
|
||||
}
|
||||
assertTrue(keyIndex != -1, "Key not found in language");
|
||||
return LANGUAGE_VALUES[LANGUAGE.current][keyIndex];
|
||||
}
|
||||
|
||||
uint16_t langaugeGetLength(const char_t *key) {
|
||||
assertNotNull(key, "Key cannot be NULL");
|
||||
assertTrue(LANGUAGE.current < LANGUAGE_COUNT, "Invalid language index");
|
||||
|
||||
int16_t keyIndex = -1;
|
||||
for(uint16_t i = 0; i < LANGUAGE_COUNTS[LANGUAGE.current]; i++) {
|
||||
if(strcmp(LANGUAGE_KEYS[LANGUAGE.current][i], key) != 0) continue;
|
||||
keyIndex = i;
|
||||
break;
|
||||
}
|
||||
assertTrue(keyIndex != -1, "Key not found in language");
|
||||
return strlen(LANGUAGE_VALUES[LANGUAGE.current][keyIndex]);
|
||||
}
|
||||
|
||||
uint16_t languageFormat(
|
||||
const char_t *key,
|
||||
char_t *buffer,
|
||||
uint16_t buffSize,
|
||||
const char_t **keys,
|
||||
const char_t **values,
|
||||
const uint16_t valueCount
|
||||
) {
|
||||
if(buffer != NULL) {
|
||||
assertTrue(buffSize > 0, "Buffer size must be greater than 0");
|
||||
} else {
|
||||
assertTrue(buffSize == 0, "Buffer size must be 0 if buffer is NULL");
|
||||
}
|
||||
|
||||
assertNotNull(key, "Key cannot be NULL");
|
||||
assertNotNull(keys, "Keys cannot be NULL");
|
||||
assertNotNull(values, "Values cannot be NULL");
|
||||
|
||||
const char_t *val = languageGet(key);
|
||||
assertNotNull(val, "Value for key cannot be NULL");
|
||||
|
||||
char_t c;
|
||||
uint16_t i = 0;
|
||||
uint16_t j = 0;
|
||||
uint8_t k = 0;
|
||||
bool_t inBraces = false;
|
||||
char_t braceBuffer[64] = {0};
|
||||
|
||||
#define bufferChar(c) ( \
|
||||
(buffer ? (buffer[j++] = c) : (j++)), \
|
||||
assertTrue(buffer ? j < buffSize : true, "Buffer overflow") \
|
||||
)
|
||||
|
||||
while((c = val[i++]) != '\0') {
|
||||
if(c == '{' && val[i] == '{') {
|
||||
goto startBraces;
|
||||
} else if(c == '}' && val[i] == '}') {
|
||||
goto endBraces;
|
||||
} else if(inBraces) {
|
||||
goto braceBuffering;
|
||||
} else {
|
||||
goto character;
|
||||
}
|
||||
|
||||
character: {
|
||||
bufferChar(c);
|
||||
continue;
|
||||
}
|
||||
|
||||
braceBuffering: {
|
||||
assertFalse(val[i] == '\0', "Unexpected end of string.");
|
||||
braceBuffer[k++] = c;
|
||||
assertTrue(k < sizeof(braceBuffer), "Brace buffer overflow");
|
||||
if(val[i] == ' ') i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
startBraces: {
|
||||
assertFalse(inBraces, "Nested braces are not allowed");
|
||||
|
||||
inBraces = true;
|
||||
i++;
|
||||
k = 0;
|
||||
assertFalse(val[i] == '\0', "Unexpected end of string.");
|
||||
if(val[i] == ' ') i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
endBraces: {
|
||||
assertTrue(inBraces, "Unmatched closing brace found");
|
||||
|
||||
inBraces = false;
|
||||
i++;
|
||||
braceBuffer[k] = '\0';
|
||||
|
||||
uint16_t l;
|
||||
for(l = 0; l < valueCount; l++) {
|
||||
if(strcmp(braceBuffer, keys[l]) != 0) {
|
||||
continue;
|
||||
}
|
||||
const char_t *replacement = values[l];
|
||||
|
||||
uint16_t r = 0;
|
||||
while((c = replacement[r++]) != '\0') {
|
||||
bufferChar(c);
|
||||
}
|
||||
break;
|
||||
}
|
||||
assertTrue(l < valueCount, "No string replacement found!");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if(buffer){
|
||||
assertTrue(j < buffSize, "Buffer overflow");
|
||||
buffer[j] = '\0';
|
||||
}
|
||||
|
||||
assertFalse(inBraces, "Unmatched opening brace found");
|
||||
return j;
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "locale/language/languages.h"
|
||||
|
||||
typedef struct {
|
||||
uint8_t current;
|
||||
} language_t;
|
||||
|
||||
extern language_t LANGUAGE;
|
||||
|
||||
/**
|
||||
* Initializes the language system.
|
||||
*
|
||||
* This function sets up the language system, loading the default language
|
||||
* and preparing any necessary resources for language handling.
|
||||
*/
|
||||
void languageInit(void);
|
||||
|
||||
/**
|
||||
* Gets a language string by its key.
|
||||
*
|
||||
* @param key The key for the language string.
|
||||
* @return The language string associated with the key.
|
||||
*/
|
||||
const char_t * languageGet(const char_t *key);
|
||||
|
||||
/**
|
||||
* Gets the length of a language string by its key.
|
||||
*
|
||||
* @param key The key for the language string.
|
||||
* @return The length of the language string associated with the key.
|
||||
*/
|
||||
uint16_t langaugeGetLength(const char_t *key);
|
||||
|
||||
/**
|
||||
* Formats a language string with given keys and values.
|
||||
*
|
||||
* This function replaces placeholders in the language string with the provided
|
||||
* values based on the keys.
|
||||
*
|
||||
* If buffer is NULL, the function will instead calculate the length of the
|
||||
* formatted string.
|
||||
*
|
||||
* @param key The key for the language string to format.
|
||||
* @param buffer The buffer to store the formatted string.
|
||||
* @param buffSize The size of the buffer.
|
||||
* @param keys An array of keys to replace in the language string.
|
||||
* @param values An array of values corresponding to the keys.
|
||||
* @param valueCount The number of key-value pairs.
|
||||
* @return The number of characters written to the buffer.
|
||||
*/
|
||||
uint16_t languageFormat(
|
||||
const char_t *key,
|
||||
char_t *buffer,
|
||||
uint16_t buffSize,
|
||||
const char_t **keys,
|
||||
const char_t **values,
|
||||
const uint16_t valueCount
|
||||
);
|
||||
@@ -1,37 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "time.h"
|
||||
#include "util/memory.h"
|
||||
#include "assert/assert.h"
|
||||
|
||||
dusktime_t TIME;
|
||||
|
||||
void timeInit(void) {
|
||||
memoryZero(&TIME, sizeof(TIME));
|
||||
|
||||
// Set these to something non-zero.
|
||||
TIME.lastTick = TIME_STEP;
|
||||
TIME.delta = TIME.realDelta = TIME_STEP;
|
||||
TIME.realTime = TIME.time = TIME_STEP * 2;
|
||||
}
|
||||
|
||||
void timeUpdate(void) {
|
||||
TIME.realDelta = timeDeltaGet();
|
||||
|
||||
#if TIME_DYNAMIC
|
||||
TIME.delta = TIME.realDelta;
|
||||
#else
|
||||
TIME.delta = TIME_PLATFORM_STEP;
|
||||
#endif
|
||||
|
||||
assertTrue(TIME.delta >= 0.0f, "Time delta is negative");
|
||||
assertTrue(TIME.realDelta >= 0.0f, "Real time delta is negative");
|
||||
|
||||
TIME.time += TIME.delta;
|
||||
TIME.realTime += TIME.realDelta;
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "dusk.h"
|
||||
|
||||
typedef struct {
|
||||
float_t delta;
|
||||
float_t lastTick;
|
||||
float_t time;
|
||||
float_t realDelta;
|
||||
float_t realTime;
|
||||
} dusktime_t;
|
||||
|
||||
extern dusktime_t TIME;
|
||||
|
||||
#define TIME_STEP (1.0f / 60.0f) // Default to 60FPS
|
||||
|
||||
#ifndef TIME_DYNAMIC
|
||||
#define TIME_DYNAMIC 1
|
||||
#endif
|
||||
|
||||
#if TIME_DYNAMIC == 0
|
||||
#ifndef TIME_PLATFORM_STEP
|
||||
#define TIME_PLATFORM_STEP TIME_STEP
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Initializes the time system.
|
||||
*/
|
||||
void timeInit(void);
|
||||
|
||||
/**
|
||||
* Updates the time system
|
||||
*/
|
||||
void timeUpdate(void);
|
||||
|
||||
#if TIME_DYNAMIC == 1
|
||||
/**
|
||||
* Gets the time delta since the last frame, in seconds. Tied to the
|
||||
* platform.
|
||||
*
|
||||
* This will only get called once per gameUpdate.
|
||||
*/
|
||||
float_t timeDeltaGet(void);
|
||||
#endif
|
||||
|
||||
@@ -1,10 +1,18 @@
|
||||
# Copyright (c) 2025 Dominic Masters
|
||||
# Copyright (c) 2026 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
add_subdirectory(debug)
|
||||
add_subdirectory(frame)
|
||||
add_subdirectory(focus)
|
||||
add_subdirectory(overlay)
|
||||
add_subdirectory(transition)
|
||||
add_subdirectory(widget)
|
||||
|
||||
# Sources
|
||||
target_sources(${DUSK_TARGET_NAME}
|
||||
PRIVATE
|
||||
uitextbox.c
|
||||
target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
||||
PUBLIC
|
||||
ui.c
|
||||
uielement.c
|
||||
)
|
||||
@@ -0,0 +1,10 @@
|
||||
# Copyright (c) 2026 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
||||
PUBLIC
|
||||
uiconsole.c
|
||||
uifps.c
|
||||
)
|
||||
@@ -0,0 +1,138 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "uiconsole.h"
|
||||
#include "assert/assert.h"
|
||||
#include "console/console.h"
|
||||
#include "display/screen/screen.h"
|
||||
#include "display/text/text.h"
|
||||
#include "display/spritebatch/spritebatch.h"
|
||||
#include "display/shader/shaderunlit.h"
|
||||
#include "display/mesh/mesh.h"
|
||||
#include "util/memory.h"
|
||||
|
||||
typedef struct {
|
||||
mesh_t mesh;
|
||||
bool_t built;
|
||||
meshvertex_t vertices[UI_CONSOLE_CACHE_VERTEX_MAX];
|
||||
int32_t vertexCount;
|
||||
int32_t cachedScanX;
|
||||
int32_t cachedScanY;
|
||||
} uiconsolecache_t;
|
||||
|
||||
uiconsolecache_t UI_CONSOLE_CACHE;
|
||||
|
||||
errorret_t uiConsoleDraw(void) {
|
||||
if(!CONSOLE.visible) errorOk();
|
||||
|
||||
if(
|
||||
CONSOLE.dirty ||
|
||||
UI_CONSOLE_CACHE.cachedScanX != SCREEN.scanX ||
|
||||
UI_CONSOLE_CACHE.cachedScanY != SCREEN.scanY
|
||||
) {
|
||||
errorChain(uiConsoleRebuild());
|
||||
}
|
||||
|
||||
if(UI_CONSOLE_CACHE.vertexCount == 0) errorOk();
|
||||
|
||||
shadermaterial_t material = {
|
||||
.unlit = {
|
||||
.color = COLOR_RED,
|
||||
.texture = FONT_DEFAULT.texture
|
||||
}
|
||||
};
|
||||
|
||||
errorChain(shaderBind(&SHADER_UNLIT));
|
||||
errorChain(shaderSetMaterial(&SHADER_UNLIT, &material));
|
||||
return meshDraw(&UI_CONSOLE_CACHE.mesh, 0, UI_CONSOLE_CACHE.vertexCount);
|
||||
}
|
||||
|
||||
errorret_t uiConsoleRebuild(void) {
|
||||
int32_t spriteCount = 0;
|
||||
for(uint32_t i = 0; i < CONSOLE_HISTORY_MAX; i++) {
|
||||
char_t c;
|
||||
int32_t j = 0;
|
||||
while((c = CONSOLE.line[i][j++]) != '\0') {
|
||||
if(c != ' ' && c != '\n') spriteCount++;
|
||||
}
|
||||
}
|
||||
|
||||
assertTrue(
|
||||
spriteCount <= UI_CONSOLE_CACHE_GLYPH_MAX,
|
||||
"Console history exceeds fixed cache capacity"
|
||||
);
|
||||
|
||||
const int32_t vertexCount = spriteCount * QUAD_VERTEX_COUNT;
|
||||
UI_CONSOLE_CACHE.vertexCount = vertexCount;
|
||||
|
||||
if(vertexCount > 0) {
|
||||
const float_t lineH = (float_t)FONT_DEFAULT.tileset->tileHeight;
|
||||
const float_t charW = (float_t)FONT_DEFAULT.tileset->tileWidth;
|
||||
|
||||
int32_t index = 0;
|
||||
int32_t row = 0;
|
||||
for(uint32_t i = 0; i < CONSOLE_HISTORY_MAX; i++) {
|
||||
float_t posX = (float_t)SCREEN.scanX;
|
||||
float_t posY = (float_t)SCREEN.scanY + lineH * (float_t)row;
|
||||
|
||||
char_t c;
|
||||
int32_t j = 0;
|
||||
while((c = CONSOLE.line[i][j++]) != '\0') {
|
||||
if(c == '\n') {
|
||||
posX = (float_t)SCREEN.scanX;
|
||||
posY += lineH;
|
||||
row++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if(c == ' ') {
|
||||
posX += charW;
|
||||
continue;
|
||||
}
|
||||
|
||||
const spritebatchsprite_t sprite = textGetSprite(
|
||||
(vec2){ posX, posY }, c, &FONT_DEFAULT
|
||||
);
|
||||
spriteBatchBufferToMesh(
|
||||
&sprite, 1,
|
||||
&UI_CONSOLE_CACHE.vertices[index], QUAD_VERTEX_COUNT
|
||||
);
|
||||
|
||||
index += QUAD_VERTEX_COUNT;
|
||||
posX += charW;
|
||||
}
|
||||
|
||||
row++;
|
||||
}
|
||||
|
||||
if(!UI_CONSOLE_CACHE.built) {
|
||||
errorChain(meshInit(
|
||||
&UI_CONSOLE_CACHE.mesh,
|
||||
QUAD_PRIMITIVE_TYPE,
|
||||
UI_CONSOLE_CACHE_VERTEX_MAX,
|
||||
UI_CONSOLE_CACHE.vertices
|
||||
));
|
||||
UI_CONSOLE_CACHE.built = true;
|
||||
} else {
|
||||
errorChain(meshFlush(&UI_CONSOLE_CACHE.mesh, 0, vertexCount));
|
||||
}
|
||||
}
|
||||
|
||||
UI_CONSOLE_CACHE.cachedScanX = SCREEN.scanX;
|
||||
UI_CONSOLE_CACHE.cachedScanY = SCREEN.scanY;
|
||||
CONSOLE.dirty = false;
|
||||
errorOk();
|
||||
}
|
||||
|
||||
errorret_t uiConsoleDispose(void) {
|
||||
if(UI_CONSOLE_CACHE.built) {
|
||||
errorChain(meshDispose(&UI_CONSOLE_CACHE.mesh));
|
||||
}
|
||||
|
||||
memoryZero(&UI_CONSOLE_CACHE, sizeof(uiconsolecache_t));
|
||||
errorOk();
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "error/error.h"
|
||||
#include "display/mesh/quad.h"
|
||||
|
||||
// Fixed capacity for the console's cached glyph mesh, in glyphs -- the
|
||||
// mesh/vertex buffer is sized to this once and never grown/shrunk, so
|
||||
// history producing more non-space characters than this asserts (see
|
||||
// uiConsoleRebuild) instead of reallocating.
|
||||
#define UI_CONSOLE_CACHE_GLYPH_MAX 512
|
||||
#define UI_CONSOLE_CACHE_VERTEX_MAX (\
|
||||
UI_CONSOLE_CACHE_GLYPH_MAX * QUAD_VERTEX_COUNT \
|
||||
)
|
||||
|
||||
/**
|
||||
* Renders the console history into the scan-safe area, drawing a mesh
|
||||
* that is only rebuilt when the history changes or the scan-safe origin
|
||||
* moves, rather than rebuffering vertices every frame. No-ops when the
|
||||
* console is not visible.
|
||||
*
|
||||
* @return Any error that occurs.
|
||||
*/
|
||||
errorret_t uiConsoleDraw(void);
|
||||
|
||||
/**
|
||||
* Rebuilds the cached mesh for the console's current history and
|
||||
* scan-safe origin. Called automatically by uiConsoleDraw() whenever
|
||||
* needed; only needs calling directly to force an immediate rebuild.
|
||||
* The underlying vertex buffer is a fixed-size array (see
|
||||
* UI_CONSOLE_CACHE_VERTEX_MAX) -- asserts if the history produces more
|
||||
* glyphs than that capacity, rather than growing it.
|
||||
*
|
||||
* @return Any error that occurs.
|
||||
*/
|
||||
errorret_t uiConsoleRebuild(void);
|
||||
|
||||
/**
|
||||
* Frees the mesh and vertex buffer built up by uiConsoleDraw().
|
||||
*
|
||||
* @return Any error that occurs.
|
||||
*/
|
||||
errorret_t uiConsoleDispose(void);
|
||||
@@ -0,0 +1,78 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "uifps.h"
|
||||
#include "time/time.h"
|
||||
#include "util/string.h"
|
||||
#include "display/text/text.h"
|
||||
#include "display/screen/screen.h"
|
||||
#include "engine/engine.h"
|
||||
|
||||
uifps_t UIFPS;
|
||||
|
||||
errorret_t uiFPSInit() {
|
||||
uiLabelInit(&UIFPS.fpsLabel, &FONT_DEFAULT);
|
||||
uiLabelInit(&UIFPS.versionLabel, &FONT_DEFAULT);
|
||||
uiLabelSetText(&UIFPS.versionLabel, ENGINE.version);
|
||||
uiLabelSetColor(&UIFPS.versionLabel, color(255, 255, 255, 128));
|
||||
errorOk();
|
||||
}
|
||||
|
||||
errorret_t uiFPSDraw() {
|
||||
char_t fpsText[32];
|
||||
|
||||
// Get now.
|
||||
dusktimeepoch_t now = timeGetEpoch();
|
||||
double_t delta = now.time - UIFPS.lastTick.time;
|
||||
UIFPS.lastTick = now;
|
||||
|
||||
// Raw current FPS
|
||||
float_t fps = delta > 0 ? 1.0 / delta : 0.0;
|
||||
|
||||
// Average FPS using exponential moving average
|
||||
const float_t alpha = 0.1f; // Smoothing factor
|
||||
if(UIFPS.fpsAverage == 0.0f) {
|
||||
UIFPS.fpsAverage = fps; // Initialize average on first run
|
||||
} else {
|
||||
UIFPS.fpsAverage = alpha * fps + (1.0f - alpha) * UIFPS.fpsAverage;
|
||||
}
|
||||
|
||||
snprintf(
|
||||
fpsText,
|
||||
sizeof(fpsText),
|
||||
"%.1f/%.1fms",
|
||||
UIFPS.fpsAverage,
|
||||
delta * 1000.0f
|
||||
);
|
||||
|
||||
color_t textColor;
|
||||
if(fps >= 55.0f) {
|
||||
textColor = COLOR_GREEN;
|
||||
} else if(fps >= 45.0f) {
|
||||
textColor = COLOR_YELLOW;
|
||||
} else {
|
||||
textColor = COLOR_RED;
|
||||
}
|
||||
|
||||
uiLabelSetColor(&UIFPS.fpsLabel, textColor);
|
||||
if(stringCompare(fpsText, UIFPS.fpsLabel.text) != 0) {
|
||||
uiLabelSetText(&UIFPS.fpsLabel, fpsText);
|
||||
}
|
||||
errorChain(uiLabelDraw(
|
||||
&UIFPS.fpsLabel, (float_t)SCREEN.scanX, (float_t)SCREEN.scanY
|
||||
));
|
||||
|
||||
int32_t versionWidth, versionHeight;
|
||||
uiLabelGetSize(&UIFPS.versionLabel, &versionWidth, &versionHeight);
|
||||
errorChain(uiLabelDraw(
|
||||
&UIFPS.versionLabel,
|
||||
(float_t)(SCREEN.scanX + SCREEN.scanWidth - versionWidth),
|
||||
(float_t)(SCREEN.scanY + SCREEN.scanHeight - versionHeight)
|
||||
));
|
||||
|
||||
errorOk();
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "error/error.h"
|
||||
#include "time/timeepoch.h"
|
||||
#include "ui/widget/uilabel.h"
|
||||
|
||||
typedef struct {
|
||||
dusktimeepoch_t lastTick;
|
||||
float_t fpsAverage;
|
||||
uilabel_t fpsLabel;
|
||||
uilabel_t versionLabel;
|
||||
} uifps_t;
|
||||
|
||||
extern uifps_t UIFPS;
|
||||
|
||||
/**
|
||||
* Initializes the FPS counter, caching the (static) version label.
|
||||
*
|
||||
* @return Any error that occurs.
|
||||
*/
|
||||
errorret_t uiFPSInit();
|
||||
|
||||
/**
|
||||
* Draws the FPS counter on the screen, and also does the update (for now).
|
||||
*
|
||||
* @return Any error that occurs.
|
||||
*/
|
||||
errorret_t uiFPSDraw();
|
||||
@@ -0,0 +1,9 @@
|
||||
# Copyright (c) 2026 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
||||
PUBLIC
|
||||
uifocus.c
|
||||
)
|
||||
@@ -0,0 +1,190 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "uifocus.h"
|
||||
#include "assert/assert.h"
|
||||
#include "util/memory.h"
|
||||
#include "input/input.h"
|
||||
#include "time/time.h"
|
||||
|
||||
const uifocusdirmap_t UI_FOCUS_DIR_MAP[] = {
|
||||
{ INPUT_BIND_UP, UI_FOCUS_DIRECTION_UP, 0, -1 },
|
||||
{ INPUT_BIND_DOWN, UI_FOCUS_DIRECTION_DOWN, 0, 1 },
|
||||
{ INPUT_BIND_LEFT, UI_FOCUS_DIRECTION_LEFT, -1, 0 },
|
||||
{ INPUT_BIND_RIGHT, UI_FOCUS_DIRECTION_RIGHT, 1, 0 },
|
||||
{ INPUT_BIND_NULL, UI_FOCUS_DIRECTION_NONE, 0, 0 },
|
||||
};
|
||||
|
||||
uifocus_t UI_FOCUS;
|
||||
|
||||
void uiFocusInit(void) {
|
||||
memoryZero(&UI_FOCUS, sizeof(uifocus_t));
|
||||
}
|
||||
|
||||
uifocusitem_t * uiFocusPush(
|
||||
const uint8_t cols,
|
||||
const uint8_t rows,
|
||||
uifocusitemcallback_t selected,
|
||||
uifocusitemcallback_t changed,
|
||||
uifocusitemcallback_t closed,
|
||||
uifocusitemdirectioncallback_t direction,
|
||||
void *user
|
||||
) {
|
||||
assertTrue(
|
||||
UI_FOCUS.count < UI_FOCUS_STACK_MAX,
|
||||
"UI focus stack overflow"
|
||||
);
|
||||
assertTrue(cols > 0, "Focus item cols must be > 0");
|
||||
assertTrue(rows > 0, "Focus item rows must be > 0");
|
||||
|
||||
uifocusitem_t *item = &UI_FOCUS.items[UI_FOCUS.count];
|
||||
memoryZero(item, sizeof(uifocusitem_t));
|
||||
item->cols = cols;
|
||||
item->rows = rows;
|
||||
item->selected = selected;
|
||||
item->changed = changed;
|
||||
item->closed = closed;
|
||||
item->direction = direction;
|
||||
item->user = user;
|
||||
UI_FOCUS.count++;
|
||||
UI_FOCUS.pushedThisTick = true;
|
||||
if(item->changed != NULL) item->changed(item);
|
||||
return item;
|
||||
}
|
||||
|
||||
void uiFocusPop(void) {
|
||||
assertTrue(UI_FOCUS.count > 0, "UI focus stack underflow");
|
||||
|
||||
uifocusitem_t *item = &UI_FOCUS.items[UI_FOCUS.count - 1];
|
||||
if(item->closed != NULL) item->closed(item);
|
||||
UI_FOCUS.count--;
|
||||
}
|
||||
|
||||
void uiFocusPopItem(uifocusitem_t *item) {
|
||||
assertTrue(UI_FOCUS.count > 0, "UI focus stack underflow");
|
||||
assertTrue(item >= UI_FOCUS.items, "Item is not on the focus stack");
|
||||
assertTrue(
|
||||
item < UI_FOCUS.items + UI_FOCUS.count,
|
||||
"Item is not on the focus stack"
|
||||
);
|
||||
|
||||
while(&UI_FOCUS.items[UI_FOCUS.count - 1] != item) {
|
||||
uiFocusPop();
|
||||
}
|
||||
uiFocusPop();
|
||||
}
|
||||
|
||||
void uiFocusSetPosition(uifocusitem_t *item, const uint8_t x, const uint8_t y) {
|
||||
assertTrue(UI_FOCUS.count > 0, "No active focus item");
|
||||
assertTrue(item->cols > 0, "Focus item cols must be > 0");
|
||||
assertTrue(item->rows > 0, "Focus item rows must be > 0");
|
||||
|
||||
uint8_t newX = x % item->cols;
|
||||
uint8_t newY = y % item->rows;
|
||||
|
||||
if(item->changed != NULL) {
|
||||
uint8_t oldX = item->x;
|
||||
uint8_t oldY = item->y;
|
||||
item->x = newX;
|
||||
item->y = newY;
|
||||
if(!item->changed(item)) {
|
||||
item->x = oldX;
|
||||
item->y = oldY;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
item->x = newX;
|
||||
item->y = newY;
|
||||
}
|
||||
|
||||
void uiFocusMoveDirection(
|
||||
uifocusitem_t *item,
|
||||
const uifocusdirection_t dir
|
||||
) {
|
||||
for(
|
||||
const uifocusdirmap_t *m = UI_FOCUS_DIR_MAP;
|
||||
m->action != INPUT_BIND_NULL;
|
||||
m++
|
||||
) {
|
||||
if(m->direction != dir) continue;
|
||||
|
||||
uint8_t x = (uint8_t)(item->x + m->dx);
|
||||
uint8_t y = (uint8_t)(item->y + m->dy);
|
||||
uiFocusSetPosition(item, x, y);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void uiFocusHandleDirection(
|
||||
uifocusitem_t *item,
|
||||
const uifocusdirection_t dir
|
||||
) {
|
||||
if(item->direction != NULL && item->direction(item, dir)) return;
|
||||
uiFocusMoveDirection(item, dir);
|
||||
}
|
||||
|
||||
void uiFocusUpdate(void) {
|
||||
if(UI_FOCUS.count == 0) return;
|
||||
|
||||
#ifdef DUSK_TIME_DYNAMIC
|
||||
if(TIME.dynamicUpdate) return;
|
||||
#endif
|
||||
|
||||
if(UI_FOCUS.pushedThisTick) {
|
||||
UI_FOCUS.pushedThisTick = false;
|
||||
return;
|
||||
}
|
||||
|
||||
uifocusitem_t *item = &UI_FOCUS.items[UI_FOCUS.count - 1];
|
||||
|
||||
if(inputPressed(INPUT_BIND_ACCEPT)) {
|
||||
if(item->selected != NULL) item->selected(item);
|
||||
return;
|
||||
}
|
||||
|
||||
if(inputPressed(INPUT_BIND_CANCEL)) {
|
||||
uiFocusPop();
|
||||
return;
|
||||
}
|
||||
|
||||
for(
|
||||
const uifocusdirmap_t *m = UI_FOCUS_DIR_MAP;
|
||||
m->action != INPUT_BIND_NULL;
|
||||
m++
|
||||
) {
|
||||
if(!inputPressed(m->action)) continue;
|
||||
UI_FOCUS.direction = m->direction;
|
||||
UI_FOCUS.timeHeld = 0.0f;
|
||||
uiFocusHandleDirection(item, m->direction);
|
||||
return;
|
||||
}
|
||||
|
||||
bool_t held = false;
|
||||
for(
|
||||
const uifocusdirmap_t *m = UI_FOCUS_DIR_MAP;
|
||||
m->action != INPUT_BIND_NULL;
|
||||
m++
|
||||
) {
|
||||
if(m->direction != UI_FOCUS.direction) continue;
|
||||
held = inputIsDown(m->action);
|
||||
break;
|
||||
}
|
||||
|
||||
if(!held) {
|
||||
UI_FOCUS.direction = UI_FOCUS_DIRECTION_NONE;
|
||||
UI_FOCUS.timeHeld = 0.0f;
|
||||
return;
|
||||
}
|
||||
|
||||
UI_FOCUS.timeHeld += TIME.delta;
|
||||
|
||||
if(UI_FOCUS.timeHeld < UI_FOCUS_HOLD_DELAY) return;
|
||||
if(UI_FOCUS.timeHeld < UI_FOCUS_HOLD_DELAY + UI_FOCUS_HOLD_REPEAT) return;
|
||||
UI_FOCUS.timeHeld = UI_FOCUS_HOLD_DELAY;
|
||||
uiFocusHandleDirection(item, UI_FOCUS.direction);
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "uifocusitem.h"
|
||||
#include "input/inputaction.h"
|
||||
|
||||
/** Maximum depth of the focus stack. */
|
||||
#define UI_FOCUS_STACK_MAX 8
|
||||
|
||||
/**
|
||||
* How long a direction must be held before repeating begins, in seconds.
|
||||
*/
|
||||
#define UI_FOCUS_HOLD_DELAY 0.5f
|
||||
|
||||
/**
|
||||
* Interval between repeated moves while a direction is held, in seconds.
|
||||
*/
|
||||
#define UI_FOCUS_HOLD_REPEAT 0.1f
|
||||
|
||||
typedef struct {
|
||||
inputbind_t action;
|
||||
uifocusdirection_t direction;
|
||||
int8_t dx;
|
||||
int8_t dy;
|
||||
} uifocusdirmap_t;
|
||||
|
||||
/**
|
||||
* Mapping of input actions to focus directions, terminated by an
|
||||
* entry with action == INPUT_BIND_NULL.
|
||||
*/
|
||||
extern const uifocusdirmap_t UI_FOCUS_DIR_MAP[];
|
||||
|
||||
/**
|
||||
* A stack of focused UI items. Push an item when a widget captures
|
||||
* focus; pop it when focus is released. The topmost item is always
|
||||
* the active focus context.
|
||||
*/
|
||||
typedef struct {
|
||||
uifocusitem_t items[UI_FOCUS_STACK_MAX];
|
||||
uint8_t count;
|
||||
uifocusdirection_t direction;
|
||||
float_t timeHeld;
|
||||
bool_t pushedThisTick;
|
||||
} uifocus_t;
|
||||
|
||||
extern uifocus_t UI_FOCUS;
|
||||
|
||||
/**
|
||||
* Initializes the focus system, zeroing all state.
|
||||
*/
|
||||
void uiFocusInit(void);
|
||||
|
||||
/**
|
||||
* Pushes a new focus item onto the stack with the given grid dimensions
|
||||
* and callbacks. x and y are initialized to 0.
|
||||
*
|
||||
* @param cols Number of columns in the focus grid.
|
||||
* @param rows Number of rows in the focus grid.
|
||||
* @param selected Called when the user selects the focused cell.
|
||||
* @param changed Called when the focused cell position changes.
|
||||
* @param closed Called when this focus item is popped.
|
||||
* @param direction Called on a direction press/hold before the default
|
||||
* cell-to-cell movement is applied; may be NULL.
|
||||
* @param user Arbitrary pointer stored on the item before changed fires.
|
||||
* @returns Pointer to the newly pushed focus item.
|
||||
*/
|
||||
uifocusitem_t * uiFocusPush(
|
||||
const uint8_t cols,
|
||||
const uint8_t rows,
|
||||
uifocusitemcallback_t selected,
|
||||
uifocusitemcallback_t changed,
|
||||
uifocusitemcallback_t closed,
|
||||
uifocusitemdirectioncallback_t direction,
|
||||
void *user
|
||||
);
|
||||
|
||||
/**
|
||||
* Pops the topmost focus item from the stack, invoking its closed
|
||||
* callback if one is set.
|
||||
*/
|
||||
void uiFocusPop(void);
|
||||
|
||||
/**
|
||||
* Pops an item and anything that was pushed after it from the focus stack.
|
||||
*
|
||||
* @param item The focus item to pop to. Must be on the stack.
|
||||
*/
|
||||
void uiFocusPopItem(uifocusitem_t *item);
|
||||
|
||||
/**
|
||||
* Manually sets the cursor position of the topmost focus item and
|
||||
* fires its changed callback.
|
||||
*
|
||||
* @param x Column to move to.
|
||||
* @param y Row to move to.
|
||||
*/
|
||||
void uiFocusSetPosition(uifocusitem_t *item, const uint8_t x, const uint8_t y);
|
||||
|
||||
/**
|
||||
* Moves the topmost focus item one step in the given direction,
|
||||
* wrapping at the grid edges, and fires its changed callback.
|
||||
*
|
||||
* @param item The focus item to move.
|
||||
* @param dir Direction to move.
|
||||
*/
|
||||
void uiFocusMoveDirection(
|
||||
uifocusitem_t *item,
|
||||
const uifocusdirection_t dir
|
||||
);
|
||||
|
||||
/**
|
||||
* Handles a direction press/hold for the given item: gives the item's
|
||||
* direction callback (if any) first refusal, falling back to the
|
||||
* default cell-to-cell movement if it's unset or returns false.
|
||||
*
|
||||
* @param item The focus item to move.
|
||||
* @param dir Direction that was pressed or held.
|
||||
*/
|
||||
void uiFocusHandleDirection(
|
||||
uifocusitem_t *item,
|
||||
const uifocusdirection_t dir
|
||||
);
|
||||
|
||||
/**
|
||||
* Updates the focus system. Handles first-press movement and
|
||||
* held-direction repeating. Called once per game tick.
|
||||
*/
|
||||
void uiFocusUpdate(void);
|
||||
@@ -0,0 +1,57 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "dusk.h"
|
||||
|
||||
typedef struct uifocusitem_s uifocusitem_t;
|
||||
|
||||
typedef enum {
|
||||
UI_FOCUS_DIRECTION_NONE,
|
||||
UI_FOCUS_DIRECTION_UP,
|
||||
UI_FOCUS_DIRECTION_DOWN,
|
||||
UI_FOCUS_DIRECTION_LEFT,
|
||||
UI_FOCUS_DIRECTION_RIGHT
|
||||
} uifocusdirection_t;
|
||||
|
||||
/**
|
||||
* Callback invoked when a focus item's selected cell changes.
|
||||
*
|
||||
* @param item The focus item that changed.
|
||||
*/
|
||||
typedef bool_t (*uifocusitemcallback_t)(const uifocusitem_t *item);
|
||||
|
||||
/**
|
||||
* Callback invoked when a direction is pressed or held-repeated while
|
||||
* this item is focused, before the default cell-to-cell movement is
|
||||
* applied.
|
||||
*
|
||||
* @param item The focus item that is currently focused.
|
||||
* @param direction The direction that was pressed.
|
||||
* @returns True if the direction was fully handled and the default
|
||||
* grid movement should be skipped; false to fall through to it.
|
||||
*/
|
||||
typedef bool_t (*uifocusitemdirectioncallback_t)(
|
||||
const uifocusitem_t *item,
|
||||
const uifocusdirection_t direction
|
||||
);
|
||||
|
||||
/**
|
||||
* A single entry on the UI focus stack. Tracks the focused cell
|
||||
* within a grid of cols x rows, and the current x/y position.
|
||||
*/
|
||||
struct uifocusitem_s {
|
||||
uint8_t cols;
|
||||
uint8_t rows;
|
||||
uint8_t x;
|
||||
uint8_t y;
|
||||
uifocusitemcallback_t selected;
|
||||
uifocusitemcallback_t changed;
|
||||
uifocusitemcallback_t closed;
|
||||
uifocusitemdirectioncallback_t direction;
|
||||
void *user;
|
||||
};
|
||||
@@ -0,0 +1,12 @@
|
||||
# Copyright (c) 2026 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
||||
PUBLIC
|
||||
uiframe.c
|
||||
uiconfirm.c
|
||||
)
|
||||
|
||||
add_subdirectory(settings)
|
||||
@@ -0,0 +1,13 @@
|
||||
# Copyright (c) 2026 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
||||
PUBLIC
|
||||
uisettings.c
|
||||
uisettingsgeneral.c
|
||||
uisettingsinput.c
|
||||
uisettingsdisplay.c
|
||||
uisettingsaudio.c
|
||||
)
|
||||
@@ -0,0 +1,248 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "uisettings.h"
|
||||
#include "uisettingsgeneral.h"
|
||||
#include "uisettingsinput.h"
|
||||
#include "uisettingsdisplay.h"
|
||||
#include "uisettingsaudio.h"
|
||||
#include "ui/frame/uiframe.h"
|
||||
#include "ui/frame/uiconfirm.h"
|
||||
#include "util/memory.h"
|
||||
#include "display/text/text.h"
|
||||
#include "display/screen/screen.h"
|
||||
#include "assert/assert.h"
|
||||
#include "locale/localemanager.h"
|
||||
#include "asset/loader/locale/assetlocaleloader.h"
|
||||
|
||||
uisettings_t UI_SETTINGS;
|
||||
|
||||
uisettingstabdef_t UI_SETTINGS_TAB_DEFS[UI_SETTINGS_TAB_COUNT] = {
|
||||
{
|
||||
.localeId = "ui.settings.tabs.general",
|
||||
.init = uiSettingsGeneralInit,
|
||||
.menu = (uimenu_t *)&UI_SETTINGS.data,
|
||||
.load = uiSettingsGeneralLoad,
|
||||
.apply = uiSettingsGeneralApply,
|
||||
.hasChanges = uiSettingsGeneralHasChanges
|
||||
},
|
||||
|
||||
{
|
||||
.localeId = "ui.settings.tabs.input",
|
||||
.init = uiSettingsInputInit,
|
||||
.menu = (uimenu_t *)&UI_SETTINGS.data,
|
||||
.load = uiSettingsInputLoad,
|
||||
.apply = uiSettingsInputApply,
|
||||
.hasChanges = uiSettingsInputHasChanges
|
||||
},
|
||||
|
||||
{
|
||||
.localeId = "ui.settings.tabs.display",
|
||||
.init = uiSettingsDisplayInit,
|
||||
.menu = (uimenu_t *)&UI_SETTINGS.data,
|
||||
.load = uiSettingsDisplayLoad,
|
||||
.apply = uiSettingsDisplayApply,
|
||||
.hasChanges = uiSettingsDisplayHasChanges
|
||||
},
|
||||
|
||||
{
|
||||
.localeId = "ui.settings.tabs.audio",
|
||||
.init = uiSettingsAudioInit,
|
||||
.menu = (uimenu_t *)&UI_SETTINGS.data,
|
||||
.load = uiSettingsAudioLoad,
|
||||
.apply = uiSettingsAudioApply,
|
||||
.hasChanges = uiSettingsAudioHasChanges
|
||||
}
|
||||
};
|
||||
|
||||
static uisettingstabdef_t UI_SETTINGS_TOP_DEF = {
|
||||
.menu = &UI_SETTINGS.tabsMenu,
|
||||
.load = uiSettingsLoad,
|
||||
.hasChanges = uiSettingsHasChanges
|
||||
};
|
||||
|
||||
static uisettingstabdef_t *UI_SETTINGS_PENDING_DISCARD = NULL;
|
||||
static uisettingstabdef_t *UI_SETTINGS_ACTIVE_TAB = NULL;
|
||||
|
||||
errorret_t uiSettingsActivateTab(uisettingstabdef_t *def) {
|
||||
if(def == UI_SETTINGS_ACTIVE_TAB) errorOk();
|
||||
|
||||
errorChain(def->init(&UI_SETTINGS.data));
|
||||
def->menu->user = def;
|
||||
def->load();
|
||||
UI_SETTINGS_ACTIVE_TAB = def;
|
||||
|
||||
errorOk();
|
||||
}
|
||||
|
||||
void uiSettingsTabChanged(
|
||||
const uimenu_t *menu,
|
||||
const uint8_t index,
|
||||
const uimenuitem_t *item
|
||||
) {
|
||||
if(index >= UI_SETTINGS_TAB_COUNT) return;
|
||||
errorCatch(uiSettingsActivateTab(&UI_SETTINGS_TAB_DEFS[index]));
|
||||
}
|
||||
|
||||
void uiSettingsTabSelected(
|
||||
const uimenu_t *menu,
|
||||
const uint8_t index,
|
||||
const uimenuitem_t *item
|
||||
) {
|
||||
if(index >= UI_SETTINGS_TAB_COUNT) return;
|
||||
|
||||
uisettingstabdef_t *def = &UI_SETTINGS_TAB_DEFS[index];
|
||||
errorCatch(uiSettingsActivateTab(def));
|
||||
uiMenuOpen(def->menu);
|
||||
}
|
||||
|
||||
errorret_t uiSettingsInit(void) {
|
||||
memoryZero(&UI_SETTINGS, sizeof(uisettings_t));
|
||||
UI_SETTINGS_ACTIVE_TAB = NULL;
|
||||
|
||||
for(uint8_t i = 0; i < UI_SETTINGS_TAB_COUNT; i++) {
|
||||
errorChain(assetLocaleGetString(
|
||||
&LOCALE.entry->data.locale,
|
||||
UI_SETTINGS_TAB_DEFS[i].localeId,
|
||||
0,
|
||||
UI_SETTINGS.tabLabels[i],
|
||||
UI_SETTINGS_TAB_LABEL_MAX
|
||||
));
|
||||
}
|
||||
|
||||
MENU_BEGIN(
|
||||
&UI_SETTINGS.tabsMenu, UI_SETTINGS.tabs, uiSettingsTabSelected,
|
||||
uiSettingsDiscardMenuClosed, uiSettingsTabChanged
|
||||
);
|
||||
for(uint8_t i = 0; i < UI_SETTINGS_TAB_COUNT; i++) {
|
||||
MENU_TAB(UI_SETTINGS.tabLabels[i]);
|
||||
}
|
||||
MENU_END(UI_SETTINGS.tabs, menuIndex);
|
||||
|
||||
UI_SETTINGS.tabsMenu.user = &UI_SETTINGS_TOP_DEF;
|
||||
|
||||
errorChain(assetLocaleGetString(
|
||||
&LOCALE.entry->data.locale,
|
||||
"ui.settings.apply",
|
||||
0,
|
||||
UI_SETTINGS.applyLabel,
|
||||
UI_SETTINGS_APPLY_LABEL_MAX
|
||||
));
|
||||
|
||||
errorChain(uiSettingsActivateTab(&UI_SETTINGS_TAB_DEFS[0]));
|
||||
|
||||
errorOk();
|
||||
}
|
||||
|
||||
errorret_t uiSettingsDraw(void) {
|
||||
if(!uiMenuIsActive(&UI_SETTINGS.tabsMenu)) errorOk();
|
||||
|
||||
const float_t width = SCREEN.width;
|
||||
const float_t height = SCREEN.height;
|
||||
const float_t x = (float_t)SCREEN.scanX +
|
||||
((float_t)SCREEN.scanWidth - width) * 0.5f;
|
||||
const float_t y = (float_t)SCREEN.scanY +
|
||||
((float_t)SCREEN.scanHeight - height) * 0.5f;
|
||||
|
||||
errorChain(uiFrameDrawCached(&UI_SETTINGS.frameCache, x, y, width, height));
|
||||
|
||||
const float_t contentX = x + UI_FRAME_START_X;
|
||||
const float_t contentY = y + UI_FRAME_START_Y;
|
||||
const float_t contentWidth = width - (UI_FRAME_START_X * 2);
|
||||
const float_t contentHeight = height - (UI_FRAME_START_Y * 2);
|
||||
|
||||
errorChain(uiMenuDraw(
|
||||
&UI_SETTINGS.tabsMenu,
|
||||
contentX,
|
||||
contentY,
|
||||
contentWidth,
|
||||
contentHeight
|
||||
));
|
||||
|
||||
const float_t tabsRowHeight = (float_t)FONT_DEFAULT.tileset->tileHeight;
|
||||
const float_t pageY = contentY + tabsRowHeight + UI_FRAME_PADDING_Y;
|
||||
const float_t pageHeight = contentHeight - tabsRowHeight - UI_FRAME_PADDING_Y;
|
||||
|
||||
if(UI_SETTINGS_ACTIVE_TAB != NULL) {
|
||||
errorChain(uiMenuDraw(
|
||||
UI_SETTINGS_ACTIVE_TAB->menu, contentX, pageY, contentWidth, pageHeight
|
||||
));
|
||||
}
|
||||
|
||||
errorOk();
|
||||
}
|
||||
|
||||
errorret_t uiSettingsUpdate(void) {
|
||||
if(!UI_SETTINGS_PENDING_DISCARD) errorOk();
|
||||
|
||||
uisettingstabdef_t *def = UI_SETTINGS_PENDING_DISCARD;
|
||||
UI_SETTINGS_PENDING_DISCARD = NULL;
|
||||
|
||||
return uiSettingsDiscardUpdate(def);
|
||||
}
|
||||
|
||||
bool_t uiSettingsIsOpen(void) {
|
||||
return uiMenuIsActive(&UI_SETTINGS.tabsMenu);
|
||||
}
|
||||
|
||||
void uiSettingsOpen() {
|
||||
uiSettingsLoad();
|
||||
uiMenuOpen(&UI_SETTINGS.tabsMenu);
|
||||
}
|
||||
|
||||
void uiSettingsClose() {
|
||||
uiMenuClose(&UI_SETTINGS.tabsMenu);
|
||||
}
|
||||
|
||||
errorret_t uiSettingsDispose(void) {
|
||||
errorOk();
|
||||
}
|
||||
|
||||
void uiSettingsLoad(void) {
|
||||
if(UI_SETTINGS_ACTIVE_TAB != NULL) UI_SETTINGS_ACTIVE_TAB->load();
|
||||
}
|
||||
|
||||
void uiSettingsApply(void) {
|
||||
if(UI_SETTINGS_ACTIVE_TAB != NULL) UI_SETTINGS_ACTIVE_TAB->apply();
|
||||
}
|
||||
|
||||
bool_t uiSettingsHasChanges(void) {
|
||||
return UI_SETTINGS_ACTIVE_TAB != NULL && UI_SETTINGS_ACTIVE_TAB->hasChanges();
|
||||
}
|
||||
|
||||
void uiSettingsDiscardMenuClosed(const uimenu_t *menu) {
|
||||
uisettingstabdef_t *def = (uisettingstabdef_t *)menu->user;
|
||||
if(def->hasChanges()) UI_SETTINGS_PENDING_DISCARD = def;
|
||||
}
|
||||
|
||||
errorret_t uiSettingsDiscardUpdate(uisettingstabdef_t *def) {
|
||||
#define UI_SETTINGS_DISCARD_TEXT_MAX 128
|
||||
char_t text[UI_SETTINGS_DISCARD_TEXT_MAX];
|
||||
errorChain(assetLocaleGetString(
|
||||
&LOCALE.entry->data.locale,
|
||||
"ui.confirm.discard_changes",
|
||||
0,
|
||||
text,
|
||||
UI_SETTINGS_DISCARD_TEXT_MAX
|
||||
));
|
||||
#undef UI_SETTINGS_DISCARD_TEXT_MAX
|
||||
|
||||
uiConfirmOpen(text, uiSettingsDiscardConfirmResult, def);
|
||||
|
||||
errorOk();
|
||||
}
|
||||
|
||||
void uiSettingsDiscardConfirmResult(const bool_t result, void *user) {
|
||||
uisettingstabdef_t *def = (uisettingstabdef_t *)user;
|
||||
|
||||
if(!result) {
|
||||
uiMenuOpen(def->menu);
|
||||
return;
|
||||
}
|
||||
|
||||
def->load();
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "error/error.h"
|
||||
#include "ui/widget/uimenu.h"
|
||||
#include "ui/frame/uiframe.h"
|
||||
#include "uisettingsdata.h"
|
||||
|
||||
#define UI_SETTINGS_TAB_COUNT 4
|
||||
#define UI_SETTINGS_TAB_LABEL_MAX 32
|
||||
#define UI_SETTINGS_APPLY_LABEL_MAX 32
|
||||
|
||||
typedef struct {
|
||||
const char_t *localeId;
|
||||
errorret_t (*init)(uisettingsdata_t *data);
|
||||
uimenu_t *menu;
|
||||
void (*load)(void);
|
||||
void (*apply)(void);
|
||||
bool_t (*hasChanges)(void);
|
||||
} uisettingstabdef_t;
|
||||
|
||||
typedef struct {
|
||||
uimenu_t tabsMenu;
|
||||
uimenuitem_t tabs[UI_SETTINGS_TAB_COUNT];
|
||||
char_t tabLabels[UI_SETTINGS_TAB_COUNT][UI_SETTINGS_TAB_LABEL_MAX];
|
||||
char_t applyLabel[UI_SETTINGS_APPLY_LABEL_MAX];
|
||||
uisettingsdata_t data;
|
||||
uiframecache_t frameCache;
|
||||
} uisettings_t;
|
||||
|
||||
extern uisettings_t UI_SETTINGS;
|
||||
extern uisettingstabdef_t UI_SETTINGS_TAB_DEFS[UI_SETTINGS_TAB_COUNT];
|
||||
|
||||
/**
|
||||
* Menu closed callback that flags a pending discard-changes
|
||||
* confirmation if the menu's settings page/panel reports unsaved
|
||||
* changes. Pass this directly as a settings page menu's closed
|
||||
* callback. The pending def is picked up by uiSettingsUpdate on the
|
||||
* next tick.
|
||||
*
|
||||
* @param menu The menu that was just closed.
|
||||
*/
|
||||
void uiSettingsDiscardMenuClosed(const uimenu_t *menu);
|
||||
|
||||
/**
|
||||
* Shows the discard-changes confirmation dialog for def. Called once
|
||||
* by uiSettingsUpdate when uiSettingsDiscardMenuClosed has flagged a
|
||||
* pending def.
|
||||
*
|
||||
* @param def The tab/panel def to show the confirmation for.
|
||||
* @return Any error that occurs.
|
||||
*/
|
||||
errorret_t uiSettingsDiscardUpdate(uisettingstabdef_t *def);
|
||||
|
||||
/**
|
||||
* Callback passed to uiConfirmOpen by uiSettingsDiscardUpdate. Reopens
|
||||
* the menu if the user chose to keep editing, otherwise reloads the
|
||||
* widgets back to the actual engine values.
|
||||
*
|
||||
* @param result True if the user confirmed discarding changes, false
|
||||
* to keep editing.
|
||||
* @param user The uisettingstabdef_t* this confirmation belongs to.
|
||||
*/
|
||||
void uiSettingsDiscardConfirmResult(const bool_t result, void *user);
|
||||
|
||||
/**
|
||||
* Initializes the settings panel and all of its category pages.
|
||||
*
|
||||
* @return Any error that occurs.
|
||||
*/
|
||||
errorret_t uiSettingsInit(void);
|
||||
|
||||
/**
|
||||
* Draws the settings panel. No-op when not visible.
|
||||
*
|
||||
* @return Any error that occurs.
|
||||
*/
|
||||
errorret_t uiSettingsDraw(void);
|
||||
|
||||
/**
|
||||
* Updates the settings panel. Shows a discard-changes confirmation if
|
||||
* the panel was just closed with unsaved changes.
|
||||
*
|
||||
* @return Any error that occurs.
|
||||
*/
|
||||
errorret_t uiSettingsUpdate(void);
|
||||
|
||||
/**
|
||||
* Returns true when the settings panel is currently open.
|
||||
*
|
||||
* @returns True if open.
|
||||
*/
|
||||
bool_t uiSettingsIsOpen(void);
|
||||
|
||||
/**
|
||||
* Opens the settings panel. No-op when already open.
|
||||
*/
|
||||
void uiSettingsOpen();
|
||||
|
||||
/**
|
||||
* Closes the settings panel. No-op when already closed.
|
||||
*/
|
||||
void uiSettingsClose();
|
||||
|
||||
/**
|
||||
* Disposes of the settings panel.
|
||||
*
|
||||
* @return Any error that occurs.
|
||||
*/
|
||||
errorret_t uiSettingsDispose(void);
|
||||
|
||||
/**
|
||||
* Loads every category page's widgets from the current engine settings.
|
||||
* Called automatically by uiSettingsOpen.
|
||||
*/
|
||||
void uiSettingsLoad(void);
|
||||
|
||||
/**
|
||||
* Applies every category page's widget values to the engine settings.
|
||||
* Called automatically when a page's own Apply button is pressed.
|
||||
*/
|
||||
void uiSettingsApply(void);
|
||||
|
||||
/**
|
||||
* Returns whether any category page has a widget value that differs
|
||||
* from what was loaded.
|
||||
*
|
||||
* @returns True if there are unsaved changes.
|
||||
*/
|
||||
bool_t uiSettingsHasChanges(void);
|
||||
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "uisettingsaudio.h"
|
||||
#include "uisettings.h"
|
||||
#include "assert/assert.h"
|
||||
#include "util/memory.h"
|
||||
|
||||
void uiSettingsAudioSelected(
|
||||
const uimenu_t *menu,
|
||||
const uint8_t index,
|
||||
const uimenuitem_t *item
|
||||
) {
|
||||
if(index != UI_SETTINGS_AUDIO_INDEX_APPLY) return;
|
||||
uiSettingsAudioApply();
|
||||
}
|
||||
|
||||
errorret_t uiSettingsAudioInit(uisettingsdata_t *data) {
|
||||
uisettingsaudio_t *audio = &data->audio;
|
||||
memoryZero(audio, sizeof(uisettingsaudio_t));
|
||||
|
||||
MENU_BEGIN(
|
||||
&audio->menu, audio->items,
|
||||
uiSettingsAudioSelected, uiSettingsDiscardMenuClosed, NULL
|
||||
);
|
||||
MENU_LABEL("No audio settings yet");
|
||||
MENU_BUTTON(UI_SETTINGS.applyLabel);
|
||||
|
||||
MENU_END(audio->items, 1);
|
||||
|
||||
errorOk();
|
||||
}
|
||||
|
||||
void uiSettingsAudioLoad(void) {
|
||||
}
|
||||
|
||||
void uiSettingsAudioApply(void) {
|
||||
uiMenuClose(&UI_SETTINGS.data.audio.menu);
|
||||
}
|
||||
|
||||
bool_t uiSettingsAudioHasChanges(void) {
|
||||
return false;
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "error/error.h"
|
||||
#include "uisettingsdata.h"
|
||||
|
||||
/**
|
||||
* Initializes the audio settings page into the shared settings data
|
||||
* union.
|
||||
*
|
||||
* @param data The shared settings data union to initialize into.
|
||||
* @return Any error that occurs.
|
||||
*/
|
||||
errorret_t uiSettingsAudioInit(uisettingsdata_t *data);
|
||||
|
||||
/**
|
||||
* Loads the page's widgets from the current engine audio settings.
|
||||
*/
|
||||
void uiSettingsAudioLoad(void);
|
||||
|
||||
/**
|
||||
* Applies the page's widget values to the engine audio settings.
|
||||
*/
|
||||
void uiSettingsAudioApply(void);
|
||||
|
||||
/**
|
||||
* Returns whether any widget's value differs from what was loaded.
|
||||
*
|
||||
* @returns True if there are unsaved changes.
|
||||
*/
|
||||
bool_t uiSettingsAudioHasChanges(void);
|
||||
@@ -0,0 +1,67 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "error/error.h"
|
||||
#include "ui/widget/uimenu.h"
|
||||
|
||||
#define UI_SETTINGS_GENERAL_ITEM_COUNT 3
|
||||
#define UI_SETTINGS_GENERAL_INDEX_LANGUAGE 0
|
||||
#define UI_SETTINGS_GENERAL_INDEX_LANGUAGE_DETAIL 1
|
||||
#define UI_SETTINGS_GENERAL_INDEX_APPLY 2
|
||||
#define UI_SETTINGS_GENERAL_LOCALE_COUNT 3
|
||||
#define UI_SETTINGS_GENERAL_LABEL_MAX 32
|
||||
#define UI_SETTINGS_GENERAL_INFO_MAX 64
|
||||
|
||||
typedef struct {
|
||||
uimenu_t menu;
|
||||
uimenuitem_t items[UI_SETTINGS_GENERAL_ITEM_COUNT];
|
||||
const char_t *localeNames[UI_SETTINGS_GENERAL_LOCALE_COUNT];
|
||||
char_t languageLabel[UI_SETTINGS_GENERAL_LABEL_MAX];
|
||||
char_t labelInfo[UI_SETTINGS_GENERAL_INFO_MAX];
|
||||
} uisettingsgeneral_t;
|
||||
|
||||
#define UI_SETTINGS_INPUT_ITEM_COUNT 2
|
||||
#define UI_SETTINGS_INPUT_LABEL_MAX 32
|
||||
#define UI_SETTINGS_INPUT_INDEX_DEADZONE 0
|
||||
#define UI_SETTINGS_INPUT_INDEX_APPLY 1
|
||||
|
||||
typedef struct {
|
||||
uimenu_t menu;
|
||||
uimenuitem_t items[UI_SETTINGS_INPUT_ITEM_COUNT];
|
||||
char_t deadzoneLabel[UI_SETTINGS_INPUT_LABEL_MAX];
|
||||
} uisettingsinput_t;
|
||||
|
||||
#define UI_SETTINGS_DISPLAY_ITEM_COUNT 2
|
||||
#define UI_SETTINGS_DISPLAY_INDEX_APPLY 1
|
||||
|
||||
typedef struct {
|
||||
uimenu_t menu;
|
||||
uimenuitem_t items[UI_SETTINGS_DISPLAY_ITEM_COUNT];
|
||||
} uisettingsdisplay_t;
|
||||
|
||||
#define UI_SETTINGS_AUDIO_ITEM_COUNT 2
|
||||
#define UI_SETTINGS_AUDIO_INDEX_APPLY 1
|
||||
|
||||
typedef struct {
|
||||
uimenu_t menu;
|
||||
uimenuitem_t items[UI_SETTINGS_AUDIO_ITEM_COUNT];
|
||||
} uisettingsaudio_t;
|
||||
|
||||
/**
|
||||
* Shared, overlapping storage for every settings tab's page data. Only
|
||||
* one member is ever live at a time -- the active tab's Init writes
|
||||
* into it, overwriting whatever the previously active tab left there.
|
||||
* This trades simultaneous access to every tab for a memory footprint
|
||||
* of only the single largest page.
|
||||
*/
|
||||
typedef union {
|
||||
uisettingsgeneral_t general;
|
||||
uisettingsinput_t input;
|
||||
uisettingsdisplay_t display;
|
||||
uisettingsaudio_t audio;
|
||||
} uisettingsdata_t;
|
||||
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "uisettingsdisplay.h"
|
||||
#include "uisettings.h"
|
||||
#include "assert/assert.h"
|
||||
#include "util/memory.h"
|
||||
|
||||
void uiSettingsDisplaySelected(
|
||||
const uimenu_t *menu,
|
||||
const uint8_t index,
|
||||
const uimenuitem_t *item
|
||||
) {
|
||||
if(index != UI_SETTINGS_DISPLAY_INDEX_APPLY) return;
|
||||
uiSettingsDisplayApply();
|
||||
}
|
||||
|
||||
errorret_t uiSettingsDisplayInit(uisettingsdata_t *data) {
|
||||
uisettingsdisplay_t *display = &data->display;
|
||||
memoryZero(display, sizeof(uisettingsdisplay_t));
|
||||
|
||||
MENU_BEGIN(
|
||||
&display->menu, display->items,
|
||||
uiSettingsDisplaySelected, uiSettingsDiscardMenuClosed, NULL
|
||||
);
|
||||
MENU_LABEL("No display settings yet");
|
||||
MENU_BUTTON(UI_SETTINGS.applyLabel);
|
||||
|
||||
MENU_END(display->items, 1);
|
||||
|
||||
errorOk();
|
||||
}
|
||||
|
||||
void uiSettingsDisplayLoad(void) {
|
||||
}
|
||||
|
||||
void uiSettingsDisplayApply(void) {
|
||||
uiMenuClose(&UI_SETTINGS.data.display.menu);
|
||||
}
|
||||
|
||||
bool_t uiSettingsDisplayHasChanges(void) {
|
||||
return false;
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "error/error.h"
|
||||
#include "uisettingsdata.h"
|
||||
|
||||
/**
|
||||
* Initializes the display settings page into the shared settings data
|
||||
* union.
|
||||
*
|
||||
* @param data The shared settings data union to initialize into.
|
||||
* @return Any error that occurs.
|
||||
*/
|
||||
errorret_t uiSettingsDisplayInit(uisettingsdata_t *data);
|
||||
|
||||
/**
|
||||
* Loads the page's widgets from the current engine display settings.
|
||||
*/
|
||||
void uiSettingsDisplayLoad(void);
|
||||
|
||||
/**
|
||||
* Applies the page's widget values to the engine display settings.
|
||||
*/
|
||||
void uiSettingsDisplayApply(void);
|
||||
|
||||
/**
|
||||
* Returns whether any widget's value differs from what was loaded.
|
||||
*
|
||||
* @returns True if there are unsaved changes.
|
||||
*/
|
||||
bool_t uiSettingsDisplayHasChanges(void);
|
||||
@@ -0,0 +1,117 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "uisettingsgeneral.h"
|
||||
#include "uisettings.h"
|
||||
#include "assert/assert.h"
|
||||
#include "util/memory.h"
|
||||
#include "util/string.h"
|
||||
#include "locale/localemanager.h"
|
||||
#include "locale/localeinfo.h"
|
||||
#include "asset/loader/locale/assetlocaleloader.h"
|
||||
|
||||
static const localeinfo_t *const UI_SETTINGS_GENERAL_LOCALES[
|
||||
UI_SETTINGS_GENERAL_LOCALE_COUNT
|
||||
] = {
|
||||
&LOCALE_EN_US,
|
||||
&LOCALE_JP_JP,
|
||||
&LOCALE_ES_MX
|
||||
};
|
||||
|
||||
void uiSettingsGeneralSelected(
|
||||
const uimenu_t *menu,
|
||||
const uint8_t index,
|
||||
const uimenuitem_t *item
|
||||
) {
|
||||
switch(index) {
|
||||
case UI_SETTINGS_GENERAL_INDEX_APPLY:
|
||||
uiSettingsGeneralApply();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
errorret_t uiSettingsGeneralInit(uisettingsdata_t *data) {
|
||||
uisettingsgeneral_t *general = &data->general;
|
||||
memoryZero(general, sizeof(uisettingsgeneral_t));
|
||||
|
||||
for(uint8_t i = 0; i < UI_SETTINGS_GENERAL_LOCALE_COUNT; i++) {
|
||||
general->localeNames[i] = UI_SETTINGS_GENERAL_LOCALES[i]->name;
|
||||
}
|
||||
|
||||
errorChain(assetLocaleGetString(
|
||||
&LOCALE.entry->data.locale,
|
||||
"ui.settings.general.language",
|
||||
0,
|
||||
general->languageLabel,
|
||||
UI_SETTINGS_GENERAL_LABEL_MAX
|
||||
));
|
||||
errorChain(assetLocaleGetString(
|
||||
&LOCALE.entry->data.locale,
|
||||
"ui.settings.general.language_detail",
|
||||
0,
|
||||
general->labelInfo,
|
||||
UI_SETTINGS_GENERAL_INFO_MAX
|
||||
));
|
||||
|
||||
MENU_BEGIN(
|
||||
&general->menu, general->items,
|
||||
uiSettingsGeneralSelected, uiSettingsDiscardMenuClosed, NULL
|
||||
);
|
||||
|
||||
MENU_DROPDOWN(
|
||||
general->languageLabel, general->localeNames,
|
||||
UI_SETTINGS_GENERAL_LOCALE_COUNT, 0
|
||||
);
|
||||
MENU_LABEL(general->labelInfo);
|
||||
|
||||
MENU_BUTTON(UI_SETTINGS.applyLabel);
|
||||
MENU_END(general->items, 1);
|
||||
|
||||
errorOk();
|
||||
}
|
||||
|
||||
void uiSettingsGeneralLoad(void) {
|
||||
uisettingsgeneral_t *general = &UI_SETTINGS.data.general;
|
||||
|
||||
uint8_t index = 0;
|
||||
for(uint8_t i = 0; i < UI_SETTINGS_GENERAL_LOCALE_COUNT; i++) {
|
||||
if(stringCompare(LOCALE.locale->file, UI_SETTINGS_GENERAL_LOCALES[i]->file) != 0) {
|
||||
continue;
|
||||
}
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
|
||||
uiDropdownSetSelectedIndex(
|
||||
&general->items[UI_SETTINGS_GENERAL_INDEX_LANGUAGE].dropdown, index
|
||||
);
|
||||
}
|
||||
|
||||
void uiSettingsGeneralApply(void) {
|
||||
uisettingsgeneral_t *general = &UI_SETTINGS.data.general;
|
||||
|
||||
uint8_t index = uiDropdownGetSelectedIndex(
|
||||
&general->items[UI_SETTINGS_GENERAL_INDEX_LANGUAGE].dropdown
|
||||
);
|
||||
errorCatch(localeManagerSetLocale(UI_SETTINGS_GENERAL_LOCALES[index]));
|
||||
|
||||
uiMenuClose(&general->menu);
|
||||
}
|
||||
|
||||
bool_t uiSettingsGeneralHasChanges(void) {
|
||||
uisettingsgeneral_t *general = &UI_SETTINGS.data.general;
|
||||
|
||||
uint8_t index = uiDropdownGetSelectedIndex(
|
||||
&general->items[UI_SETTINGS_GENERAL_INDEX_LANGUAGE].dropdown
|
||||
);
|
||||
return stringCompare(
|
||||
LOCALE.locale->file, UI_SETTINGS_GENERAL_LOCALES[index]->file
|
||||
) != 0;
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "error/error.h"
|
||||
#include "uisettingsdata.h"
|
||||
|
||||
/**
|
||||
* Initializes the general settings page into the shared settings data
|
||||
* union.
|
||||
*
|
||||
* @param data The shared settings data union to initialize into.
|
||||
* @return Any error that occurs.
|
||||
*/
|
||||
errorret_t uiSettingsGeneralInit(uisettingsdata_t *data);
|
||||
|
||||
/**
|
||||
* Loads the page's widgets from the current engine general settings.
|
||||
*/
|
||||
void uiSettingsGeneralLoad(void);
|
||||
|
||||
/**
|
||||
* Applies the page's widget values to the engine general settings.
|
||||
*/
|
||||
void uiSettingsGeneralApply(void);
|
||||
|
||||
/**
|
||||
* Returns whether any widget's value differs from what was loaded.
|
||||
*
|
||||
* @returns True if there are unsaved changes.
|
||||
*/
|
||||
bool_t uiSettingsGeneralHasChanges(void);
|
||||
@@ -0,0 +1,82 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "uisettingsinput.h"
|
||||
#include "uisettings.h"
|
||||
#include "assert/assert.h"
|
||||
#include "util/memory.h"
|
||||
#include "locale/localemanager.h"
|
||||
#include "asset/loader/locale/assetlocaleloader.h"
|
||||
#include "input/input.h"
|
||||
#include "save/savesettings.h"
|
||||
|
||||
void uiSettingsInputSelected(
|
||||
const uimenu_t *menu,
|
||||
const uint8_t index,
|
||||
const uimenuitem_t *item
|
||||
) {
|
||||
if(index != UI_SETTINGS_INPUT_INDEX_APPLY) return;
|
||||
uiSettingsInputApply();
|
||||
}
|
||||
|
||||
errorret_t uiSettingsInputInit(uisettingsdata_t *data) {
|
||||
uisettingsinput_t *input = &data->input;
|
||||
memoryZero(input, sizeof(uisettingsinput_t));
|
||||
|
||||
MENU_BEGIN(
|
||||
&input->menu, input->items,
|
||||
uiSettingsInputSelected, uiSettingsDiscardMenuClosed, NULL
|
||||
);
|
||||
#ifdef DUSK_INPUT_GAMEPAD
|
||||
errorChain(assetLocaleGetString(
|
||||
&LOCALE.entry->data.locale,
|
||||
"ui.settings.input.deadzone",
|
||||
0,
|
||||
input->deadzoneLabel,
|
||||
UI_SETTINGS_INPUT_LABEL_MAX
|
||||
));
|
||||
MENU_SLIDER_FLOAT(
|
||||
input->deadzoneLabel, INPUT_DEADZONE_DEFAULT, 0.0f, 1.0f, 0.05f
|
||||
);
|
||||
#else
|
||||
MENU_LABEL("No input settings yet");
|
||||
#endif
|
||||
|
||||
MENU_BUTTON(UI_SETTINGS.applyLabel);
|
||||
MENU_END(input->items, 1);
|
||||
|
||||
errorOk();
|
||||
}
|
||||
|
||||
void uiSettingsInputLoad(void) {
|
||||
#ifdef DUSK_INPUT_GAMEPAD
|
||||
uiSliderSetFloat(
|
||||
&UI_SETTINGS.data.input.items[UI_SETTINGS_INPUT_INDEX_DEADZONE].slider,
|
||||
INPUT.deadzone
|
||||
);
|
||||
#endif
|
||||
}
|
||||
|
||||
void uiSettingsInputApply(void) {
|
||||
#ifdef DUSK_INPUT_GAMEPAD
|
||||
INPUT.deadzone = uiSliderGetFloat(
|
||||
&UI_SETTINGS.data.input.items[UI_SETTINGS_INPUT_INDEX_DEADZONE].slider
|
||||
);
|
||||
#endif
|
||||
errorCatch(errorPrint(saveSettingsWrite()));
|
||||
uiMenuClose(&UI_SETTINGS.data.input.menu);
|
||||
}
|
||||
|
||||
bool_t uiSettingsInputHasChanges(void) {
|
||||
#ifdef DUSK_INPUT_GAMEPAD
|
||||
if(uiSliderGetFloat(
|
||||
&UI_SETTINGS.data.input.items[UI_SETTINGS_INPUT_INDEX_DEADZONE].slider
|
||||
) != INPUT.deadzone) return true;
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "error/error.h"
|
||||
#include "uisettingsdata.h"
|
||||
|
||||
/**
|
||||
* Initializes the input settings page into the shared settings data
|
||||
* union.
|
||||
*
|
||||
* @param data The shared settings data union to initialize into.
|
||||
* @return Any error that occurs.
|
||||
*/
|
||||
errorret_t uiSettingsInputInit(uisettingsdata_t *data);
|
||||
|
||||
/**
|
||||
* Loads the page's widgets from the current engine input settings.
|
||||
*/
|
||||
void uiSettingsInputLoad(void);
|
||||
|
||||
/**
|
||||
* Applies the page's widget values to the engine input settings.
|
||||
*/
|
||||
void uiSettingsInputApply(void);
|
||||
|
||||
/**
|
||||
* Returns whether any widget's value differs from what was loaded.
|
||||
*
|
||||
* @returns True if there are unsaved changes.
|
||||
*/
|
||||
bool_t uiSettingsInputHasChanges(void);
|
||||
@@ -0,0 +1,126 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "uiconfirm.h"
|
||||
#include "uiframe.h"
|
||||
#include "assert/assert.h"
|
||||
#include "util/memory.h"
|
||||
#include "util/math.h"
|
||||
#include "display/screen/screen.h"
|
||||
#include "display/text/text.h"
|
||||
#include "display/color.h"
|
||||
#include "display/spritebatch/spritebatch.h"
|
||||
#include "display/texture/texture.h"
|
||||
#include "display/shader/shaderunlit.h"
|
||||
|
||||
#define UI_CONFIRM_BACKDROP_COLOR color4b(0, 0, 0, 160)
|
||||
|
||||
uiconfirm_t UI_CONFIRM;
|
||||
|
||||
void uiConfirmSelected(
|
||||
const uimenu_t *menu,
|
||||
const uint8_t index,
|
||||
const uimenuitem_t *item
|
||||
) {
|
||||
UI_CONFIRM.result = index == UI_CONFIRM_INDEX_CONFIRM;
|
||||
uiConfirmClose();
|
||||
}
|
||||
|
||||
void uiConfirmClosed(const uimenu_t *menu) {
|
||||
if(UI_CONFIRM.callback != NULL) {
|
||||
UI_CONFIRM.callback(UI_CONFIRM.result, UI_CONFIRM.user);
|
||||
}
|
||||
}
|
||||
|
||||
errorret_t uiConfirmInit(void) {
|
||||
memoryZero(&UI_CONFIRM, sizeof(uiconfirm_t));
|
||||
uiLabelInit(&UI_CONFIRM.textLabel, &FONT_DEFAULT);
|
||||
|
||||
MENU_BEGIN(
|
||||
&UI_CONFIRM.menu, UI_CONFIRM.items, uiConfirmSelected, uiConfirmClosed, NULL
|
||||
);
|
||||
MENU_BUTTON("Confirm");
|
||||
MENU_BUTTON("Cancel");
|
||||
|
||||
MENU_END(UI_CONFIRM.items, menuIndex);
|
||||
|
||||
errorOk();
|
||||
}
|
||||
|
||||
errorret_t uiConfirmDraw(void) {
|
||||
if(!uiMenuIsActive(&UI_CONFIRM.menu)) errorOk();
|
||||
|
||||
spritebatchsprite_t backdropSprite = {
|
||||
.min = { 0.0f, 0.0f, 0.0f },
|
||||
.max = { (float_t)SCREEN.width, (float_t)SCREEN.height, 0.0f },
|
||||
.uvMin = { 0.0f, 0.0f },
|
||||
.uvMax = { 1.0f, 1.0f }
|
||||
};
|
||||
shadermaterial_t backdropMaterial = {
|
||||
.unlit = {
|
||||
.color = UI_CONFIRM_BACKDROP_COLOR,
|
||||
.texture = &TEXTURE_WHITE
|
||||
}
|
||||
};
|
||||
errorChain(
|
||||
spriteBatchBuffer(&backdropSprite, 1, &SHADER_UNLIT, backdropMaterial)
|
||||
);
|
||||
|
||||
int32_t textW, textH;
|
||||
uiLabelGetSize(&UI_CONFIRM.textLabel, &textW, &textH);
|
||||
|
||||
float_t rowHeight = (float_t)FONT_DEFAULT.tileset->tileHeight;
|
||||
float_t width = mathMax(
|
||||
(float_t)textW + (UI_FRAME_START_X * 2), UI_CONFIRM_MIN_WIDTH
|
||||
);
|
||||
float_t height = (UI_FRAME_START_Y * 2) + rowHeight + UI_FRAME_PADDING_Y +
|
||||
rowHeight;
|
||||
float_t x = (float_t)SCREEN.scanX + ((float_t)SCREEN.scanWidth - width) * 0.5f;
|
||||
float_t y = (float_t)SCREEN.scanY + ((float_t)SCREEN.scanHeight - height) * 0.5f;
|
||||
|
||||
errorChain(uiFrameDrawCached(&UI_CONFIRM.frameCache, x, y, width, height));
|
||||
|
||||
float_t contentX = x + UI_FRAME_START_X;
|
||||
float_t contentY = y + UI_FRAME_START_Y;
|
||||
float_t contentWidth = width - (UI_FRAME_START_X * 2);
|
||||
|
||||
errorChain(uiLabelDraw(&UI_CONFIRM.textLabel, contentX, contentY));
|
||||
|
||||
float_t buttonsY = contentY + rowHeight + UI_FRAME_PADDING_Y;
|
||||
errorChain(uiMenuDraw(&UI_CONFIRM.menu, contentX, buttonsY, contentWidth, rowHeight));
|
||||
|
||||
errorOk();
|
||||
}
|
||||
|
||||
bool_t uiConfirmIsOpen(void) {
|
||||
return uiMenuIsActive(&UI_CONFIRM.menu);
|
||||
}
|
||||
|
||||
bool_t uiConfirmGetResult(void) {
|
||||
return UI_CONFIRM.result;
|
||||
}
|
||||
|
||||
void uiConfirmOpen(
|
||||
const char_t *question,
|
||||
uiconfirmcallback_t callback,
|
||||
void *user
|
||||
) {
|
||||
assertNotNull(question, "Question cannot be NULL");
|
||||
uiLabelSetText(&UI_CONFIRM.textLabel, question);
|
||||
UI_CONFIRM.callback = callback;
|
||||
UI_CONFIRM.user = user;
|
||||
UI_CONFIRM.result = false;
|
||||
uiMenuOpen(&UI_CONFIRM.menu);
|
||||
}
|
||||
|
||||
void uiConfirmClose(void) {
|
||||
uiMenuClose(&UI_CONFIRM.menu);
|
||||
}
|
||||
|
||||
errorret_t uiConfirmDispose(void) {
|
||||
errorOk();
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "error/error.h"
|
||||
#include "ui/widget/uimenu.h"
|
||||
#include "ui/widget/uilabel.h"
|
||||
#include "ui/frame/uiframe.h"
|
||||
|
||||
#define UI_CONFIRM_MIN_WIDTH 160.0f
|
||||
#define UI_CONFIRM_INDEX_CONFIRM 0
|
||||
#define UI_CONFIRM_INDEX_CANCEL 1
|
||||
#define UI_CONFIRM_ITEM_COUNT 2
|
||||
|
||||
/**
|
||||
* Callback invoked once a confirm dialog is dismissed.
|
||||
*
|
||||
* @param result True if Confirm was selected, false if Cancel was
|
||||
* selected or the dialog was backed out of.
|
||||
* @param user Arbitrary pointer passed to uiConfirmOpen.
|
||||
*/
|
||||
typedef void (*uiconfirmcallback_t)(const bool_t result, void *user);
|
||||
|
||||
typedef struct {
|
||||
uilabel_t textLabel;
|
||||
uimenu_t menu;
|
||||
uimenuitem_t items[UI_CONFIRM_ITEM_COUNT];
|
||||
uiconfirmcallback_t callback;
|
||||
void *user;
|
||||
bool_t result;
|
||||
uiframecache_t frameCache;
|
||||
} uiconfirm_t;
|
||||
|
||||
extern uiconfirm_t UI_CONFIRM;
|
||||
|
||||
/**
|
||||
* Initializes the confirm dialog.
|
||||
*
|
||||
* @return Any error that occurs.
|
||||
*/
|
||||
errorret_t uiConfirmInit(void);
|
||||
|
||||
/**
|
||||
* Draws the confirm dialog: a semi-transparent black backdrop covering
|
||||
* the whole screen, then its own centered frame with the question text
|
||||
* and Confirm/Cancel buttons. No-op when not open.
|
||||
*
|
||||
* @return Any error that occurs.
|
||||
*/
|
||||
errorret_t uiConfirmDraw(void);
|
||||
|
||||
/**
|
||||
* Returns true when the confirm dialog is currently open.
|
||||
*
|
||||
* @returns True if open.
|
||||
*/
|
||||
bool_t uiConfirmIsOpen(void);
|
||||
|
||||
/**
|
||||
* Returns the result of the most recently dismissed confirm dialog.
|
||||
*
|
||||
* @returns True if Confirm was selected, false otherwise.
|
||||
*/
|
||||
bool_t uiConfirmGetResult(void);
|
||||
|
||||
/**
|
||||
* Opens the confirm dialog with the given question text. callback is
|
||||
* invoked exactly once with the result, whether the dialog was
|
||||
* dismissed by selecting a button or by pressing cancel/back.
|
||||
*
|
||||
* @param question Display text; copied internally, safe to be transient.
|
||||
* @param callback Called with the result once the dialog closes. May be
|
||||
* NULL.
|
||||
* @param user Arbitrary pointer passed through to callback.
|
||||
*/
|
||||
void uiConfirmOpen(
|
||||
const char_t *question,
|
||||
uiconfirmcallback_t callback,
|
||||
void *user
|
||||
);
|
||||
|
||||
/**
|
||||
* Closes the confirm dialog. No-op when already closed.
|
||||
*/
|
||||
void uiConfirmClose(void);
|
||||
|
||||
/**
|
||||
* Disposes of the confirm dialog.
|
||||
*
|
||||
* @return Any error that occurs.
|
||||
*/
|
||||
errorret_t uiConfirmDispose(void);
|
||||
@@ -0,0 +1,161 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "uiframe.h"
|
||||
#include "assert/assert.h"
|
||||
#include "util/memory.h"
|
||||
#include "display/texture/texture.h"
|
||||
#include "display/spritebatch/spritebatch.h"
|
||||
#include "display/shader/shaderunlit.h"
|
||||
#include "display/color.h"
|
||||
|
||||
uiframe_t UI_FRAME;
|
||||
|
||||
errorret_t uiFrameInit(void) {
|
||||
memoryZero(&UI_FRAME, sizeof(uiframe_t));
|
||||
|
||||
// Init texture.
|
||||
color_t border = color4b(0, 50, 255, 255);
|
||||
color_t center = color4b(0, 100, 220, 240);
|
||||
|
||||
for(uint8_t y = 0; y < UI_FRAME_TEXTURE_HEIGHT_POW2; y++) {
|
||||
for(uint8_t x = 0; x < UI_FRAME_TEXTURE_WIDTH_POW2; x++) {
|
||||
color_t c;
|
||||
if(x >= UI_FRAME_TEXTURE_WIDTH || y >= UI_FRAME_TEXTURE_HEIGHT) {
|
||||
c = COLOR_TRANSPARENT;
|
||||
} else if(
|
||||
y < UI_FRAME_TILE_HEIGHT || y >= UI_FRAME_TILE_HEIGHT * 2 ||
|
||||
x < UI_FRAME_TILE_WIDTH || x >= UI_FRAME_TILE_WIDTH * 2
|
||||
) {
|
||||
c = border;
|
||||
} else {
|
||||
c = center;
|
||||
}
|
||||
UI_FRAME.pixels[y * UI_FRAME_TEXTURE_WIDTH_POW2 + x] = c;
|
||||
}
|
||||
}
|
||||
|
||||
errorChain(textureInit(
|
||||
&UI_FRAME.texture,
|
||||
UI_FRAME_TEXTURE_WIDTH_POW2, UI_FRAME_TEXTURE_HEIGHT_POW2,
|
||||
TEXTURE_FORMAT_RGBA,
|
||||
(texturedata_t){ .rgbaColors = UI_FRAME.pixels }
|
||||
));
|
||||
|
||||
UI_FRAME.tileset.tileWidth = UI_FRAME_TILE_WIDTH;
|
||||
UI_FRAME.tileset.tileHeight = UI_FRAME_TILE_HEIGHT;
|
||||
UI_FRAME.tileset.columns = 3;
|
||||
UI_FRAME.tileset.rows = 3;
|
||||
UI_FRAME.tileset.tileCount = 9;
|
||||
UI_FRAME.tileset.uv[0] =
|
||||
(float_t)UI_FRAME_TILE_WIDTH / UI_FRAME_TEXTURE_WIDTH_POW2;
|
||||
UI_FRAME.tileset.uv[1] =
|
||||
(float_t)UI_FRAME_TILE_HEIGHT / UI_FRAME_TEXTURE_HEIGHT_POW2;
|
||||
|
||||
errorOk();
|
||||
}
|
||||
|
||||
errorret_t uiFrameDraw(
|
||||
const float_t x,
|
||||
const float_t y,
|
||||
const float_t width,
|
||||
const float_t height
|
||||
) {
|
||||
shadermaterial_t material = {
|
||||
.unlit = {
|
||||
.color = COLOR_WHITE,
|
||||
.texture = &UI_FRAME.texture
|
||||
}
|
||||
};
|
||||
spritebatchsprite_t sprites[9];
|
||||
uiFrameBuildSprites(sprites, x, y, width, height);
|
||||
return spriteBatchBuffer(sprites, 9, &SHADER_UNLIT, material);
|
||||
}
|
||||
|
||||
void uiFrameBuildSprites(
|
||||
spritebatchsprite_t sprites[9],
|
||||
const float_t x,
|
||||
const float_t y,
|
||||
const float_t width,
|
||||
const float_t height
|
||||
) {
|
||||
float_t tileW = (float_t)UI_FRAME_BORDER_WIDTH;
|
||||
float_t tileH = (float_t)UI_FRAME_BORDER_HEIGHT;
|
||||
|
||||
sprites[0] = spriteBatchSpriteTilesetPosition(
|
||||
&UI_FRAME.tileset, 0, 0,
|
||||
x, y, tileW, tileH
|
||||
);
|
||||
sprites[1] = spriteBatchSpriteTilesetPosition(
|
||||
&UI_FRAME.tileset, 1, 0,
|
||||
x + tileW, y, width - (tileW * 2.0f), tileH
|
||||
);
|
||||
sprites[2] = spriteBatchSpriteTilesetPosition(
|
||||
&UI_FRAME.tileset, 2, 0,
|
||||
x + width - tileW, y, tileW, tileH
|
||||
);
|
||||
sprites[3] = spriteBatchSpriteTilesetPosition(
|
||||
&UI_FRAME.tileset, 0, 1,
|
||||
x, y + tileH, tileW, height - (tileH * 2.0f)
|
||||
);
|
||||
sprites[4] = spriteBatchSpriteTilesetPosition(
|
||||
&UI_FRAME.tileset, 1, 1,
|
||||
x + tileW, y + tileH,
|
||||
width - (tileW * 2.0f), height - (tileH * 2.0f)
|
||||
);
|
||||
sprites[5] = spriteBatchSpriteTilesetPosition(
|
||||
&UI_FRAME.tileset, 2, 1,
|
||||
x + width - tileW, y + tileH, tileW, height - (tileH * 2.0f)
|
||||
);
|
||||
sprites[6] = spriteBatchSpriteTilesetPosition(
|
||||
&UI_FRAME.tileset, 0, 2,
|
||||
x, y + height - tileH, tileW, tileH
|
||||
);
|
||||
sprites[7] = spriteBatchSpriteTilesetPosition(
|
||||
&UI_FRAME.tileset, 1, 2,
|
||||
x + tileW, y + height - tileH, width - (tileW * 2.0f), tileH
|
||||
);
|
||||
sprites[8] = spriteBatchSpriteTilesetPosition(
|
||||
&UI_FRAME.tileset, 2, 2,
|
||||
x + width - tileW, y + height - tileH, tileW, tileH
|
||||
);
|
||||
}
|
||||
|
||||
errorret_t uiFrameDrawCached(
|
||||
uiframecache_t *cache,
|
||||
const float_t x,
|
||||
const float_t y,
|
||||
const float_t width,
|
||||
const float_t height
|
||||
) {
|
||||
assertNotNull(cache, "Frame cache cannot be NULL");
|
||||
|
||||
if(
|
||||
!cache->built ||
|
||||
cache->lastX != x || cache->lastY != y ||
|
||||
cache->lastWidth != width || cache->lastHeight != height
|
||||
) {
|
||||
uiFrameBuildSprites(cache->sprites, x, y, width, height);
|
||||
cache->lastX = x;
|
||||
cache->lastY = y;
|
||||
cache->lastWidth = width;
|
||||
cache->lastHeight = height;
|
||||
cache->built = true;
|
||||
}
|
||||
|
||||
shadermaterial_t material = {
|
||||
.unlit = {
|
||||
.color = COLOR_WHITE,
|
||||
.texture = &UI_FRAME.texture
|
||||
}
|
||||
};
|
||||
return spriteBatchBuffer(cache->sprites, 9, &SHADER_UNLIT, material);
|
||||
}
|
||||
|
||||
errorret_t uiFrameDispose(void) {
|
||||
return textureDispose(&UI_FRAME.texture);
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "error/error.h"
|
||||
#include "display/texture/texture.h"
|
||||
#include "display/texture/tileset.h"
|
||||
#include "display/spritebatch/spritebatchsprite.h"
|
||||
|
||||
#define UI_FRAME_BORDER_WIDTH 6
|
||||
#define UI_FRAME_BORDER_HEIGHT 6
|
||||
#define UI_FRAME_PADDING_X 2
|
||||
#define UI_FRAME_PADDING_Y 2
|
||||
#define UI_FRAME_START_X (UI_FRAME_BORDER_WIDTH + UI_FRAME_PADDING_X)
|
||||
#define UI_FRAME_START_Y (UI_FRAME_BORDER_HEIGHT + UI_FRAME_PADDING_Y)
|
||||
#define UI_FRAME_TILE_WIDTH 1
|
||||
#define UI_FRAME_TILE_HEIGHT 1
|
||||
#define UI_FRAME_TEXTURE_WIDTH (UI_FRAME_TILE_WIDTH * 3)
|
||||
#define UI_FRAME_TEXTURE_HEIGHT (UI_FRAME_TILE_HEIGHT * 3)
|
||||
#define UI_FRAME_TEXTURE_WIDTH_POW2 4
|
||||
#define UI_FRAME_TEXTURE_HEIGHT_POW2 4
|
||||
|
||||
typedef struct {
|
||||
tileset_t tileset;
|
||||
texture_t texture;
|
||||
color_t pixels[UI_FRAME_BORDER_WIDTH * UI_FRAME_BORDER_HEIGHT];
|
||||
} uiframe_t;
|
||||
|
||||
extern uiframe_t UI_FRAME;
|
||||
|
||||
/**
|
||||
* Initializes the global UI_FRAME: builds the dummy texture and
|
||||
* configures the tileset. Call once after displayInit().
|
||||
*
|
||||
* @return Any error that occurs.
|
||||
*/
|
||||
errorret_t uiFrameInit(void);
|
||||
|
||||
/**
|
||||
* Draws UI_FRAME using 9-slice rendering from its 3x3 tileset.
|
||||
* Pushes quads to the sprite batch without flushing.
|
||||
*
|
||||
* @param x Screen x position.
|
||||
* @param y Screen y position.
|
||||
* @param width Total width of the frame.
|
||||
* @param height Total height of the frame.
|
||||
* @return Any error that occurs.
|
||||
*/
|
||||
errorret_t uiFrameDraw(
|
||||
const float_t x,
|
||||
const float_t y,
|
||||
const float_t width,
|
||||
const float_t height
|
||||
);
|
||||
|
||||
/**
|
||||
* Builds the 9 sprites for a 9-slice frame at the given rect. Used
|
||||
* internally by uiFrameDraw and uiFrameDrawCached -- call directly only
|
||||
* if you need the raw sprites instead of buffering them.
|
||||
*
|
||||
* @param sprites Destination array of exactly 9 sprites.
|
||||
* @param x Screen x position.
|
||||
* @param y Screen y position.
|
||||
* @param width Total width of the frame.
|
||||
* @param height Total height of the frame.
|
||||
*/
|
||||
void uiFrameBuildSprites(
|
||||
spritebatchsprite_t sprites[9],
|
||||
const float_t x,
|
||||
const float_t y,
|
||||
const float_t width,
|
||||
const float_t height
|
||||
);
|
||||
|
||||
/**
|
||||
* A frame's cached 9-slice sprites, plus the rect they were built for.
|
||||
* Owned by whichever widget/screen draws a frame repeatedly (dialogs,
|
||||
* textboxes, settings panels) so uiFrameDrawCached can skip rebuilding
|
||||
* the sprites when the rect hasn't moved since the last draw.
|
||||
*/
|
||||
typedef struct {
|
||||
spritebatchsprite_t sprites[9];
|
||||
bool_t built;
|
||||
float_t lastX;
|
||||
float_t lastY;
|
||||
float_t lastWidth;
|
||||
float_t lastHeight;
|
||||
} uiframecache_t;
|
||||
|
||||
/**
|
||||
* Draws a 9-slice frame using a caller-owned cache, only rebuilding the
|
||||
* sprites (via uiFrameBuildSprites) when x/y/width/height differ from
|
||||
* the last call -- unlike uiFrameDraw, which rebuilds unconditionally
|
||||
* every time. Prefer this for frames redrawn every frame at a fixed or
|
||||
* rarely-changing rect (dialogs, panels); use plain uiFrameDraw for
|
||||
* genuinely one-off or per-frame-varying rects.
|
||||
*
|
||||
* @param cache Caller-owned cache, zero-initialized before first use.
|
||||
* @param x Screen x position.
|
||||
* @param y Screen y position.
|
||||
* @param width Total width of the frame.
|
||||
* @param height Total height of the frame.
|
||||
* @return Any error that occurs.
|
||||
*/
|
||||
errorret_t uiFrameDrawCached(
|
||||
uiframecache_t *cache,
|
||||
const float_t x,
|
||||
const float_t y,
|
||||
const float_t width,
|
||||
const float_t height
|
||||
);
|
||||
|
||||
/**
|
||||
* Disposes of the global UI_FRAME, releasing its GPU texture.
|
||||
*
|
||||
* @return Any error that occurs.
|
||||
*/
|
||||
errorret_t uiFrameDispose(void);
|
||||
@@ -0,0 +1,11 @@
|
||||
# Copyright (c) 2026 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
||||
PUBLIC
|
||||
uicrop.c
|
||||
uifullbox.c
|
||||
uiloading.c
|
||||
)
|
||||
@@ -0,0 +1,89 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "uicrop.h"
|
||||
#include "display/screen/screen.h"
|
||||
#include "display/spritebatch/spritebatch.h"
|
||||
#include "display/shader/shaderunlit.h"
|
||||
#include "display/texture/texture.h"
|
||||
|
||||
uicrop_t UI_CROP;
|
||||
|
||||
errorret_t uiCropInit(void) {
|
||||
UI_CROP.color = COLOR_BLACK;
|
||||
errorOk();
|
||||
}
|
||||
|
||||
errorret_t uiCropDraw(void) {
|
||||
#ifndef DUSK_DISPLAY_SIZE_DYNAMIC
|
||||
errorOk();
|
||||
#endif
|
||||
|
||||
if(
|
||||
SCREEN.scanX == 0 &&
|
||||
SCREEN.scanY == 0 &&
|
||||
SCREEN.scanWidth == SCREEN.width &&
|
||||
SCREEN.scanHeight == SCREEN.height
|
||||
) errorOk();
|
||||
|
||||
float_t x0 = (float_t)SCREEN.scanX;
|
||||
float_t y0 = (float_t)SCREEN.scanY;
|
||||
float_t x1 = (float_t)(SCREEN.scanX + SCREEN.scanWidth);
|
||||
float_t y1 = (float_t)(SCREEN.scanY + SCREEN.scanHeight);
|
||||
float_t w = (float_t)SCREEN.width;
|
||||
float_t h = (float_t)SCREEN.height;
|
||||
|
||||
spritebatchsprite_t sprites[4];
|
||||
int32_t count = 0;
|
||||
|
||||
if(SCREEN.scanX > 0) {
|
||||
sprites[count++] = (spritebatchsprite_t){
|
||||
.min = { 0.0f, 0.0f, 0.0f },
|
||||
.max = { x0, h, 0.0f },
|
||||
.uvMin = { 0.0f, 0.0f },
|
||||
.uvMax = { 1.0f, 1.0f }
|
||||
};
|
||||
}
|
||||
|
||||
if(SCREEN.scanX + SCREEN.scanWidth < SCREEN.width) {
|
||||
sprites[count++] = (spritebatchsprite_t){
|
||||
.min = { x1, 0.0f, 0.0f },
|
||||
.max = { w, h, 0.0f },
|
||||
.uvMin = { 0.0f, 0.0f },
|
||||
.uvMax = { 1.0f, 1.0f }
|
||||
};
|
||||
}
|
||||
|
||||
if(SCREEN.scanY > 0) {
|
||||
sprites[count++] = (spritebatchsprite_t){
|
||||
.min = { x0, 0.0f, 0.0f },
|
||||
.max = { x1, y0, 0.0f },
|
||||
.uvMin = { 0.0f, 0.0f },
|
||||
.uvMax = { 1.0f, 1.0f }
|
||||
};
|
||||
}
|
||||
|
||||
if(SCREEN.scanY + SCREEN.scanHeight < SCREEN.height) {
|
||||
sprites[count++] = (spritebatchsprite_t){
|
||||
.min = { x0, y1, 0.0f },
|
||||
.max = { x1, h, 0.0f },
|
||||
.uvMin = { 0.0f, 0.0f },
|
||||
.uvMax = { 1.0f, 1.0f }
|
||||
};
|
||||
}
|
||||
|
||||
if(count == 0) errorOk();
|
||||
|
||||
shadermaterial_t material = {
|
||||
.unlit = {
|
||||
.color = UI_CROP.color,
|
||||
.texture = &TEXTURE_WHITE
|
||||
}
|
||||
};
|
||||
errorChain(spriteBatchBuffer(sprites, count, &SHADER_UNLIT, material));
|
||||
errorOk();
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "error/error.h"
|
||||
#include "display/color.h"
|
||||
|
||||
typedef struct {
|
||||
color_t color;
|
||||
} uicrop_t;
|
||||
|
||||
extern uicrop_t UI_CROP;
|
||||
|
||||
/**
|
||||
* Initializes the crop bars to opaque black.
|
||||
*
|
||||
* @return Any error that occurs.
|
||||
*/
|
||||
errorret_t uiCropInit(void);
|
||||
|
||||
/**
|
||||
* Renders solid-color bars covering every area outside the
|
||||
* current scan-safe region. No-ops when the scan area equals
|
||||
* the full viewport.
|
||||
*
|
||||
* @return Any error that occurs.
|
||||
*/
|
||||
errorret_t uiCropDraw(void);
|
||||
@@ -0,0 +1,122 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "uifullbox.h"
|
||||
#include "assert/assert.h"
|
||||
#include "util/memory.h"
|
||||
#include "time/time.h"
|
||||
#include "display/screen/screen.h"
|
||||
#include "display/texture/texture.h"
|
||||
#include "display/spritebatch/spritebatch.h"
|
||||
#include "display/shader/shaderunlit.h"
|
||||
|
||||
uifullbox_t UI_FULLBOX_UNDER;
|
||||
uifullbox_t UI_FULLBOX_OVER;
|
||||
|
||||
void uiFullboxInit(uifullbox_t *fullbox) {
|
||||
assertNotNull(fullbox, "fullbox must not be NULL");
|
||||
memoryZero(fullbox, sizeof(uifullbox_t));
|
||||
eventInit(
|
||||
&fullbox->onTransitionEnd,
|
||||
fullbox->onTransitionEndCallbacks,
|
||||
fullbox->onTransitionEndUsers,
|
||||
4
|
||||
);
|
||||
}
|
||||
|
||||
void uiFullboxUpdate(uifullbox_t *fullbox, float_t delta) {
|
||||
assertNotNull(fullbox, "fullbox must not be NULL");
|
||||
if(fullbox->duration <= 0.0f || fullbox->time >= fullbox->duration) return;
|
||||
|
||||
fullbox->time += delta;
|
||||
if(fullbox->time >= fullbox->duration) {
|
||||
fullbox->time = fullbox->duration;
|
||||
eventInvoke(&fullbox->onTransitionEnd, fullbox);
|
||||
}
|
||||
}
|
||||
|
||||
static color_t uiFullboxGetColor(const uifullbox_t *fullbox) {
|
||||
if(fullbox->duration <= 0.0f || fullbox->time >= fullbox->duration) {
|
||||
return fullbox->toColor;
|
||||
}
|
||||
float_t t = easingApply(fullbox->easing, fullbox->time / fullbox->duration);
|
||||
return color4b(
|
||||
(uint8_t)((float_t)fullbox->fromColor.r +
|
||||
((float_t)fullbox->toColor.r - (float_t)fullbox->fromColor.r) * t),
|
||||
(uint8_t)((float_t)fullbox->fromColor.g +
|
||||
((float_t)fullbox->toColor.g - (float_t)fullbox->fromColor.g) * t),
|
||||
(uint8_t)((float_t)fullbox->fromColor.b +
|
||||
((float_t)fullbox->toColor.b - (float_t)fullbox->fromColor.b) * t),
|
||||
(uint8_t)((float_t)fullbox->fromColor.a +
|
||||
((float_t)fullbox->toColor.a - (float_t)fullbox->fromColor.a) * t)
|
||||
);
|
||||
}
|
||||
|
||||
errorret_t uiFullboxDraw(uifullbox_t *fullbox) {
|
||||
assertNotNull(fullbox, "fullbox must not be NULL");
|
||||
|
||||
color_t color = uiFullboxGetColor(fullbox);
|
||||
if(color.a == 0) errorOk();
|
||||
|
||||
spritebatchsprite_t sprite = {
|
||||
.min = { 0.0f, 0.0f, 0.0f },
|
||||
.max = { (float_t)SCREEN.width, (float_t)SCREEN.height, 0.0f },
|
||||
.uvMin = { 0.0f, 0.0f },
|
||||
.uvMax = { 1.0f, 1.0f }
|
||||
};
|
||||
shadermaterial_t material = {
|
||||
.unlit = {
|
||||
.color = color,
|
||||
.texture = &TEXTURE_WHITE
|
||||
}
|
||||
};
|
||||
errorChain(spriteBatchBuffer(&sprite, 1, &SHADER_UNLIT, material));
|
||||
errorOk();
|
||||
}
|
||||
|
||||
void uiFullboxTransition(
|
||||
uifullbox_t *fullbox,
|
||||
color_t from,
|
||||
color_t to,
|
||||
float_t duration,
|
||||
easingtype_t easing
|
||||
) {
|
||||
assertNotNull(fullbox, "fullbox must not be NULL");
|
||||
fullbox->fromColor = from;
|
||||
fullbox->toColor = to;
|
||||
fullbox->duration = duration;
|
||||
fullbox->time = 0.0f;
|
||||
fullbox->easing = easing;
|
||||
}
|
||||
|
||||
errorret_t uiFullboxUnderInit(void) {
|
||||
uiFullboxInit(&UI_FULLBOX_UNDER);
|
||||
errorOk();
|
||||
}
|
||||
|
||||
errorret_t uiFullboxUnderUpdate(void) {
|
||||
uiFullboxUpdate(&UI_FULLBOX_UNDER, TIME.delta);
|
||||
errorOk();
|
||||
}
|
||||
|
||||
errorret_t uiFullboxUnderDraw(void) {
|
||||
return uiFullboxDraw(&UI_FULLBOX_UNDER);
|
||||
}
|
||||
|
||||
errorret_t uiFullboxOverInit(void) {
|
||||
uiFullboxInit(&UI_FULLBOX_OVER);
|
||||
errorOk();
|
||||
}
|
||||
|
||||
errorret_t uiFullboxOverUpdate(void) {
|
||||
uiFullboxUpdate(&UI_FULLBOX_OVER, TIME.delta);
|
||||
errorOk();
|
||||
}
|
||||
|
||||
errorret_t uiFullboxOverDraw(void) {
|
||||
return uiFullboxDraw(&UI_FULLBOX_OVER);
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "error/error.h"
|
||||
#include "display/color.h"
|
||||
#include "animation/easing.h"
|
||||
#include "event/event.h"
|
||||
|
||||
typedef struct {
|
||||
color_t fromColor;
|
||||
color_t toColor;
|
||||
float_t duration;
|
||||
float_t time;
|
||||
easingtype_t easing;
|
||||
eventcallback_t onTransitionEndCallbacks[4];
|
||||
void *onTransitionEndUsers[4];
|
||||
event_t onTransitionEnd;
|
||||
} uifullbox_t;
|
||||
|
||||
extern uifullbox_t UI_FULLBOX_UNDER;
|
||||
extern uifullbox_t UI_FULLBOX_OVER;
|
||||
|
||||
/**
|
||||
* Initializes a fullbox, zeroing all fields.
|
||||
*
|
||||
* @param fullbox The fullbox to initialize.
|
||||
*/
|
||||
void uiFullboxInit(uifullbox_t *fullbox);
|
||||
|
||||
/**
|
||||
* Advances the fullbox transition. Fires onTransitionEnd once when the
|
||||
* transition completes. Safe to call when no transition is running.
|
||||
*
|
||||
* @param fullbox The fullbox to update.
|
||||
* @param delta Seconds elapsed since last update.
|
||||
*/
|
||||
void uiFullboxUpdate(uifullbox_t *fullbox, float_t delta);
|
||||
|
||||
/**
|
||||
* Renders the fullbox. Skipped entirely when the current alpha is zero.
|
||||
*
|
||||
* @param fullbox The fullbox to draw.
|
||||
* @return Any error that occurs.
|
||||
*/
|
||||
errorret_t uiFullboxDraw(uifullbox_t *fullbox);
|
||||
|
||||
/**
|
||||
* Begins a color transition.
|
||||
*
|
||||
* @param fullbox The fullbox to transition.
|
||||
* @param from Start color.
|
||||
* @param to End color.
|
||||
* @param duration Transition duration in seconds.
|
||||
* @param easing Easing function to apply.
|
||||
*/
|
||||
void uiFullboxTransition(
|
||||
uifullbox_t *fullbox,
|
||||
color_t from,
|
||||
color_t to,
|
||||
float_t duration,
|
||||
easingtype_t easing
|
||||
);
|
||||
|
||||
/**
|
||||
* Init function for UI_FULLBOX_UNDER (registered in UI_ELEMENTS).
|
||||
*
|
||||
* @return Any error that occurs.
|
||||
*/
|
||||
errorret_t uiFullboxUnderInit(void);
|
||||
|
||||
/**
|
||||
* Update function for UI_FULLBOX_UNDER (registered in UI_ELEMENTS).
|
||||
*
|
||||
* @return Any error that occurs.
|
||||
*/
|
||||
errorret_t uiFullboxUnderUpdate(void);
|
||||
|
||||
/**
|
||||
* Draw function for UI_FULLBOX_UNDER (registered in UI_ELEMENTS).
|
||||
*
|
||||
* @return Any error that occurs.
|
||||
*/
|
||||
errorret_t uiFullboxUnderDraw(void);
|
||||
|
||||
/**
|
||||
* Init function for UI_FULLBOX_OVER (registered in UI_ELEMENTS).
|
||||
*
|
||||
* @return Any error that occurs.
|
||||
*/
|
||||
errorret_t uiFullboxOverInit(void);
|
||||
|
||||
/**
|
||||
* Update function for UI_FULLBOX_OVER (registered in UI_ELEMENTS).
|
||||
*
|
||||
* @return Any error that occurs.
|
||||
*/
|
||||
errorret_t uiFullboxOverUpdate(void);
|
||||
|
||||
/**
|
||||
* Draw function for UI_FULLBOX_OVER (registered in UI_ELEMENTS).
|
||||
*
|
||||
* @return Any error that occurs.
|
||||
*/
|
||||
errorret_t uiFullboxOverDraw(void);
|
||||
@@ -0,0 +1,111 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "uiloading.h"
|
||||
#include "assert/assert.h"
|
||||
#include "util/memory.h"
|
||||
#include "time/time.h"
|
||||
#include "display/text/text.h"
|
||||
#include "display/screen/screen.h"
|
||||
#include "uifullbox.h"
|
||||
|
||||
#define UI_LOADING_TEXT "loading"
|
||||
|
||||
uiloading_t UI_LOADING;
|
||||
|
||||
errorret_t uiLoadingInit(void) {
|
||||
memoryZero(&UI_LOADING, sizeof(uiloading_t));
|
||||
uiLabelInit(&UI_LOADING.textLabel, &FONT_DEFAULT);
|
||||
uiLabelSetText(&UI_LOADING.textLabel, UI_LOADING_TEXT);
|
||||
eventInit(
|
||||
&UI_LOADING.onTransitionEnd,
|
||||
UI_LOADING.onTransitionEndCallbacks,
|
||||
UI_LOADING.onTransitionEndUsers,
|
||||
4
|
||||
);
|
||||
errorOk();
|
||||
}
|
||||
|
||||
errorret_t uiLoadingUpdate(void) {
|
||||
if(UI_LOADING.duration > 0.0f && UI_LOADING.time < UI_LOADING.duration) {
|
||||
UI_LOADING.time += TIME.delta;
|
||||
if(UI_LOADING.time >= UI_LOADING.duration) {
|
||||
UI_LOADING.time = UI_LOADING.duration;
|
||||
eventInvoke(&UI_LOADING.onTransitionEnd, &UI_LOADING);
|
||||
}
|
||||
}
|
||||
errorOk();
|
||||
}
|
||||
|
||||
errorret_t uiLoadingDraw(void) {
|
||||
float_t alpha;
|
||||
if(UI_LOADING.duration <= 0.0f || UI_LOADING.time >= UI_LOADING.duration) {
|
||||
alpha = UI_LOADING.toAlpha;
|
||||
} else {
|
||||
float_t t = UI_LOADING.time / UI_LOADING.duration;
|
||||
alpha = UI_LOADING.fromAlpha +
|
||||
(UI_LOADING.toAlpha - UI_LOADING.fromAlpha) * t;
|
||||
}
|
||||
|
||||
if(alpha <= 0.0f) errorOk();
|
||||
|
||||
int32_t textW, textH;
|
||||
uiLabelGetSize(&UI_LOADING.textLabel, &textW, &textH);
|
||||
|
||||
float_t x = (float_t)(SCREEN.scanX + SCREEN.scanWidth) -
|
||||
(float_t)textW - UI_LOADING_MARGIN;
|
||||
float_t y = (float_t)(SCREEN.scanY + SCREEN.scanHeight) -
|
||||
(float_t)textH - UI_LOADING_MARGIN;
|
||||
|
||||
color_t color = COLOR_WHITE;
|
||||
color.a = (uint8_t)(alpha * 255.0f);
|
||||
uiLabelSetColor(&UI_LOADING.textLabel, color);
|
||||
|
||||
errorChain(uiLabelDraw(&UI_LOADING.textLabel, x, y));
|
||||
errorOk();
|
||||
}
|
||||
|
||||
static void uiLoadingTransition(
|
||||
const float_t from,
|
||||
const float_t to,
|
||||
const eventcallback_t callback,
|
||||
void *user
|
||||
) {
|
||||
UI_LOADING.fromAlpha = from;
|
||||
UI_LOADING.toAlpha = to;
|
||||
UI_LOADING.duration = UI_LOADING_FADE_DURATION;
|
||||
UI_LOADING.time = 0.0f;
|
||||
eventInit(
|
||||
&UI_LOADING.onTransitionEnd,
|
||||
UI_LOADING.onTransitionEndCallbacks,
|
||||
UI_LOADING.onTransitionEndUsers,
|
||||
4
|
||||
);
|
||||
if(callback) eventSubscribe(&UI_LOADING.onTransitionEnd, callback, user);
|
||||
}
|
||||
|
||||
void uiLoadingShow(eventcallback_t callback, void *user) {
|
||||
uiLoadingTransition(0.0f, 1.0f, callback, user);
|
||||
uiFullboxTransition(
|
||||
&UI_FULLBOX_OVER,
|
||||
COLOR_TRANSPARENT_BLACK,
|
||||
COLOR_BLACK,
|
||||
UI_LOADING_FADE_DURATION,
|
||||
EASING_LINEAR
|
||||
);
|
||||
}
|
||||
|
||||
void uiLoadingHide(eventcallback_t callback, void *user) {
|
||||
uiLoadingTransition(1.0f, 0.0f, callback, user);
|
||||
uiFullboxTransition(
|
||||
&UI_FULLBOX_OVER,
|
||||
COLOR_BLACK,
|
||||
COLOR_TRANSPARENT_BLACK,
|
||||
UI_LOADING_FADE_DURATION,
|
||||
EASING_LINEAR
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "error/error.h"
|
||||
#include "event/event.h"
|
||||
#include "ui/widget/uilabel.h"
|
||||
|
||||
#define UI_LOADING_FADE_DURATION 0.5f
|
||||
#define UI_LOADING_MARGIN 8.0f
|
||||
|
||||
typedef struct {
|
||||
float_t fromAlpha;
|
||||
float_t toAlpha;
|
||||
float_t duration;
|
||||
float_t time;
|
||||
eventcallback_t onTransitionEndCallbacks[4];
|
||||
void *onTransitionEndUsers[4];
|
||||
event_t onTransitionEnd;
|
||||
uilabel_t textLabel;
|
||||
} uiloading_t;
|
||||
|
||||
extern uiloading_t UI_LOADING;
|
||||
|
||||
/**
|
||||
* Initializes the loading indicator.
|
||||
*
|
||||
* @return Any error that occurs.
|
||||
*/
|
||||
errorret_t uiLoadingInit(void);
|
||||
|
||||
/**
|
||||
* Advances the loading indicator fade transition. Fires onTransitionEnd once
|
||||
* when the transition completes.
|
||||
*
|
||||
* @return Any error that occurs.
|
||||
*/
|
||||
errorret_t uiLoadingUpdate(void);
|
||||
|
||||
/**
|
||||
* Draws the loading indicator. No-op when fully transparent.
|
||||
*
|
||||
* @return Error state.
|
||||
*/
|
||||
errorret_t uiLoadingDraw(void);
|
||||
|
||||
/**
|
||||
* Fades the loading indicator in. Invokes callback when fully visible.
|
||||
*
|
||||
* @param callback Called when the fade-in completes. May be NULL.
|
||||
* @param user Forwarded to the callback unchanged.
|
||||
*/
|
||||
void uiLoadingShow(eventcallback_t callback, void *user);
|
||||
|
||||
/**
|
||||
* Fades the loading indicator out. Invokes callback when fully hidden.
|
||||
*
|
||||
* @param callback Called when the fade-out completes. May be NULL.
|
||||
* @param user Forwarded to the callback unchanged.
|
||||
*/
|
||||
void uiLoadingHide(eventcallback_t callback, void *user);
|
||||
@@ -0,0 +1,10 @@
|
||||
# Copyright (c) 2026 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
||||
PUBLIC
|
||||
uitransition.c
|
||||
uitransitionfade.c
|
||||
)
|
||||
@@ -0,0 +1,81 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "uitransition.h"
|
||||
#include "uitransitionfade.h"
|
||||
#include "assert/assert.h"
|
||||
#include "util/memory.h"
|
||||
#include "time/time.h"
|
||||
#include "util/math.h"
|
||||
|
||||
uitransition_t UI_TRANSITION;
|
||||
|
||||
uitransitiondrawfunc_t UI_TRANSITION_TYPE_DRAW[UI_TRANSITION_TYPE_COUNT] = {
|
||||
[UI_TRANSITION_TYPE_FADE] = uiTransitionFadeDraw
|
||||
};
|
||||
|
||||
errorret_t uiTransitionInit(void) {
|
||||
memoryZero(&UI_TRANSITION, sizeof(uitransition_t));
|
||||
|
||||
// uiTransitionStart((uitransitionstartparams_t){
|
||||
// .duration = 5.0f,
|
||||
// .type = UI_TRANSITION_TYPE_FADE,
|
||||
// .params = {
|
||||
// .fade = {
|
||||
// .easing = EASING_OUT_QUART,
|
||||
// .fromColor = COLOR_TRANSPARENT_BLACK,
|
||||
// .toColor = COLOR_BLACK
|
||||
// }
|
||||
// },
|
||||
// .finished = NULL,
|
||||
// .user = NULL
|
||||
// });
|
||||
|
||||
errorOk();
|
||||
}
|
||||
|
||||
errorret_t uiTransitionUpdate(void) {
|
||||
// Update time.
|
||||
float_t newTime = UI_TRANSITION.data.time + TIME.delta;
|
||||
|
||||
UI_TRANSITION.data.time = mathClamp(
|
||||
newTime,
|
||||
0.0f,
|
||||
UI_TRANSITION.data.duration
|
||||
);
|
||||
UI_TRANSITION.data.t = (
|
||||
(UI_TRANSITION.data.duration <= 0.0f) ?
|
||||
1.0f :
|
||||
(UI_TRANSITION.data.time / UI_TRANSITION.data.duration)
|
||||
);
|
||||
|
||||
if(UI_TRANSITION.data.t >= 1.0f && UI_TRANSITION.finished) {
|
||||
UI_TRANSITION.finished(UI_TRANSITION.user);
|
||||
}
|
||||
|
||||
errorOk();
|
||||
}
|
||||
|
||||
errorret_t uiTransitionDraw(void) {
|
||||
uitransitiondrawfunc_t draw = UI_TRANSITION_TYPE_DRAW[UI_TRANSITION.type];
|
||||
if(!draw) errorOk();
|
||||
return draw(&UI_TRANSITION.data);
|
||||
}
|
||||
|
||||
void uiTransitionStart(const uitransitionstartparams_t info) {
|
||||
assertTrue(info.type > UI_TRANSITION_TYPE_NULL, "Invalid type");
|
||||
assertTrue(info.type < UI_TRANSITION_TYPE_COUNT, "Invalid type");
|
||||
assertTrue(info.duration >= 0.0f, "Duration must be non-negative");
|
||||
|
||||
memoryZero(&UI_TRANSITION, sizeof(uitransition_t));
|
||||
|
||||
UI_TRANSITION.data.duration = info.duration;
|
||||
UI_TRANSITION.type = info.type;
|
||||
UI_TRANSITION.data.params = info.params;
|
||||
UI_TRANSITION.finished = info.finished;
|
||||
UI_TRANSITION.user = info.user;
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "error/error.h"
|
||||
#include "display/color.h"
|
||||
#include "animation/easing.h"
|
||||
#include "uitransitiondata.h"
|
||||
|
||||
typedef void (*uitransitioncallback_t)(void *user);
|
||||
|
||||
typedef enum {
|
||||
UI_TRANSITION_TYPE_NULL,
|
||||
|
||||
UI_TRANSITION_TYPE_FADE,
|
||||
|
||||
UI_TRANSITION_TYPE_COUNT
|
||||
} uitransitiontype_t;
|
||||
|
||||
extern uitransitiondrawfunc_t UI_TRANSITION_TYPE_DRAW[UI_TRANSITION_TYPE_COUNT];
|
||||
|
||||
|
||||
typedef struct {
|
||||
uitransitiondata_t data;
|
||||
uitransitiontype_t type;
|
||||
uitransitioncallback_t finished;
|
||||
void *user;
|
||||
} uitransition_t;
|
||||
|
||||
extern uitransition_t UI_TRANSITION;
|
||||
|
||||
/**
|
||||
* Initializes the transition overlay, zeroing all fields and wiring the
|
||||
* onTransitionEnd event.
|
||||
*
|
||||
* @return Any error that occurs.
|
||||
*/
|
||||
errorret_t uiTransitionInit(void);
|
||||
|
||||
/**
|
||||
* Advances the transition. Fires onTransitionEnd once when it completes.
|
||||
* Safe to call when no transition is running.
|
||||
*
|
||||
* @return Any error that occurs.
|
||||
*/
|
||||
errorret_t uiTransitionUpdate(void);
|
||||
|
||||
/**
|
||||
* Renders the transition overlay. Skipped entirely when the current alpha
|
||||
* is zero.
|
||||
*
|
||||
* @return Any error that occurs.
|
||||
*/
|
||||
errorret_t uiTransitionDraw(void);
|
||||
|
||||
typedef struct {
|
||||
float_t duration;
|
||||
uitransitiontype_t type;
|
||||
uitransitionparams_t params;
|
||||
uitransitioncallback_t finished;
|
||||
void *user;
|
||||
} uitransitionstartparams_t;
|
||||
|
||||
/**
|
||||
* Starts a transition described by an info struct.
|
||||
*
|
||||
* @param info Transition parameters.
|
||||
*/
|
||||
void uiTransitionStart(const uitransitionstartparams_t info);
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "error/error.h"
|
||||
#include "uitransitionfade.h"
|
||||
|
||||
typedef union uitransitionparams_u {
|
||||
uitransitionfade_t fade;
|
||||
} uitransitionparams_t;
|
||||
|
||||
typedef struct uitransitiondata_s {
|
||||
float_t time;
|
||||
float_t duration;
|
||||
float_t t;
|
||||
uitransitionparams_t params;
|
||||
} uitransitiondata_t;
|
||||
|
||||
typedef errorret_t (*uitransitiondrawfunc_t)(const uitransitiondata_t *data);
|
||||
@@ -0,0 +1,56 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "uitransition.h"
|
||||
#include "assert/assert.h"
|
||||
#include "display/screen/screen.h"
|
||||
#include "display/texture/texture.h"
|
||||
#include "display/spritebatch/spritebatch.h"
|
||||
#include "display/shader/shaderunlit.h"
|
||||
|
||||
errorret_t uiTransitionFadeDraw(const uitransitiondata_t *data) {
|
||||
assertNotNull(data, "data must not be NULL");
|
||||
|
||||
float_t e = easingApply(data->params.fade.easing, data->t);
|
||||
|
||||
float_t r = (float_t)(
|
||||
data->params.fade.toColor.r - data->params.fade.fromColor.r
|
||||
) * e;
|
||||
float_t g = (float_t)(
|
||||
data->params.fade.toColor.g - data->params.fade.fromColor.g
|
||||
) * e;
|
||||
float_t b = (float_t)(
|
||||
data->params.fade.toColor.b - data->params.fade.fromColor.b
|
||||
) * e;
|
||||
float_t a = (float_t)(
|
||||
data->params.fade.toColor.a - data->params.fade.fromColor.a
|
||||
) * e;
|
||||
|
||||
color_t color = color4b(
|
||||
data->params.fade.fromColor.r + (uint8_t)r,
|
||||
data->params.fade.fromColor.g + (uint8_t)g,
|
||||
data->params.fade.fromColor.b + (uint8_t)b,
|
||||
data->params.fade.fromColor.a + (uint8_t)a
|
||||
);
|
||||
|
||||
if(color.a == 0) errorOk();
|
||||
|
||||
spritebatchsprite_t sprite = {
|
||||
.min = { 0.0f, 0.0f, 0.0f },
|
||||
.max = { (float_t)SCREEN.width, (float_t)SCREEN.height, 0.0f },
|
||||
.uvMin = { 0.0f, 0.0f },
|
||||
.uvMax = { 1.0f, 1.0f }
|
||||
};
|
||||
shadermaterial_t material = {
|
||||
.unlit = {
|
||||
.color = color,
|
||||
.texture = NULL
|
||||
}
|
||||
};
|
||||
errorChain(spriteBatchBuffer(&sprite, 1, &SHADER_UNLIT, material));
|
||||
errorOk();
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "error/error.h"
|
||||
#include "display/color.h"
|
||||
#include "animation/easing.h"
|
||||
|
||||
typedef struct uitransitiondata_s uitransitiondata_t;
|
||||
|
||||
typedef struct {
|
||||
color_t fromColor;
|
||||
color_t toColor;
|
||||
easingtype_t easing;
|
||||
} uitransitionfade_t;
|
||||
|
||||
/**
|
||||
* Renders a full-screen color overlay interpolated between fade->fromColor
|
||||
* and fade->toColor using fade->easing. t is the raw normalized progress
|
||||
* in [0, 1] before easing is applied. No-op when the resulting alpha is zero.
|
||||
*
|
||||
* @param fade The fade parameters.
|
||||
* @return Any error that occurs.
|
||||
*/
|
||||
errorret_t uiTransitionFadeDraw(const uitransitiondata_t *fade);
|
||||
@@ -0,0 +1,62 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "ui.h"
|
||||
#include "util/memory.h"
|
||||
#include "assert/assert.h"
|
||||
#include "display/spritebatch/spritebatch.h"
|
||||
#include "display/screen/screen.h"
|
||||
#include "ui/uielement.h"
|
||||
#include "ui/focus/uifocus.h"
|
||||
|
||||
ui_t UI;
|
||||
|
||||
errorret_t uiInit(void) {
|
||||
memoryZero(&UI, sizeof(ui_t));
|
||||
uiFocusInit();
|
||||
uiElementsSort();
|
||||
|
||||
uielement_t *element = &UI_ELEMENTS[0];
|
||||
while(!uiElementIsNull(element)) {
|
||||
errorChain(uiElementInit(element));
|
||||
element++;
|
||||
}
|
||||
|
||||
errorOk();
|
||||
}
|
||||
|
||||
errorret_t uiUpdate(void) {
|
||||
uiFocusUpdate();
|
||||
|
||||
uielement_t *element = &UI_ELEMENTS[0];
|
||||
while(!uiElementIsNull(element)) {
|
||||
errorChain(uiElementUpdate(element));
|
||||
element++;
|
||||
}
|
||||
|
||||
errorOk();
|
||||
}
|
||||
|
||||
errorret_t uiRender(void) {
|
||||
const uielement_t *element = &UI_ELEMENTS[0];
|
||||
while(!uiElementIsNull(element)) {
|
||||
errorChain(uiElementDraw(element));
|
||||
element++;
|
||||
}
|
||||
|
||||
errorChain(spriteBatchFlush());
|
||||
errorOk();
|
||||
}
|
||||
|
||||
errorret_t uiDispose(void) {
|
||||
uielement_t *element = &UI_ELEMENTS[0];
|
||||
while(!uiElementIsNull(element)) {
|
||||
errorChain(uiElementDispose(element));
|
||||
element++;
|
||||
}
|
||||
errorOk();
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "error/error.h"
|
||||
|
||||
typedef struct {
|
||||
void *nothing;
|
||||
} ui_t;
|
||||
|
||||
extern ui_t UI;
|
||||
|
||||
/**
|
||||
* Initializes the UI system.
|
||||
*/
|
||||
errorret_t uiInit(void);
|
||||
|
||||
/**
|
||||
* Updates the UI system.
|
||||
*
|
||||
* @return Any error that occurs.
|
||||
*/
|
||||
errorret_t uiUpdate(void);
|
||||
|
||||
/**
|
||||
* Renders the UI system.
|
||||
*
|
||||
* @return Any error that occurs.
|
||||
*/
|
||||
errorret_t uiRender(void);
|
||||
|
||||
/**
|
||||
* Disposes of the UI system.
|
||||
*
|
||||
* @return Any error that occurs.
|
||||
*/
|
||||
errorret_t uiDispose(void);
|
||||
@@ -0,0 +1,86 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "uielement.h"
|
||||
#include "assert/assert.h"
|
||||
#include "util/sort.h"
|
||||
#include "ui/frame/uiframe.h"
|
||||
#include "ui/debug/uifps.h"
|
||||
#include "engine/engine.h"
|
||||
#include "ui/overlay/uifullbox.h"
|
||||
#include "ui/overlay/uiloading.h"
|
||||
#include "ui/overlay/uicrop.h"
|
||||
#include "ui/transition/uitransition.h"
|
||||
#include "ui/debug/uiconsole.h"
|
||||
#include "ui/frame/uiconfirm.h"
|
||||
|
||||
// Priming pass: X does nothing here, so this only exists to process any
|
||||
// #include directives nested in uielementlist.h/ui/uielementgame.h at
|
||||
// file scope (each such header's own #pragma once makes it a no-op on
|
||||
// the real pass below, which happens inside UI_ELEMENTS[]'s braces,
|
||||
// where a raw #include of a declaration would be invalid).
|
||||
#define X(initFn, updateFn, drawFn, disposeFn, order) // do nothing
|
||||
#include "uielementlist.h"
|
||||
#undef X
|
||||
|
||||
uielement_t UI_ELEMENTS[] = {
|
||||
#define X(initFn, updateFn, drawFn, disposeFn, elementOrder) \
|
||||
{ \
|
||||
.init = initFn, .update = updateFn, .draw = drawFn, \
|
||||
.dispose = disposeFn, .order = elementOrder \
|
||||
},
|
||||
#include "uielementlist.h"
|
||||
#undef X
|
||||
|
||||
{ 0 } // Null terminator
|
||||
};
|
||||
|
||||
bool_t uiElementIsNull(const uielement_t *element) {
|
||||
return element->init == NULL &&
|
||||
element->update == NULL &&
|
||||
element->draw == NULL &&
|
||||
element->dispose == NULL;
|
||||
}
|
||||
|
||||
int_t uiElementCompareOrder(const void *a, const void *b) {
|
||||
const uielement_t *elementA = (const uielement_t *)a;
|
||||
const uielement_t *elementB = (const uielement_t *)b;
|
||||
if(elementA->order < elementB->order) return -1;
|
||||
if(elementA->order > elementB->order) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void uiElementsSort(void) {
|
||||
// The trailing null terminator is always the last static entry -- sort
|
||||
// everything before it, and leave it in place.
|
||||
const size_t count = (sizeof(UI_ELEMENTS) / sizeof(UI_ELEMENTS[0])) - 1;
|
||||
sortBubble(UI_ELEMENTS, count, sizeof(uielement_t), uiElementCompareOrder);
|
||||
}
|
||||
|
||||
errorret_t uiElementInit(uielement_t *element) {
|
||||
assertNotNull(element, "element must not be NULL");
|
||||
if(element->init != NULL) errorChain(element->init());
|
||||
errorOk();
|
||||
}
|
||||
|
||||
errorret_t uiElementUpdate(uielement_t *element) {
|
||||
assertNotNull(element, "element must not be NULL");
|
||||
if(element->update != NULL) errorChain(element->update());
|
||||
errorOk();
|
||||
}
|
||||
|
||||
errorret_t uiElementDraw(const uielement_t *element) {
|
||||
assertNotNull(element, "element must not be NULL");
|
||||
if(element->draw != NULL) errorChain(element->draw());
|
||||
errorOk();
|
||||
}
|
||||
|
||||
errorret_t uiElementDispose(uielement_t *element) {
|
||||
assertNotNull(element, "element must not be NULL");
|
||||
if(element->dispose != NULL) errorChain(element->dispose());
|
||||
errorOk();
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "error/error.h"
|
||||
|
||||
// Built-in order tiers. Lower values update/render first; ties preserve
|
||||
// their relative UI_ELEMENTS declaration order (uiElementsSort uses a
|
||||
// stable sort). Game-specific elements can use any int32_t value -- these
|
||||
// are just the ones the engine itself relies on.
|
||||
#define UI_ELEMENT_ORDER_DEFAULT 0
|
||||
#define UI_ELEMENT_ORDER_DEBUG 1000
|
||||
|
||||
typedef struct {
|
||||
errorret_t (*init)();
|
||||
errorret_t (*update)();
|
||||
errorret_t (*draw)();
|
||||
errorret_t (*dispose)();
|
||||
int32_t order;
|
||||
} uielement_t;
|
||||
|
||||
extern uielement_t UI_ELEMENTS[];
|
||||
|
||||
/**
|
||||
* Returns true when all four callbacks on the element are NULL,
|
||||
* which marks the end of the UI_ELEMENTS array.
|
||||
*
|
||||
* @param element The element to test.
|
||||
* @returns True if the element is the null terminator.
|
||||
*/
|
||||
bool_t uiElementIsNull(const uielement_t *element);
|
||||
|
||||
/**
|
||||
* Compares two elements by their .order field, ascending. Matches
|
||||
* sortcompare_t, for use with the project's sort utilities.
|
||||
*
|
||||
* @param a First uielement_t to compare.
|
||||
* @param b Second uielement_t to compare.
|
||||
* @return Negative if a < b, zero if a == b, positive if a > b.
|
||||
*/
|
||||
int_t uiElementCompareOrder(const void *a, const void *b);
|
||||
|
||||
/**
|
||||
* Stably sorts UI_ELEMENTS in place by .order, ascending. The trailing
|
||||
* null terminator is never moved. Called once by uiInit -- element order
|
||||
* is static after that, so there's no need to re-sort every frame.
|
||||
*/
|
||||
void uiElementsSort(void);
|
||||
|
||||
/**
|
||||
* Initializes a UI element, invoking its init callback if set.
|
||||
*
|
||||
* @param element The element to initialize.
|
||||
* @return Any error that occurs.
|
||||
*/
|
||||
errorret_t uiElementInit(uielement_t *element);
|
||||
|
||||
/**
|
||||
* Updates a UI element, calling its update callback if set.
|
||||
*
|
||||
* @param element The element to update.
|
||||
* @return Any error that occurs.
|
||||
*/
|
||||
errorret_t uiElementUpdate(uielement_t *element);
|
||||
|
||||
/**
|
||||
* Draws a UI element, calling its draw callback if set.
|
||||
*
|
||||
* @param element The element to render.
|
||||
* @return Any error that occurs.
|
||||
*/
|
||||
errorret_t uiElementDraw(const uielement_t *element);
|
||||
|
||||
/**
|
||||
* Disposes of a UI element, invoking its dispose callback if set.
|
||||
*
|
||||
* @param element The element to dispose.
|
||||
* @return Any error that occurs.
|
||||
*/
|
||||
errorret_t uiElementDispose(uielement_t *element);
|
||||
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
// X(init, update, draw, dispose, order) -- pass NULL for any callback the
|
||||
// element doesn't need. order controls update/draw sequence (lower first,
|
||||
// see UI_ELEMENT_ORDER_* in uielement.h); ties preserve declaration order.
|
||||
// See uielement.c for how this expands.
|
||||
|
||||
X(uiFrameInit, NULL, NULL, uiFrameDispose, UI_ELEMENT_ORDER_DEFAULT)
|
||||
|
||||
// Fullbox under: above scene, below system UI.
|
||||
X(
|
||||
uiFullboxUnderInit, uiFullboxUnderUpdate, uiFullboxUnderDraw, NULL,
|
||||
UI_ELEMENT_ORDER_DEFAULT
|
||||
)
|
||||
|
||||
// Text stuffs
|
||||
X(uiConfirmInit, NULL, uiConfirmDraw, uiConfirmDispose, UI_ELEMENT_ORDER_DEFAULT)
|
||||
|
||||
X(
|
||||
uiTransitionInit, uiTransitionUpdate, uiTransitionDraw, NULL,
|
||||
UI_ELEMENT_ORDER_DEFAULT
|
||||
)
|
||||
|
||||
// Fullbox over: above absolutely everything (except debug).
|
||||
X(
|
||||
uiFullboxOverInit, uiFullboxOverUpdate, uiFullboxOverDraw, NULL,
|
||||
UI_ELEMENT_ORDER_DEFAULT
|
||||
)
|
||||
|
||||
X(
|
||||
uiLoadingInit, uiLoadingUpdate, uiLoadingDraw, NULL,
|
||||
UI_ELEMENT_ORDER_DEFAULT
|
||||
)
|
||||
|
||||
X(uiCropInit, NULL, uiCropDraw, NULL, UI_ELEMENT_ORDER_DEFAULT)
|
||||
|
||||
// Debug items -- always last.
|
||||
X(NULL, NULL, uiConsoleDraw, uiConsoleDispose, UI_ELEMENT_ORDER_DEBUG)
|
||||
X(uiFPSInit, NULL, uiFPSDraw, NULL, UI_ELEMENT_ORDER_DEBUG)
|
||||
|
||||
// Game-specific UI elements (duskrpg)
|
||||
#include "ui/uielementgame.h"
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user