Compare commits
26
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
49b97ba508 | ||
|
|
6c11d8165d | ||
|
|
93554b39ba | ||
|
|
6af0e9cf28 | ||
|
|
083deb8357 | ||
|
|
ffb375faeb | ||
|
|
b8cbd8ff6a | ||
|
|
c2bd761383 | ||
|
|
878e3438c8 | ||
|
|
3da65370e0 | ||
|
|
83e646cba9 | ||
|
|
0566166af4 | ||
|
|
ed0b8c3911 | ||
|
|
03d753a83f | ||
|
|
cf51ed1988 | ||
|
|
70f46e89d3 | ||
|
|
efd760fb2e | ||
|
|
f303d24f4a | ||
|
|
9688e88a7c | ||
|
|
c8a6325615 | ||
|
|
798db14bb5 | ||
|
|
178d78ef72 | ||
|
|
8139a0ea54 | ||
|
|
327c2bec70 | ||
|
|
fc0195d9f7 | ||
|
|
db42bca44b |
No files matched your search
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"items": [
|
||||
{
|
||||
"type": "START_BATTLE",
|
||||
"encounterType": "REGULAR",
|
||||
"fleeAvailable": true,
|
||||
"enemies": [
|
||||
{
|
||||
"stats": { "attack": 8, "defense": 4, "magic": 0, "speed": 5, "luck": 2 },
|
||||
"healthMax": 30,
|
||||
"mpMax": 0
|
||||
},
|
||||
{
|
||||
"stats": { "attack": 6, "defense": 3, "magic": 0, "speed": 7, "luck": 2 },
|
||||
"healthMax": 20,
|
||||
"mpMax": 0
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "REGULAR_BATTLE"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -73,6 +73,12 @@ msgstr "Select Save"
|
||||
msgid "ui.select_save.empty"
|
||||
msgstr "Empty Slot"
|
||||
|
||||
msgid "ui.select_save.corrupt"
|
||||
msgstr "Corrupted Save"
|
||||
|
||||
msgid "ui.select_save.corrupt_warning"
|
||||
msgstr "This save file is corrupted and could not be loaded. Please contact support if this issue persists."
|
||||
|
||||
msgid "ui.select_save.slot_format"
|
||||
msgstr "%s Lv.%d %s"
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
{"meshes":[{"file":"house_4_4.dmf","pos":[2,1,0]},{"file":"house_6_3.dmf","pos":[1,9,0]},{"file":"house_2_2.dmf","pos":[12,6,0]}],"tiles":[[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,null,null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,null,null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,null,null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0]]}
|
||||
@@ -0,0 +1 @@
|
||||
{"tiles":[[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[6,0],[2,0],[2,0],[2,0],[2,0],[2,0],[2,0],[7,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[3,0],[1,1],[1,1],[1,1],[1,1],[1,1],[1,1],[5,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[3,0],[1,1],[1,1],[1,1],[1,1],[1,1],[1,1],[5,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[3,0],[1,1],[1,1],[1,1],[1,1],[1,1],[1,1],[5,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[8,0],[4,0],[4,0],[4,0],[12,0],[1,1],[1,1],[5,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[3,0],[1,1],[1,1],[5,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[3,0],[1,1],[1,1],[5,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[8,0],[4,0],[4,0],[9,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0]],"meshes":[{"file":"house_5_3.dmf","pos":[1,1,0]}],"entities":[{"type":"global","globalId":3,"pos":[8,8,1]},{"type":"global","globalId":4,"pos":[12,2,0]}],"areas":[{"min":[11,3,0],"max":[16,9,10],"callbackId":1,"notify":3,"trigger":6}]}
|
||||
@@ -0,0 +1 @@
|
||||
{"meshes":[{"file":"house_8_4.dmf","pos":[1,1,0]},{"file":"house_3_3.dmf","pos":[11,2,0]},{"file":"house_2_2.dmf","pos":[3,11,0]}],"tiles":[[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,null,null,null,null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,null,null,null,null,null,[1,0],[1,0],null,null,null,[1,0],[1,0],[1,0],null,null,null,null,null,null,null,null,[1,0],[1,0],null,null,null,[1,0],[1,0],[1,0],null,null,null,null,null,null,null,null,[1,0],[1,0],null,null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0]]}
|
||||
@@ -0,0 +1 @@
|
||||
{"meshes":[{"file":"house_3_2.dmf","pos":[1,1,0]},{"file":"house_2_3.dmf","pos":[7,2,0]},{"file":"house_4_2.dmf","pos":[1,8,0]},{"file":"house_1_1.dmf","pos":[11,10,0]},{"file":"house_5_2.dmf","pos":[13,6,0]}],"tiles":[[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,[1,0],[1,0],[1,0],null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,[1,0],null,null,null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0]]}
|
||||
@@ -0,0 +1 @@
|
||||
{"meshes":[{"file":"house_5_5.dmf","pos":[3,2,0]},{"file":"house_2_3.dmf","pos":[10,3,0]},{"file":"house_3_1.dmf","pos":[1,12,0]}],"tiles":[[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,null,null,[1,0],[1,0],null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,null,null,[1,0],[1,0],null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,null,null,[1,0],[1,0],null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0]]}
|
||||
@@ -0,0 +1 @@
|
||||
{"tiles":[[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,3],[1,3],[1,3],[1,3],[1,3],[1,3],[1,0],[1,0],[1,0],[1,0],null,null,[1,0],[1,0],[1,0],[1,0],[1,3],[1,3],[1,3],[1,3],[1,3],[1,3],[1,0],[1,0],[1,0],[1,0],null,null,[1,0],[1,0],[1,0],[1,0],[1,3],[1,3],[1,3],[1,3],[1,3],[1,3],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[4,2],[4,2],[4,2],[4,2],[4,2],[4,2],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[4,1],[4,1],[4,1],[4,1],[4,1],[4,1],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[4,0],[4,0],[4,0],[4,0],[4,0],[4,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0]],"meshes":[]}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,10 +0,0 @@
|
||||
{
|
||||
"mesh": "meshes/chunks/chunk_-1_0_0_0.dmf",
|
||||
"color": [
|
||||
255,
|
||||
255,
|
||||
255,
|
||||
255
|
||||
],
|
||||
"texture": "tiles.png"
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
{
|
||||
"mesh": "meshes/chunks/chunk_0_0_0_0.dmf",
|
||||
"color": [
|
||||
255,
|
||||
255,
|
||||
255,
|
||||
255
|
||||
],
|
||||
"texture": "tiles.png"
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
{
|
||||
"mesh": "meshes/chunks/chunk_0_1_0_0.dmf",
|
||||
"color": [
|
||||
255,
|
||||
255,
|
||||
255,
|
||||
255
|
||||
],
|
||||
"texture": "tiles.png"
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
{
|
||||
"mesh": "meshes/chunks/chunk_1_0_0_0.dmf",
|
||||
"color": [
|
||||
255,
|
||||
255,
|
||||
255,
|
||||
255
|
||||
],
|
||||
"texture": "tiles.png"
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
{
|
||||
"mesh": "meshes/chunks/chunk_1_1_0_0.dmf",
|
||||
"color": [
|
||||
255,
|
||||
255,
|
||||
255,
|
||||
255
|
||||
],
|
||||
"texture": "tiles.png"
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
{
|
||||
"mesh": "meshes/chunks/chunk_2_0_0_0.dmf",
|
||||
"color": [
|
||||
255,
|
||||
255,
|
||||
255,
|
||||
255
|
||||
],
|
||||
"texture": "tiles.png"
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -27,6 +27,7 @@ target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
||||
)
|
||||
|
||||
set(DUSK_BACKTRACE ON CACHE BOOL "Enable backtrace support for assert failures.")
|
||||
set(DUSK_TRACK_MEMORY ON CACHE BOOL "Track memoryAllocate() call sites to help find memory leaks.")
|
||||
|
||||
# Define platform-specific macros.
|
||||
target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
||||
|
||||
@@ -60,6 +60,19 @@ target_compile_definitions(${DUSK_BINARY_TARGET_NAME} PUBLIC
|
||||
DUSK_DISPLAY_OVERSCAN=6
|
||||
)
|
||||
|
||||
# logDebug()/logError() additionally write every call to a file on the
|
||||
# Memory Stick (ms0:/PSP/GAME/Dusk/*.log) - a real, measured source of
|
||||
# per-call hitching (fopen+write+fclose every log line), not just a
|
||||
# theoretical cost. Default off so a normal build doesn't pay it; opt in
|
||||
# with -DDUSK_PSP_LOG_FILE=ON when the log file itself is actually needed
|
||||
# (e.g. no way to see stdout on real hardware).
|
||||
set(DUSK_PSP_LOG_FILE OFF CACHE BOOL "Also write PSP debug/error logs to ms0:/PSP/GAME/Dusk/*.log (slow - Memory Stick I/O per call).")
|
||||
if(DUSK_PSP_LOG_FILE)
|
||||
target_compile_definitions(${DUSK_BINARY_TARGET_NAME} PUBLIC
|
||||
DUSK_PSP_LOG_FILE
|
||||
)
|
||||
endif()
|
||||
|
||||
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
target_compile_definitions(${DUSK_BINARY_TARGET_NAME} PUBLIC
|
||||
DUSK_ASSERTIONS_FAKED
|
||||
|
||||
@@ -345,12 +345,14 @@
|
||||
return promise;
|
||||
}
|
||||
|
||||
const MAP_NAME = "overworld";
|
||||
|
||||
function chunkPaths(x, y, z) {
|
||||
return {
|
||||
raw: `assetsraw/chunks/chunk_${x}_${y}_${z}.json`,
|
||||
dcf: `assets/chunks/${x}_${y}_${z}.dcf`,
|
||||
terrainDmf: `assets/meshes/chunks/chunk_${x}_${y}_${z}_0.dmf`,
|
||||
terrainModel: `assets/models/chunks/chunk_${x}_${y}_${z}_0.json`,
|
||||
raw: `assetsraw/maps/${MAP_NAME}/chunks/chunk_${x}_${y}_${z}.json`,
|
||||
dcf: `assets/maps/${MAP_NAME}/chunks/${x}_${y}_${z}.dcf`,
|
||||
terrainDmf: `assets/maps/${MAP_NAME}/meshes/chunks/chunk_${x}_${y}_${z}_0.dmf`,
|
||||
terrainModel: `assets/maps/${MAP_NAME}/models/chunks/chunk_${x}_${y}_${z}_0.json`,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -767,7 +769,7 @@
|
||||
async function buildChunkBrowseList() {
|
||||
const list = document.getElementById("chunkBrowseList");
|
||||
list.innerHTML = "";
|
||||
const res = await apiLs("assetsraw/chunks");
|
||||
const res = await apiLs(`assetsraw/maps/${MAP_NAME}/chunks`);
|
||||
for(const entry of res.entries || []) {
|
||||
const m = entry.name.match(/^chunk_(-?\d+)_(-?\d+)_(-?\d+)\.json$/);
|
||||
if(!m) continue;
|
||||
|
||||
@@ -209,7 +209,10 @@ class Handler(BaseHTTPRequestHandler):
|
||||
self.send_json({"error": "invalid chunk coordinates"}, 400)
|
||||
return
|
||||
|
||||
json_path = PROJECT_ROOT / "assetsraw" / "chunks" / f"chunk_{x}_{y}_{z}.json"
|
||||
json_path = (
|
||||
PROJECT_ROOT / "assetsraw" / "maps" / "overworld" / "chunks"
|
||||
/ f"chunk_{x}_{y}_{z}.json"
|
||||
)
|
||||
if not json_path.is_file():
|
||||
self.send_json({"error": "chunk json not found"}, 404)
|
||||
return
|
||||
|
||||
@@ -50,6 +50,12 @@ if(DUSK_BACKTRACE)
|
||||
)
|
||||
endif()
|
||||
|
||||
if(DUSK_TRACK_MEMORY)
|
||||
target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
||||
DUSK_TRACK_MEMORY
|
||||
)
|
||||
endif()
|
||||
|
||||
# Includes
|
||||
target_include_directories(${DUSK_LIBRARY_TARGET_NAME}
|
||||
PUBLIC
|
||||
@@ -74,6 +80,7 @@ add_subdirectory(engine)
|
||||
add_subdirectory(error)
|
||||
add_subdirectory(input)
|
||||
add_subdirectory(locale)
|
||||
add_subdirectory(perf)
|
||||
add_subdirectory(rpg)
|
||||
add_subdirectory(scene)
|
||||
add_subdirectory(system)
|
||||
|
||||
+4
-14
@@ -25,11 +25,9 @@ errorret_t assetInit(void) {
|
||||
threadMutexInit(&ASSET.loading[i].mutex);
|
||||
}
|
||||
|
||||
// assetInitPlatform must either define both ASSET.zip/ASSET.zipStored or
|
||||
// throw an error.
|
||||
// assetInitPlatform must either define ASSET.zip or throw an error.
|
||||
errorChain(assetInitPlatform());
|
||||
assertNotNull(ASSET.zip, "Asset zip null without error.");
|
||||
assertNotNull(ASSET.zipStored, "Asset stored zip null without error.");
|
||||
threadInit(&ASSET.loadThread, assetUpdateAsync);
|
||||
threadStart(&ASSET.loadThread);
|
||||
|
||||
@@ -40,9 +38,7 @@ bool_t assetFileExists(const char_t *filename) {
|
||||
assertStrLenMax(filename, ASSET_FILE_NAME_MAX, "Filename too long.");
|
||||
|
||||
threadMutexLock(&ASSET.zipLock);
|
||||
bool_t found =
|
||||
zip_name_locate(ASSET.zip, filename, 0) >= 0 ||
|
||||
zip_name_locate(ASSET.zipStored, filename, 0) >= 0;
|
||||
bool_t found = zip_name_locate(ASSET.zip, filename, 0) >= 0;
|
||||
threadMutexUnlock(&ASSET.zipLock);
|
||||
return found;
|
||||
}
|
||||
@@ -445,19 +441,13 @@ errorret_t assetDispose(void) {
|
||||
|
||||
errorChain(assetReapUnused());
|
||||
|
||||
// Cleanup zip files.
|
||||
// Cleanup zip file.
|
||||
if(ASSET.zip != NULL) {
|
||||
if(zip_close(ASSET.zip) != 0) {
|
||||
errorThrow("Failed to close compressed asset zip archive.");
|
||||
errorThrow("Failed to close asset zip archive.");
|
||||
}
|
||||
ASSET.zip = NULL;
|
||||
}
|
||||
if(ASSET.zipStored != NULL) {
|
||||
if(zip_close(ASSET.zipStored) != 0) {
|
||||
errorThrow("Failed to close stored asset zip archive.");
|
||||
}
|
||||
ASSET.zipStored = NULL;
|
||||
}
|
||||
|
||||
errorChain(assetDisposePlatform());
|
||||
threadMutexDispose(&ASSET.zipLock);
|
||||
|
||||
@@ -29,16 +29,12 @@
|
||||
#define ASSET_BASE_DIRECTORY_MAX 256
|
||||
|
||||
typedef struct asset_s {
|
||||
// Compressed (DEFLATE) archive - expected to hold the bulk of a game's
|
||||
// binary assets. Looked up first by assetFileInit().
|
||||
// The dusk.dsk archive - a single uncompressed (ZIP_STORED) zip, so
|
||||
// every entry gets the reliable repeated seeking/re-opening that
|
||||
// libzip only supports reliably for uncompressed entries (locale
|
||||
// strings, MP3 loop restarts, etc.).
|
||||
zip_t *zip;
|
||||
|
||||
// Stored (uncompressed) archive - expected to hold small files that need
|
||||
// reliable repeated seeking/re-opening (e.g. locale strings), which
|
||||
// libzip only supports reliably for uncompressed entries. Looked up by
|
||||
// assetFileInit() only if the name isn't found in `zip`.
|
||||
zip_t *zipStored;
|
||||
|
||||
// Directory dusk.dsk was actually found/opened in (on PSP, the directory
|
||||
// EBOOT.PBP lives in, since dusk.dsk is embedded inside it rather than a
|
||||
// loose file) - populated by each platform's own assetInitXxx() once it
|
||||
@@ -52,7 +48,7 @@ typedef struct asset_s {
|
||||
|
||||
assetplatform_t platform;
|
||||
|
||||
// Guards every libzip call against ASSET.zip/ASSET.zipStored (zip_fopen,
|
||||
// Guards every libzip call against ASSET.zip (zip_fopen,
|
||||
// zip_fread, zip_fclose, zip_fseek, zip_stat, zip_name_locate - see
|
||||
// assetfile.c/assetFileExists). libzip is documented as not thread-safe,
|
||||
// and this asset system genuinely calls it from multiple real threads at
|
||||
|
||||
+39
-163
@@ -30,9 +30,9 @@ errorret_t assetDskParseHeader(
|
||||
// Every field is a little-endian uint32_t regardless of host - convert
|
||||
// to host order (a no-op on little-endian hosts, a real byteswap on
|
||||
// Dolphin's big-endian PowerPC).
|
||||
uint32_t fields[7];
|
||||
uint32_t fields[3];
|
||||
memoryCopy(fields, bytes + ASSET_DSK_MAGIC_SIZE, sizeof(fields));
|
||||
for(uint8_t i = 0; i < 7; i++) {
|
||||
for(uint8_t i = 0; i < 3; i++) {
|
||||
fields[i] = endianLittleToHost32(fields[i]);
|
||||
}
|
||||
|
||||
@@ -41,24 +41,17 @@ errorret_t assetDskParseHeader(
|
||||
errorThrow("dusk.dsk has an unsupported version: %u", version);
|
||||
}
|
||||
|
||||
outHeader->compressedOffset = fields[1];
|
||||
outHeader->compressedSize = fields[2];
|
||||
outHeader->compressedChecksum = fields[3];
|
||||
outHeader->storedOffset = fields[4];
|
||||
outHeader->storedSize = fields[5];
|
||||
outHeader->storedChecksum = fields[6];
|
||||
outHeader->size = fields[1];
|
||||
outHeader->checksum = fields[2];
|
||||
|
||||
errorOk();
|
||||
}
|
||||
|
||||
errorret_t assetDskOpenFromPath(
|
||||
const char_t *path,
|
||||
zip_t **outCompressed,
|
||||
zip_t **outStored
|
||||
zip_t **outZip
|
||||
) {
|
||||
errorChain(assetDskOpenFromPathRange(
|
||||
path, 0, SIZE_MAX, outCompressed, outStored
|
||||
));
|
||||
errorChain(assetDskOpenFromPathRange(path, 0, SIZE_MAX, outZip));
|
||||
errorOk();
|
||||
}
|
||||
|
||||
@@ -66,15 +59,12 @@ errorret_t assetDskOpenFromPathRange(
|
||||
const char_t *path,
|
||||
const size_t baseOffset,
|
||||
const size_t baseSize,
|
||||
zip_t **outCompressed,
|
||||
zip_t **outStored
|
||||
zip_t **outZip
|
||||
) {
|
||||
assertNotNull(path, "Path cannot be NULL.");
|
||||
assertNotNull(outCompressed, "Out compressed cannot be NULL.");
|
||||
assertNotNull(outStored, "Out stored cannot be NULL.");
|
||||
assertNotNull(outZip, "Out zip cannot be NULL.");
|
||||
|
||||
*outCompressed = NULL;
|
||||
*outStored = NULL;
|
||||
*outZip = NULL;
|
||||
|
||||
FILE *headerFile = fopen(path, "rb");
|
||||
if(headerFile == NULL) {
|
||||
@@ -96,104 +86,30 @@ errorret_t assetDskOpenFromPathRange(
|
||||
assetdskheader_t header;
|
||||
errorChain(assetDskParseHeader(headerBytes, sizeof(headerBytes), &header));
|
||||
|
||||
if(
|
||||
(size_t) header.compressedOffset + header.compressedSize > baseSize ||
|
||||
(size_t) header.storedOffset + header.storedSize > baseSize
|
||||
) {
|
||||
errorThrow("dusk.dsk header describes ranges beyond its containing file.");
|
||||
if((size_t) ASSET_DSK_HEADER_SIZE + header.size > baseSize) {
|
||||
errorThrow("dusk.dsk header describes a range beyond its containing file.");
|
||||
}
|
||||
|
||||
zip_error_t zipError;
|
||||
zip_error_init(&zipError);
|
||||
|
||||
zip_source_t *compressedSource = zip_source_file_create(
|
||||
zip_source_t *source = zip_source_file_create(
|
||||
path,
|
||||
(zip_uint64_t) (baseOffset + header.compressedOffset),
|
||||
(zip_int64_t) header.compressedSize,
|
||||
(zip_uint64_t) (baseOffset + ASSET_DSK_HEADER_SIZE),
|
||||
(zip_int64_t) header.size,
|
||||
&zipError
|
||||
);
|
||||
if(compressedSource == NULL) {
|
||||
if(source == NULL) {
|
||||
errorThrow(
|
||||
"Failed to create compressed dusk.dsk source: %s",
|
||||
zip_error_strerror(&zipError)
|
||||
"Failed to create dusk.dsk source: %s", zip_error_strerror(&zipError)
|
||||
);
|
||||
}
|
||||
|
||||
*outCompressed =
|
||||
zip_open_from_source(compressedSource, ZIP_RDONLY, &zipError);
|
||||
if(*outCompressed == NULL) {
|
||||
zip_source_free(compressedSource);
|
||||
*outZip = zip_open_from_source(source, ZIP_RDONLY, &zipError);
|
||||
if(*outZip == NULL) {
|
||||
zip_source_free(source);
|
||||
errorThrow(
|
||||
"Failed to open compressed dusk.dsk archive: %s",
|
||||
zip_error_strerror(&zipError)
|
||||
);
|
||||
}
|
||||
|
||||
zip_source_t *storedSource = zip_source_file_create(
|
||||
path,
|
||||
(zip_uint64_t) (baseOffset + header.storedOffset),
|
||||
(zip_int64_t) header.storedSize,
|
||||
&zipError
|
||||
);
|
||||
if(storedSource == NULL) {
|
||||
zip_close(*outCompressed);
|
||||
*outCompressed = NULL;
|
||||
errorThrow(
|
||||
"Failed to create stored dusk.dsk source: %s",
|
||||
zip_error_strerror(&zipError)
|
||||
);
|
||||
}
|
||||
|
||||
*outStored = zip_open_from_source(storedSource, ZIP_RDONLY, &zipError);
|
||||
if(*outStored == NULL) {
|
||||
zip_source_free(storedSource);
|
||||
zip_close(*outCompressed);
|
||||
*outCompressed = NULL;
|
||||
errorThrow(
|
||||
"Failed to open stored dusk.dsk archive: %s",
|
||||
zip_error_strerror(&zipError)
|
||||
);
|
||||
}
|
||||
|
||||
// The stored archive is small by convention, so verifying its checksum
|
||||
// here (one extra small read) is cheap; the compressed archive isn't
|
||||
// checked since it's meant to be read lazily/on-demand from here on.
|
||||
uint8_t *storedBytes = (uint8_t *) memoryAllocate(header.storedSize);
|
||||
FILE *storedFile = fopen(path, "rb");
|
||||
if(storedFile == NULL) {
|
||||
memoryFree(storedBytes);
|
||||
zip_close(*outStored);
|
||||
zip_close(*outCompressed);
|
||||
*outStored = NULL;
|
||||
*outCompressed = NULL;
|
||||
errorThrow(
|
||||
"Failed to re-open dusk.dsk to verify stored checksum: %s", path
|
||||
);
|
||||
}
|
||||
fseek(storedFile, (long) (baseOffset + header.storedOffset), SEEK_SET);
|
||||
size_t storedRead = fread(storedBytes, 1, header.storedSize, storedFile);
|
||||
fclose(storedFile);
|
||||
if(storedRead != header.storedSize) {
|
||||
memoryFree(storedBytes);
|
||||
zip_close(*outStored);
|
||||
zip_close(*outCompressed);
|
||||
*outStored = NULL;
|
||||
*outCompressed = NULL;
|
||||
errorThrow(
|
||||
"Failed to read dusk.dsk stored archive to verify checksum: %s", path
|
||||
);
|
||||
}
|
||||
|
||||
uint32_t checksum =
|
||||
(uint32_t) crc32(0L, storedBytes, (uInt) header.storedSize);
|
||||
memoryFree(storedBytes);
|
||||
if(checksum != header.storedChecksum) {
|
||||
zip_close(*outStored);
|
||||
zip_close(*outCompressed);
|
||||
*outStored = NULL;
|
||||
*outCompressed = NULL;
|
||||
errorThrow(
|
||||
"dusk.dsk stored archive failed checksum verification: %s", path
|
||||
"Failed to open dusk.dsk archive: %s", zip_error_strerror(&zipError)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -203,85 +119,45 @@ errorret_t assetDskOpenFromPathRange(
|
||||
errorret_t assetDskOpenFromBuffer(
|
||||
uint8_t *buffer,
|
||||
const size_t bufferSize,
|
||||
zip_t **outCompressed,
|
||||
zip_t **outStored
|
||||
zip_t **outZip
|
||||
) {
|
||||
assertNotNull(buffer, "Buffer cannot be NULL.");
|
||||
assertNotNull(outCompressed, "Out compressed cannot be NULL.");
|
||||
assertNotNull(outStored, "Out stored cannot be NULL.");
|
||||
assertNotNull(outZip, "Out zip cannot be NULL.");
|
||||
|
||||
*outCompressed = NULL;
|
||||
*outStored = NULL;
|
||||
*outZip = NULL;
|
||||
|
||||
assetdskheader_t header;
|
||||
errorChain(assetDskParseHeader(buffer, bufferSize, &header));
|
||||
|
||||
if(
|
||||
(size_t) header.compressedOffset + header.compressedSize > bufferSize ||
|
||||
(size_t) header.storedOffset + header.storedSize > bufferSize
|
||||
) {
|
||||
errorThrow("dusk.dsk header describes ranges beyond the buffer.");
|
||||
if((size_t) ASSET_DSK_HEADER_SIZE + header.size > bufferSize) {
|
||||
errorThrow("dusk.dsk header describes a range beyond the buffer.");
|
||||
}
|
||||
|
||||
uint32_t compressedChecksum = (uint32_t) crc32(
|
||||
0L, buffer + header.compressedOffset, (uInt) header.compressedSize
|
||||
);
|
||||
if(compressedChecksum != header.compressedChecksum) {
|
||||
errorThrow("dusk.dsk compressed archive failed checksum verification.");
|
||||
}
|
||||
|
||||
uint32_t storedChecksum = (uint32_t) crc32(
|
||||
0L, buffer + header.storedOffset, (uInt) header.storedSize
|
||||
);
|
||||
if(storedChecksum != header.storedChecksum) {
|
||||
errorThrow("dusk.dsk stored archive failed checksum verification.");
|
||||
uint8_t *data = buffer + ASSET_DSK_HEADER_SIZE;
|
||||
uint32_t checksum = (uint32_t) crc32(0L, data, (uInt) header.size);
|
||||
if(checksum != header.checksum) {
|
||||
errorThrow("dusk.dsk archive failed checksum verification.");
|
||||
}
|
||||
|
||||
zip_error_t zipError;
|
||||
zip_error_init(&zipError);
|
||||
|
||||
// freep=0 for both - they're non-owning windows into the same caller-owned
|
||||
// buffer, not independent allocations libzip should free.
|
||||
zip_source_t *compressedSource = zip_source_buffer_create(
|
||||
buffer + header.compressedOffset, header.compressedSize, 0, &zipError
|
||||
// freep=0 - this is a non-owning window into the same caller-owned
|
||||
// buffer, not an independent allocation libzip should free.
|
||||
zip_source_t *source = zip_source_buffer_create(
|
||||
data, header.size, 0, &zipError
|
||||
);
|
||||
if(compressedSource == NULL) {
|
||||
if(source == NULL) {
|
||||
errorThrow(
|
||||
"Failed to create compressed dusk.dsk source: %s",
|
||||
zip_error_strerror(&zipError)
|
||||
"Failed to create dusk.dsk source: %s", zip_error_strerror(&zipError)
|
||||
);
|
||||
}
|
||||
|
||||
*outCompressed =
|
||||
zip_open_from_source(compressedSource, ZIP_RDONLY, &zipError);
|
||||
if(*outCompressed == NULL) {
|
||||
zip_source_free(compressedSource);
|
||||
*outZip = zip_open_from_source(source, ZIP_RDONLY, &zipError);
|
||||
if(*outZip == NULL) {
|
||||
zip_source_free(source);
|
||||
errorThrow(
|
||||
"Failed to open compressed dusk.dsk archive: %s",
|
||||
zip_error_strerror(&zipError)
|
||||
);
|
||||
}
|
||||
|
||||
zip_source_t *storedSource = zip_source_buffer_create(
|
||||
buffer + header.storedOffset, header.storedSize, 0, &zipError
|
||||
);
|
||||
if(storedSource == NULL) {
|
||||
zip_close(*outCompressed);
|
||||
*outCompressed = NULL;
|
||||
errorThrow(
|
||||
"Failed to create stored dusk.dsk source: %s",
|
||||
zip_error_strerror(&zipError)
|
||||
);
|
||||
}
|
||||
|
||||
*outStored = zip_open_from_source(storedSource, ZIP_RDONLY, &zipError);
|
||||
if(*outStored == NULL) {
|
||||
zip_source_free(storedSource);
|
||||
zip_close(*outCompressed);
|
||||
*outCompressed = NULL;
|
||||
errorThrow(
|
||||
"Failed to open stored dusk.dsk archive: %s",
|
||||
zip_error_strerror(&zipError)
|
||||
"Failed to open dusk.dsk archive: %s", zip_error_strerror(&zipError)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
+36
-47
@@ -13,30 +13,26 @@
|
||||
// never gets misread as a valid dusk.dsk.
|
||||
#define ASSET_DSK_MAGIC_SIZE 4
|
||||
#define ASSET_DSK_MAGIC "DSK2"
|
||||
#define ASSET_DSK_VERSION 1
|
||||
#define ASSET_DSK_VERSION 2
|
||||
|
||||
// magic(4) + version(4) + compressedOffset(4) + compressedSize(4) +
|
||||
// compressedChecksum(4) + storedOffset(4) + storedSize(4) +
|
||||
// storedChecksum(4), all little-endian regardless of host - see
|
||||
// assetDskParseHeader.
|
||||
#define ASSET_DSK_HEADER_SIZE 32
|
||||
// magic(4) + version(4) + size(4) + checksum(4), all little-endian
|
||||
// regardless of host - see assetDskParseHeader. The zip archive itself
|
||||
// starts immediately after, at ASSET_DSK_HEADER_SIZE.
|
||||
#define ASSET_DSK_HEADER_SIZE 16
|
||||
|
||||
/**
|
||||
* Parsed dusk.dsk (DSK2 format) header. dusk.dsk is two independent, back
|
||||
* to back zip archives (see tools/asset/pack) rather than a single plain
|
||||
* zip: a "compressed" one (DEFLATE, expected to hold the bulk of a game's
|
||||
* binary assets, opened lazily/on-demand) and a "stored" one (uncompressed,
|
||||
* expected to hold small files - locale strings, config - that need
|
||||
* reliable repeated seeking/re-opening, which libzip only supports for
|
||||
* uncompressed entries).
|
||||
* Parsed dusk.dsk (DSK2 format) header. dusk.dsk is a single uncompressed
|
||||
* (ZIP_STORED) zip archive (see tools/asset/pack) rather than DEFLATEd -
|
||||
* the bulk of what's packed (audio, images) is already compressed at the
|
||||
* file level, so DEFLATE-ing the whole archive on top buys negligible
|
||||
* space for real CPU cost, and every entry gets the reliable repeated
|
||||
* seeking/re-opening that libzip only supports for uncompressed entries
|
||||
* (locale line-by-line reads, MP3 loop restarts, etc.) instead of just a
|
||||
* hand-picked subset of files.
|
||||
*/
|
||||
typedef struct {
|
||||
uint32_t compressedOffset;
|
||||
uint32_t compressedSize;
|
||||
uint32_t compressedChecksum;
|
||||
uint32_t storedOffset;
|
||||
uint32_t storedSize;
|
||||
uint32_t storedChecksum;
|
||||
uint32_t size;
|
||||
uint32_t checksum;
|
||||
} assetdskheader_t;
|
||||
|
||||
/**
|
||||
@@ -56,27 +52,24 @@ errorret_t assetDskParseHeader(
|
||||
);
|
||||
|
||||
/**
|
||||
* Opens both archives of a dusk.dsk file given a filesystem path, using
|
||||
* lazy/windowed file-backed zip sources - no more memory used than the
|
||||
* Opens the dusk.dsk archive given a filesystem path, using a lazy/
|
||||
* windowed file-backed zip source - no more memory used than the
|
||||
* existing per-platform small read buffers, matching the memory
|
||||
* characteristics of a plain zip_open() on the whole file. Verifies the
|
||||
* (small, by convention) stored archive's checksum; the compressed
|
||||
* archive's checksum is intentionally not verified here since doing so
|
||||
* would require reading the bulk of the game's assets just to compute it.
|
||||
* characteristics of a plain zip_open() on the whole file. The checksum
|
||||
* is intentionally not verified here since doing so would require
|
||||
* reading the whole (potentially large) archive just to compute it.
|
||||
*
|
||||
* See assetDskOpenFromPathRange() for the case where the DSK2 blob isn't
|
||||
* the whole file (e.g. embedded inside another container).
|
||||
*
|
||||
* @param path Filesystem path to the dusk.dsk file.
|
||||
* @param outCompressed Set to the opened compressed archive on success.
|
||||
* @param outStored Set to the opened stored archive on success.
|
||||
* @param outZip Set to the opened archive on success.
|
||||
* @return OK on success, error if the file is missing, too short, has a
|
||||
* bad header, or either archive fails to open/verify.
|
||||
* bad header, or the archive fails to open.
|
||||
*/
|
||||
errorret_t assetDskOpenFromPath(
|
||||
const char_t *path,
|
||||
zip_t **outCompressed,
|
||||
zip_t **outStored
|
||||
zip_t **outZip
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -90,39 +83,35 @@ errorret_t assetDskOpenFromPath(
|
||||
* @param path Filesystem path to the container file.
|
||||
* @param baseOffset Byte offset within `path` where the DSK2 blob starts.
|
||||
* @param baseSize Number of bytes available at `baseOffset`.
|
||||
* @param outCompressed Set to the opened compressed archive on success.
|
||||
* @param outStored Set to the opened stored archive on success.
|
||||
* @param outZip Set to the opened archive on success.
|
||||
* @return OK on success, error if the file is missing, too short, has a
|
||||
* bad header, or either archive fails to open/verify.
|
||||
* bad header, or the archive fails to open.
|
||||
*/
|
||||
errorret_t assetDskOpenFromPathRange(
|
||||
const char_t *path,
|
||||
const size_t baseOffset,
|
||||
const size_t baseSize,
|
||||
zip_t **outCompressed,
|
||||
zip_t **outStored
|
||||
zip_t **outZip
|
||||
);
|
||||
|
||||
/**
|
||||
* Opens both archives of a dusk.dsk file already fully resident in memory
|
||||
* (e.g. a PSAR embedded in an EBOOT.PBP, or an ISO-embedded file already
|
||||
* read via DVD_ReadAbs - platforms that already buffer the whole file for
|
||||
* reasons unrelated to this format). Neither archive takes ownership of
|
||||
* `buffer` (both are opened as non-owning sub-ranges of it) - the caller
|
||||
* Opens the dusk.dsk archive already fully resident in memory (e.g. a
|
||||
* PSAR embedded in an EBOOT.PBP, or an ISO-embedded file already read via
|
||||
* DVD_ReadAbs - platforms that already buffer the whole file for reasons
|
||||
* unrelated to this format). The returned archive doesn't take ownership
|
||||
* of `buffer` (it's opened as a non-owning sub-range of it) - the caller
|
||||
* remains responsible for freeing it, and must keep it alive for as long
|
||||
* as either archive stays open. Verifies both archives' checksums, since
|
||||
* the bytes are already resident.
|
||||
* as the archive stays open. Verifies the checksum, since the bytes are
|
||||
* already resident.
|
||||
*
|
||||
* @param buffer The whole dusk.dsk file's bytes.
|
||||
* @param bufferSize Number of bytes at `buffer`.
|
||||
* @param outCompressed Set to the opened compressed archive on success.
|
||||
* @param outStored Set to the opened stored archive on success.
|
||||
* @param outZip Set to the opened archive on success.
|
||||
* @return OK on success, error if too short, has a bad header/checksum, or
|
||||
* either archive fails to open.
|
||||
* the archive fails to open.
|
||||
*/
|
||||
errorret_t assetDskOpenFromBuffer(
|
||||
uint8_t *buffer,
|
||||
const size_t bufferSize,
|
||||
zip_t **outCompressed,
|
||||
zip_t **outStored
|
||||
zip_t **outZip
|
||||
);
|
||||
@@ -24,20 +24,11 @@ errorret_t assetFileInit(
|
||||
file->params = params;
|
||||
file->output = output;
|
||||
|
||||
// Stat the file, trying the compressed archive first and falling back to
|
||||
// the stored one - remember which matched so assetFileOpen opens it from
|
||||
// the right archive.
|
||||
zip_stat_init(&file->stat);
|
||||
threadMutexLock(&ASSET.zipLock);
|
||||
if(zip_stat(ASSET.zip, filename, 0, &file->stat) == 0) {
|
||||
file->sourceZip = ASSET.zip;
|
||||
} else if(zip_stat(ASSET.zipStored, filename, 0, &file->stat) == 0) {
|
||||
file->sourceZip = ASSET.zipStored;
|
||||
} else {
|
||||
file->sourceZip = NULL;
|
||||
}
|
||||
int statResult = zip_stat(ASSET.zip, filename, 0, &file->stat);
|
||||
threadMutexUnlock(&ASSET.zipLock);
|
||||
if(file->sourceZip == NULL) {
|
||||
if(statResult != 0) {
|
||||
errorThrow("Failed to stat asset file: %s", filename);
|
||||
}
|
||||
|
||||
@@ -85,11 +76,10 @@ errorret_t assetFileRewind(assetfile_t *file) {
|
||||
errorret_t assetFileOpen(assetfile_t *file) {
|
||||
assertNotNull(file, "Asset file cannot be NULL.");
|
||||
assertNotNull(file->filename, "Asset file filename cannot be NULL.");
|
||||
assertNotNull(file->sourceZip, "Asset file must be inited before opening.");
|
||||
assertNull(file->zipFile, "Asset file already open.");
|
||||
|
||||
threadMutexLock(&ASSET.zipLock);
|
||||
file->zipFile = zip_fopen(file->sourceZip, file->filename, 0);
|
||||
file->zipFile = zip_fopen(ASSET.zip, file->filename, 0);
|
||||
threadMutexUnlock(&ASSET.zipLock);
|
||||
if(file->zipFile == NULL) {
|
||||
errorThrow("Failed to open asset file: %s", file->filename);
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include "error/error.h"
|
||||
#include <zip.h>
|
||||
|
||||
#define ASSET_FILE_NAME_MAX 48
|
||||
#define ASSET_FILE_NAME_MAX 128
|
||||
|
||||
// Max bytes requested per zip_fread() call in assetFileRead(). Some
|
||||
// zip_fread() implementations (seen on PSP) reject a single call asking
|
||||
@@ -32,11 +32,6 @@ typedef struct assetfile_s {
|
||||
zip_int64_t position;
|
||||
zip_int64_t lastRead;
|
||||
zip_file_t *zipFile;
|
||||
|
||||
// The archive this file was found in (ASSET.zip or ASSET.zipStored),
|
||||
// set by assetFileInit and used by assetFileOpen so lookups fall back
|
||||
// correctly between the two dusk.dsk archives.
|
||||
zip_t *sourceZip;
|
||||
} assetfile_t;
|
||||
|
||||
/**
|
||||
|
||||
@@ -8,41 +8,284 @@
|
||||
#include "assetchunkloader.h"
|
||||
#include "assert/assert.h"
|
||||
#include "util/memory.h"
|
||||
#include "util/endian.h"
|
||||
#include "util/string.h"
|
||||
#include "asset/asset.h"
|
||||
#include "asset/loader/assetloading.h"
|
||||
#include "asset/loader/assetentry.h"
|
||||
#include "asset/loader/assetloader.h"
|
||||
#include "asset/asset.h"
|
||||
#include "asset/loader/json/assetjsonloader.h"
|
||||
#include "display/color.h"
|
||||
#include "display/texture/texture.h"
|
||||
#include "rpg/overworld/worldpos.h"
|
||||
#include "yyjson.h"
|
||||
|
||||
#define ASSET_CHUNK_TERRAIN_TEXTURE "tiles.png"
|
||||
|
||||
// Per-shape corner Z offsets (sw, se, ne, nw) as offsets from a tile's own
|
||||
// base Z, ported 1:1 from tools/asset/chunk/__main__.py's _RAMP_CORNERS.
|
||||
// TILE_SHAPE_NULL's row is never read - assetChunkTilesHaveTerrain/
|
||||
// assetChunkBuildTerrain skip those tiles outright.
|
||||
static const float_t CHUNK_RAMP_CORNERS[TILE_SHAPE_COUNT][4] = {
|
||||
[TILE_SHAPE_GROUND] = {0.0f, 0.0f, 0.0f, 0.0f},
|
||||
[TILE_SHAPE_RAMP_NORTH] = {0.0f, 0.0f, 1.0f, 1.0f},
|
||||
[TILE_SHAPE_RAMP_SOUTH] = {1.0f, 1.0f, 0.0f, 0.0f},
|
||||
[TILE_SHAPE_RAMP_EAST] = {0.0f, 1.0f, 1.0f, 0.0f},
|
||||
[TILE_SHAPE_RAMP_WEST] = {1.0f, 0.0f, 0.0f, 1.0f},
|
||||
[TILE_SHAPE_RAMP_NORTHEAST] = {0.0f, 0.0f, 1.0f, 0.0f},
|
||||
[TILE_SHAPE_RAMP_NORTHWEST] = {0.0f, 0.0f, 0.0f, 1.0f},
|
||||
[TILE_SHAPE_RAMP_SOUTHEAST] = {0.0f, 1.0f, 0.0f, 0.0f},
|
||||
[TILE_SHAPE_RAMP_SOUTHWEST] = {1.0f, 0.0f, 0.0f, 0.0f},
|
||||
[TILE_SHAPE_RAMP_NORTHEAST_INNER] = {0.0f, 1.0f, 1.0f, 1.0f},
|
||||
[TILE_SHAPE_RAMP_NORTHWEST_INNER] = {1.0f, 0.0f, 1.0f, 1.0f},
|
||||
[TILE_SHAPE_RAMP_SOUTHEAST_INNER] = {1.0f, 1.0f, 1.0f, 0.0f},
|
||||
[TILE_SHAPE_RAMP_SOUTHWEST_INNER] = {1.0f, 1.0f, 0.0f, 1.0f},
|
||||
};
|
||||
|
||||
errorret_t assetChunkLoaderAsync(assetloading_t *loading) {
|
||||
assertNotNull(loading, "Loading cannot be NULL");
|
||||
assertNotMainThread("Should be called from an async thread.");
|
||||
errorOk();
|
||||
}
|
||||
|
||||
if(loading->loading.chunk.state != ASSET_CHUNK_LOADING_STATE_READ_FILE) {
|
||||
errorOk();
|
||||
static bool_t assetChunkTilesHaveTerrain(const tile_t *tiles) {
|
||||
for(uint32_t i = 0; i < CHUNK_TILE_COUNT; i++) {
|
||||
if(tiles[i].shape != TILE_SHAPE_NULL) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reads the "tiles" array - a dense, fixed-size CHUNK_TILE_COUNT grid,
|
||||
// one slot per (x, y) column at index x + y * CHUNK_WIDTH (position is
|
||||
// implicit in the index, not stored). Each slot is either `null` (empty
|
||||
// column, already zeroed = TILE_SHAPE_NULL) or a 2-element [type, z]
|
||||
// array.
|
||||
static void assetChunkParseTiles(yyjson_val *root, tile_t *tiles) {
|
||||
memoryZero(tiles, CHUNK_TILE_COUNT * sizeof(tile_t));
|
||||
|
||||
yyjson_val *tilesArr = yyjson_obj_get(root, "tiles");
|
||||
if(!yyjson_is_arr(tilesArr)) return;
|
||||
|
||||
size_t idx, len;
|
||||
yyjson_val *tileVal;
|
||||
yyjson_arr_foreach(tilesArr, idx, len, tileVal) {
|
||||
if(idx >= CHUNK_TILE_COUNT) break;
|
||||
if(!yyjson_is_arr(tileVal) || yyjson_arr_size(tileVal) < 2) continue;
|
||||
|
||||
int32_t type = (int32_t)yyjson_get_int(yyjson_arr_get(tileVal, 0));
|
||||
int32_t z = (int32_t)yyjson_get_int(yyjson_arr_get(tileVal, 1));
|
||||
tiles[idx] = (tile_t){ .shape = (tileshape_t)type, .z = (uint8_t)z };
|
||||
}
|
||||
}
|
||||
|
||||
// Resolves "meshes" (external building references, by bare filename) into
|
||||
// out->modelNames/meshOffsets starting at *ioIndex, advancing it as
|
||||
// entries are written. Filenames are resolved as
|
||||
// "models/buildings/<basename>.json" - a hardcoded stand-in for
|
||||
// tools/asset/chunk/__main__.py's find_model() recursive search, valid
|
||||
// as long as every building model lives flat under that one directory
|
||||
// (true today - see the raw-json-maps plan notes for the tradeoff).
|
||||
static void assetChunkParseMeshes(
|
||||
yyjson_val *root, assetchunkoutput_t *out, uint8_t *ioIndex
|
||||
) {
|
||||
yyjson_val *meshesArr = yyjson_obj_get(root, "meshes");
|
||||
if(!yyjson_is_arr(meshesArr)) return;
|
||||
|
||||
size_t idx, len;
|
||||
yyjson_val *meshVal;
|
||||
yyjson_arr_foreach(meshesArr, idx, len, meshVal) {
|
||||
if(*ioIndex >= CHUNK_MESH_COUNT_MAX) break;
|
||||
|
||||
yyjson_val *fileVal = yyjson_obj_get(meshVal, "file");
|
||||
if(!fileVal || !yyjson_is_str(fileVal)) continue;
|
||||
|
||||
char_t baseName[CHUNK_MESH_NAME_MAX];
|
||||
stringCopy(baseName, yyjson_get_str(fileVal), sizeof(baseName));
|
||||
char_t *dot = stringFindLastChar(baseName, '.');
|
||||
if(dot != NULL) *dot = '\0';
|
||||
|
||||
uint8_t m = *ioIndex;
|
||||
stringFormat(
|
||||
out->modelNames[m], CHUNK_MESH_NAME_MAX,
|
||||
"models/buildings/%s.json", baseName
|
||||
);
|
||||
|
||||
vec3 offset = {0.0f, 0.0f, 0.0f};
|
||||
yyjson_val *posArr = yyjson_obj_get(meshVal, "pos");
|
||||
if(yyjson_is_arr(posArr) && yyjson_arr_size(posArr) >= 3) {
|
||||
offset[0] = (float_t)yyjson_get_num(yyjson_arr_get(posArr, 0));
|
||||
offset[1] = (float_t)yyjson_get_num(yyjson_arr_get(posArr, 1));
|
||||
offset[2] = (float_t)yyjson_get_num(yyjson_arr_get(posArr, 2));
|
||||
}
|
||||
memoryCopy(out->meshOffsets[m], offset, sizeof(vec3));
|
||||
|
||||
(*ioIndex)++;
|
||||
}
|
||||
}
|
||||
|
||||
static void assetChunkParseEntities(yyjson_val *root, assetchunkoutput_t *out) {
|
||||
out->entitySpawnCount = 0;
|
||||
|
||||
yyjson_val *arr = yyjson_obj_get(root, "entities");
|
||||
if(!yyjson_is_arr(arr)) return;
|
||||
|
||||
size_t idx, len;
|
||||
yyjson_val *val;
|
||||
yyjson_arr_foreach(arr, idx, len, val) {
|
||||
if(out->entitySpawnCount >= CHUNK_ENTITY_SPAWN_COUNT_MAX) break;
|
||||
|
||||
const char_t *type = yyjson_get_str(yyjson_obj_get(val, "type"));
|
||||
yyjson_val *posArr = yyjson_obj_get(val, "pos");
|
||||
if(type == NULL || !yyjson_is_arr(posArr) || yyjson_arr_size(posArr) < 3) {
|
||||
continue;
|
||||
}
|
||||
worldpos_t pos = {
|
||||
.x = (worldunit_t)yyjson_get_int(yyjson_arr_get(posArr, 0)),
|
||||
.y = (worldunit_t)yyjson_get_int(yyjson_arr_get(posArr, 1)),
|
||||
.z = (worldunit_t)yyjson_get_int(yyjson_arr_get(posArr, 2)),
|
||||
};
|
||||
|
||||
chunkentityspawn_t *spawn = &out->entitySpawns[out->entitySpawnCount];
|
||||
if(stringEquals(type, "global")) {
|
||||
spawn->kind = CHUNK_ENTITY_SPAWN_KIND_GLOBAL;
|
||||
spawn->globalId =
|
||||
(uint16_t)yyjson_get_int(yyjson_obj_get(val, "globalId"));
|
||||
spawn->itemId = 0;
|
||||
spawn->itemQuantity = 0;
|
||||
} else if(stringEquals(type, "item")) {
|
||||
spawn->kind = CHUNK_ENTITY_SPAWN_KIND_ITEM;
|
||||
spawn->globalId = 0;
|
||||
spawn->itemId = (uint16_t)yyjson_get_int(yyjson_obj_get(val, "itemId"));
|
||||
spawn->itemQuantity =
|
||||
(uint8_t)yyjson_get_int(yyjson_obj_get(val, "quantity"));
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
spawn->position = pos;
|
||||
out->entitySpawnCount++;
|
||||
}
|
||||
}
|
||||
|
||||
static void assetChunkParseAreas(yyjson_val *root, assetchunkoutput_t *out) {
|
||||
out->areaSpawnCount = 0;
|
||||
|
||||
yyjson_val *arr = yyjson_obj_get(root, "areas");
|
||||
if(!yyjson_is_arr(arr)) return;
|
||||
|
||||
size_t idx, len;
|
||||
yyjson_val *val;
|
||||
yyjson_arr_foreach(arr, idx, len, val) {
|
||||
if(out->areaSpawnCount >= CHUNK_AREA_COUNT_MAX) break;
|
||||
|
||||
yyjson_val *minArr = yyjson_obj_get(val, "min");
|
||||
yyjson_val *maxArr = yyjson_obj_get(val, "max");
|
||||
if(
|
||||
!yyjson_is_arr(minArr) || yyjson_arr_size(minArr) < 3 ||
|
||||
!yyjson_is_arr(maxArr) || yyjson_arr_size(maxArr) < 3
|
||||
) continue;
|
||||
|
||||
chunkareaspawn_t *area = &out->areaSpawns[out->areaSpawnCount];
|
||||
area->min = (worldpos_t){
|
||||
.x = (worldunit_t)yyjson_get_int(yyjson_arr_get(minArr, 0)),
|
||||
.y = (worldunit_t)yyjson_get_int(yyjson_arr_get(minArr, 1)),
|
||||
.z = (worldunit_t)yyjson_get_int(yyjson_arr_get(minArr, 2)),
|
||||
};
|
||||
area->max = (worldpos_t){
|
||||
.x = (worldunit_t)yyjson_get_int(yyjson_arr_get(maxArr, 0)),
|
||||
.y = (worldunit_t)yyjson_get_int(yyjson_arr_get(maxArr, 1)),
|
||||
.z = (worldunit_t)yyjson_get_int(yyjson_arr_get(maxArr, 2)),
|
||||
};
|
||||
area->callbackId =
|
||||
(uint16_t)yyjson_get_int(yyjson_obj_get(val, "callbackId"));
|
||||
area->notify = (uint8_t)yyjson_get_int(yyjson_obj_get(val, "notify"));
|
||||
area->trigger = (uint8_t)yyjson_get_int(yyjson_obj_get(val, "trigger"));
|
||||
out->areaSpawnCount++;
|
||||
}
|
||||
}
|
||||
|
||||
// Six vertices (2 CCW triangles) for one tile's quad, matching
|
||||
// tools/asset/chunk/__main__.py's _tile_quad. Corner order: SW=(x,y),
|
||||
// SE=(x+1,y), NE=(x+1,y+1), NW=(x,y+1). NORTH=+Y, EAST=+X.
|
||||
static void assetChunkAppendTileQuad(
|
||||
meshvertex_t *verts, uint32_t *vertCount,
|
||||
const uint32_t x, const uint32_t y,
|
||||
const float_t sw, const float_t se, const float_t ne, const float_t nw
|
||||
) {
|
||||
const float_t u0 = (float_t)x / (float_t)CHUNK_WIDTH;
|
||||
const float_t u1 = (float_t)(x + 1) / (float_t)CHUNK_WIDTH;
|
||||
const float_t v0 = (float_t)y / (float_t)CHUNK_HEIGHT;
|
||||
const float_t v1 = (float_t)(y + 1) / (float_t)CHUNK_HEIGHT;
|
||||
const float_t fx = (float_t)x;
|
||||
const float_t fy = (float_t)y;
|
||||
|
||||
meshvertex_t *v = verts + *vertCount;
|
||||
v[0] = (meshvertex_t){ .uv = {u0, v0}, .pos = {fx, fy, sw} };
|
||||
v[1] = (meshvertex_t){ .uv = {u1, v0}, .pos = {fx + 1, fy, se} };
|
||||
v[2] = (meshvertex_t){ .uv = {u1, v1}, .pos = {fx + 1, fy + 1, ne} };
|
||||
v[3] = (meshvertex_t){ .uv = {u0, v0}, .pos = {fx, fy, sw} };
|
||||
v[4] = (meshvertex_t){ .uv = {u1, v1}, .pos = {fx + 1, fy + 1, ne} };
|
||||
v[5] = (meshvertex_t){ .uv = {u0, v1}, .pos = {fx, fy + 1, nw} };
|
||||
*vertCount += 6;
|
||||
}
|
||||
|
||||
// Builds a mesh_t straight from the tile grid - one quad per non-null
|
||||
// tile column, shaped by CHUNK_RAMP_CORNERS - the runtime equivalent of
|
||||
// tools/asset/chunk/__main__.py's build_terrain_verts. Only called once
|
||||
// assetChunkTilesHaveTerrain has confirmed at least one real tile exists.
|
||||
// Mirrors assetMeshLoaderSync's meshInit/meshFlush/free-after-upload
|
||||
// sequence (assetmeshloader.c) since this produces the same
|
||||
// assetmeshoutput_t shape, just from generated verts instead of a file.
|
||||
static errorret_t assetChunkBuildTerrain(
|
||||
const tile_t *tiles, assetmeshoutput_t *out
|
||||
) {
|
||||
meshvertex_t *verts = memoryAllocate(
|
||||
CHUNK_TILE_COUNT * 6 * sizeof(meshvertex_t)
|
||||
);
|
||||
uint32_t vertCount = 0;
|
||||
|
||||
for(uint32_t y = 0; y < CHUNK_HEIGHT; y++) {
|
||||
for(uint32_t x = 0; x < CHUNK_WIDTH; x++) {
|
||||
const tile_t *tile = &tiles[x + y * CHUNK_WIDTH];
|
||||
if(tile->shape == TILE_SHAPE_NULL) continue;
|
||||
|
||||
const float_t *corners = CHUNK_RAMP_CORNERS[tile->shape];
|
||||
const float_t fz = (float_t)tile->z;
|
||||
assetChunkAppendTileQuad(
|
||||
verts, &vertCount, x, y,
|
||||
(fz + corners[0]) * WORLD_LAYER_HEIGHT,
|
||||
(fz + corners[1]) * WORLD_LAYER_HEIGHT,
|
||||
(fz + corners[2]) * WORLD_LAYER_HEIGHT,
|
||||
(fz + corners[3]) * WORLD_LAYER_HEIGHT
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
assertNull(loading->loading.chunk.data, "Data already defined?");
|
||||
assertTrue(vertCount > 0, "Terrain build called with no terrain tiles.");
|
||||
|
||||
assetfile_t *file = &loading->loading.chunk.file;
|
||||
assetLoaderErrorChain(loading,
|
||||
assetFileInit(file, loading->entry->name, NULL, NULL)
|
||||
out->vertices = verts;
|
||||
errorret_t ret = meshInit(
|
||||
&out->mesh, MESH_PRIMITIVE_TYPE_TRIANGLES, (int32_t)vertCount, verts
|
||||
);
|
||||
if(errorIsNotOk(ret)) {
|
||||
memoryFree(out->vertices);
|
||||
out->vertices = NULL;
|
||||
errorChain(ret);
|
||||
}
|
||||
out->meshInitialized = true;
|
||||
|
||||
uint8_t *data = memoryAllocate(file->size);
|
||||
assetLoaderErrorChain(loading, assetFileOpen(file));
|
||||
assetLoaderErrorChain(loading, assetFileRead(file, data, file->size));
|
||||
assetLoaderErrorChain(loading, assetFileClose(file));
|
||||
assetLoaderErrorChain(loading, assetFileDispose(file));
|
||||
assertTrue(
|
||||
file->lastRead == file->size,
|
||||
"Failed to read entire chunk file."
|
||||
);
|
||||
ret = meshFlush(&out->mesh, 0, (int32_t)vertCount);
|
||||
if(errorIsNotOk(ret)) {
|
||||
meshDispose(&out->mesh);
|
||||
out->meshInitialized = false;
|
||||
memoryFree(out->vertices);
|
||||
out->vertices = NULL;
|
||||
errorChain(ret);
|
||||
}
|
||||
|
||||
#if defined(DUSK_OPENGL) && !defined(DUSK_OPENGL_LEGACY)
|
||||
memoryFree(out->vertices);
|
||||
out->vertices = NULL;
|
||||
#endif
|
||||
|
||||
loading->loading.chunk.data = data;
|
||||
loading->loading.chunk.state = ASSET_CHUNK_LOADING_STATE_PARSE;
|
||||
loading->entry->state = ASSET_ENTRY_STATE_PENDING_SYNC;
|
||||
errorOk();
|
||||
}
|
||||
|
||||
@@ -55,8 +298,8 @@ errorret_t assetChunkLoaderSync(assetloading_t *loading) {
|
||||
|
||||
switch(loading->loading.chunk.state) {
|
||||
case ASSET_CHUNK_LOADING_STATE_INITIAL:
|
||||
loading->loading.chunk.state = ASSET_CHUNK_LOADING_STATE_READ_FILE;
|
||||
loading->entry->state = ASSET_ENTRY_STATE_PENDING_ASYNC;
|
||||
loading->loading.chunk.state = ASSET_CHUNK_LOADING_STATE_PARSE;
|
||||
loading->entry->state = ASSET_ENTRY_STATE_PENDING_SYNC;
|
||||
errorOk();
|
||||
|
||||
case ASSET_CHUNK_LOADING_STATE_PARSE:
|
||||
@@ -69,9 +312,7 @@ errorret_t assetChunkLoaderSync(assetloading_t *loading) {
|
||||
out->modelEntries[m] = assetLock(
|
||||
out->modelNames[m], ASSET_LOADER_TYPE_MODEL, NULL
|
||||
);
|
||||
assertNotNull(
|
||||
out->modelEntries[m], "Failed to lock model."
|
||||
);
|
||||
assertNotNull(out->modelEntries[m], "Failed to lock model.");
|
||||
loading->entry->state = ASSET_ENTRY_STATE_PENDING_SYNC;
|
||||
errorOk();
|
||||
}
|
||||
@@ -93,126 +334,103 @@ errorret_t assetChunkLoaderSync(assetloading_t *loading) {
|
||||
errorOk();
|
||||
}
|
||||
|
||||
uint8_t *data = loading->loading.chunk.data;
|
||||
assertNotNull(data, "Chunk data should have been loaded by now.");
|
||||
|
||||
if(data[0] != 'D' || data[1] != 'C' || data[2] != 'F') {
|
||||
memoryFree(data);
|
||||
assetLoaderErrorThrow(loading, "Invalid chunk file header");
|
||||
}
|
||||
|
||||
uint32_t version = endianLittleToHost32(*(uint32_t *)(data + 4));
|
||||
if(version != ASSET_CHUNK_FILE_VERSION) {
|
||||
memoryFree(data);
|
||||
// --- PARSE: lock+require the chunk's own JSON as a sub-asset, exactly
|
||||
// like assetmodelloader.c's ASSET_MODEL_LOADING_STATE_LOCK_ASSETS does
|
||||
// for its model descriptor, then read everything out of it before
|
||||
// unlocking (the yyjson_doc/vals only stay valid while jsonEntry does).
|
||||
char_t jsonKey[ASSET_FILE_NAME_MAX];
|
||||
stringFormat(jsonKey, sizeof(jsonKey), "json:%s", loading->entry->name);
|
||||
assetloaderinput_t jsonInput;
|
||||
memoryZero(&jsonInput, sizeof(jsonInput));
|
||||
stringCopy(
|
||||
jsonInput.json.path, loading->entry->name, ASSET_FILE_NAME_MAX
|
||||
);
|
||||
assetentry_t *jsonEntry =
|
||||
assetLock(jsonKey, ASSET_LOADER_TYPE_JSON, &jsonInput);
|
||||
errorret_t jsonRet = assetRequireLoaded(jsonEntry);
|
||||
if(errorIsNotOk(jsonRet)) {
|
||||
assetUnlockEntry(jsonEntry);
|
||||
assetLoaderErrorThrow(
|
||||
loading, "Unsupported chunk file version %u", version
|
||||
loading, "Failed to load chunk JSON: %s", loading->entry->name
|
||||
);
|
||||
}
|
||||
|
||||
size_t offset = 8;
|
||||
yyjson_val *root = yyjson_doc_get_root(jsonEntry->data.json);
|
||||
|
||||
size_t tileSize = CHUNK_TILE_COUNT * sizeof(tile_t);
|
||||
out->tiles = memoryAllocate(tileSize);
|
||||
memoryCopy(out->tiles, data + offset, tileSize);
|
||||
offset += tileSize;
|
||||
tile_t tiles[CHUNK_TILE_COUNT];
|
||||
assetChunkParseTiles(root, tiles);
|
||||
out->hasTerrain = assetChunkTilesHaveTerrain(tiles);
|
||||
|
||||
for(size_t t = 0; t < CHUNK_TILE_COUNT; t++) {
|
||||
uint32_t *shape = (uint32_t *)&out->tiles[t].shape;
|
||||
*shape = endianLittleToHost32(*shape);
|
||||
}
|
||||
uint8_t meshIndex = out->hasTerrain ? 1 : 0;
|
||||
assetChunkParseMeshes(root, out, &meshIndex);
|
||||
out->meshCount = meshIndex;
|
||||
|
||||
out->meshCount = data[offset];
|
||||
offset += sizeof(uint8_t);
|
||||
assertTrue(
|
||||
out->meshCount <= CHUNK_MESH_COUNT_MAX,
|
||||
"Chunk mesh count exceeds maximum."
|
||||
);
|
||||
assetChunkParseEntities(root, out);
|
||||
assetChunkParseAreas(root, out);
|
||||
|
||||
for(uint8_t m = 0; m < out->meshCount; m++) {
|
||||
uint8_t nameLen = 0;
|
||||
while(
|
||||
data[offset + nameLen] != '\0' &&
|
||||
nameLen < CHUNK_MESH_NAME_MAX - 1
|
||||
) {
|
||||
nameLen++;
|
||||
}
|
||||
memoryCopy(out->modelNames[m], data + offset, nameLen);
|
||||
out->modelNames[m][nameLen] = '\0';
|
||||
offset += nameLen + 1;
|
||||
assetUnlockEntry(jsonEntry);
|
||||
|
||||
memoryCopy(out->meshOffsets[m], data + offset, sizeof(vec3));
|
||||
offset += sizeof(vec3);
|
||||
out->meshOffsets[m][0] = endianLittleToHostFloat(out->meshOffsets[m][0]);
|
||||
out->meshOffsets[m][1] = endianLittleToHostFloat(out->meshOffsets[m][1]);
|
||||
out->meshOffsets[m][2] = endianLittleToHostFloat(out->meshOffsets[m][2]);
|
||||
}
|
||||
out->tiles = memoryAllocate(CHUNK_TILE_COUNT * sizeof(tile_t));
|
||||
memoryCopy(out->tiles, tiles, CHUNK_TILE_COUNT * sizeof(tile_t));
|
||||
|
||||
out->entitySpawnCount = data[offset];
|
||||
offset += sizeof(uint8_t);
|
||||
assertTrue(
|
||||
out->entitySpawnCount <= CHUNK_ENTITY_SPAWN_COUNT_MAX,
|
||||
"Chunk entity spawn count exceeds maximum."
|
||||
);
|
||||
|
||||
for(uint8_t s = 0; s < out->entitySpawnCount; s++) {
|
||||
chunkentityspawn_t *spawn = &out->entitySpawns[s];
|
||||
spawn->kind = (chunkentityspawnkind_t)data[offset];
|
||||
offset += sizeof(uint8_t);
|
||||
|
||||
uint16_t a;
|
||||
memoryCopy(&a, data + offset, sizeof(uint16_t));
|
||||
a = endianLittleToHost16(a);
|
||||
offset += sizeof(uint16_t);
|
||||
|
||||
uint8_t b = data[offset];
|
||||
offset += sizeof(uint8_t);
|
||||
|
||||
if(spawn->kind == CHUNK_ENTITY_SPAWN_KIND_ITEM) {
|
||||
spawn->globalId = 0;
|
||||
spawn->itemId = a;
|
||||
spawn->itemQuantity = b;
|
||||
} else {
|
||||
spawn->globalId = a;
|
||||
spawn->itemId = 0;
|
||||
spawn->itemQuantity = 0;
|
||||
// Terrain: build the mesh, then wrap it in synthetic (non-cache,
|
||||
// non-refcounted) mesh/model entries so modelEntries[0] behaves exactly
|
||||
// like a real file-backed model entry for every downstream consumer -
|
||||
// see the header's doc comment on hasTerrain/terrainMeshEntry.
|
||||
if(out->hasTerrain) {
|
||||
assetmeshoutput_t terrainMesh;
|
||||
memoryZero(&terrainMesh, sizeof(terrainMesh));
|
||||
errorret_t terrainRet = assetChunkBuildTerrain(out->tiles, &terrainMesh);
|
||||
if(errorIsNotOk(terrainRet)) {
|
||||
memoryFree(out->tiles);
|
||||
out->tiles = NULL;
|
||||
assetLoaderErrorThrow(
|
||||
loading, "Failed to build chunk terrain mesh: %s",
|
||||
loading->entry->name
|
||||
);
|
||||
}
|
||||
|
||||
spawn->position = worldPosReadLE(data, &offset);
|
||||
assetloaderinput_t texInput = { .texture = TEXTURE_FORMAT_RGBA };
|
||||
assetentry_t *texEntry = assetLock(
|
||||
ASSET_CHUNK_TERRAIN_TEXTURE, ASSET_LOADER_TYPE_TEXTURE, &texInput
|
||||
);
|
||||
errorret_t texRet = assetRequireLoaded(texEntry);
|
||||
if(errorIsNotOk(texRet)) {
|
||||
assetUnlockEntry(texEntry);
|
||||
meshDispose(&terrainMesh.mesh);
|
||||
memoryFree(out->tiles);
|
||||
out->tiles = NULL;
|
||||
assetLoaderErrorThrow(
|
||||
loading, "Failed to load chunk terrain texture: %s",
|
||||
loading->entry->name
|
||||
);
|
||||
}
|
||||
out->terrainTexEntry = texEntry;
|
||||
|
||||
out->terrainMeshEntry = memoryAllocate(sizeof(assetentry_t));
|
||||
memoryZero(out->terrainMeshEntry, sizeof(assetentry_t));
|
||||
out->terrainMeshEntry->type = ASSET_LOADER_TYPE_MESH;
|
||||
out->terrainMeshEntry->state = ASSET_ENTRY_STATE_LOADED;
|
||||
out->terrainMeshEntry->data.mesh = terrainMesh;
|
||||
|
||||
out->terrainModelEntry = memoryAllocate(sizeof(assetentry_t));
|
||||
memoryZero(out->terrainModelEntry, sizeof(assetentry_t));
|
||||
out->terrainModelEntry->type = ASSET_LOADER_TYPE_MODEL;
|
||||
out->terrainModelEntry->state = ASSET_ENTRY_STATE_LOADED;
|
||||
out->terrainModelEntry->data.model.meshEntry = out->terrainMeshEntry;
|
||||
out->terrainModelEntry->data.model.texEntry = out->terrainTexEntry;
|
||||
out->terrainModelEntry->data.model.color = COLOR_WHITE;
|
||||
|
||||
out->modelEntries[0] = out->terrainModelEntry;
|
||||
}
|
||||
|
||||
out->areaSpawnCount = data[offset];
|
||||
offset += sizeof(uint8_t);
|
||||
assertTrue(
|
||||
out->areaSpawnCount <= CHUNK_AREA_COUNT_MAX,
|
||||
"Chunk area spawn count exceeds maximum."
|
||||
);
|
||||
|
||||
for(uint8_t s = 0; s < out->areaSpawnCount; s++) {
|
||||
chunkareaspawn_t *area = &out->areaSpawns[s];
|
||||
area->min = worldPosReadLE(data, &offset);
|
||||
area->max = worldPosReadLE(data, &offset);
|
||||
|
||||
uint16_t callbackId;
|
||||
memoryCopy(&callbackId, data + offset, sizeof(uint16_t));
|
||||
area->callbackId = endianLittleToHost16(callbackId);
|
||||
offset += sizeof(uint16_t);
|
||||
|
||||
area->notify = data[offset];
|
||||
offset += sizeof(uint8_t);
|
||||
area->trigger = data[offset];
|
||||
offset += sizeof(uint8_t);
|
||||
}
|
||||
|
||||
memoryFree(data);
|
||||
loading->loading.chunk.data = NULL;
|
||||
|
||||
if(out->meshCount == 0) {
|
||||
loading->entry->state = ASSET_ENTRY_STATE_LOADED;
|
||||
errorOk();
|
||||
}
|
||||
|
||||
loading->loading.chunk.state = ASSET_CHUNK_LOADING_STATE_LOAD_MODELS;
|
||||
loading->loading.chunk.modelIndex = 0;
|
||||
loading->loading.chunk.modelIndex = out->hasTerrain ? 1 : 0;
|
||||
loading->entry->state = ASSET_ENTRY_STATE_PENDING_SYNC;
|
||||
errorOk();
|
||||
}
|
||||
@@ -231,8 +449,36 @@ errorret_t assetChunkDispose(assetentry_t *entry) {
|
||||
|
||||
for(uint8_t m = 0; m < out->meshCount; m++) {
|
||||
if(out->modelEntries[m] == NULL) continue;
|
||||
if(out->hasTerrain && m == 0) continue; // synthetic - freed below.
|
||||
assetUnlockEntry(out->modelEntries[m]);
|
||||
out->modelEntries[m] = NULL;
|
||||
}
|
||||
|
||||
if(out->hasTerrain) {
|
||||
if(out->terrainMeshEntry != NULL) {
|
||||
assetmeshoutput_t *meshOut = &out->terrainMeshEntry->data.mesh;
|
||||
if(meshOut->meshInitialized) {
|
||||
meshDispose(&meshOut->mesh);
|
||||
meshOut->meshInitialized = false;
|
||||
}
|
||||
if(meshOut->vertices != NULL) {
|
||||
memoryFree(meshOut->vertices);
|
||||
meshOut->vertices = NULL;
|
||||
}
|
||||
memoryFree(out->terrainMeshEntry);
|
||||
out->terrainMeshEntry = NULL;
|
||||
}
|
||||
if(out->terrainModelEntry != NULL) {
|
||||
memoryFree(out->terrainModelEntry);
|
||||
out->terrainModelEntry = NULL;
|
||||
}
|
||||
if(out->terrainTexEntry != NULL) {
|
||||
assetUnlockEntry(out->terrainTexEntry);
|
||||
out->terrainTexEntry = NULL;
|
||||
}
|
||||
out->modelEntries[0] = NULL;
|
||||
out->hasTerrain = false;
|
||||
}
|
||||
|
||||
errorOk();
|
||||
}
|
||||
@@ -9,8 +9,6 @@
|
||||
#include "asset/assetfile.h"
|
||||
#include "rpg/overworld/chunk.h"
|
||||
|
||||
#define ASSET_CHUNK_FILE_VERSION 5
|
||||
|
||||
typedef struct assetloading_s assetloading_t;
|
||||
typedef struct assetentry_s assetentry_t;
|
||||
|
||||
@@ -20,16 +18,17 @@ typedef struct {
|
||||
|
||||
typedef enum {
|
||||
ASSET_CHUNK_LOADING_STATE_INITIAL,
|
||||
ASSET_CHUNK_LOADING_STATE_READ_FILE,
|
||||
ASSET_CHUNK_LOADING_STATE_PARSE,
|
||||
ASSET_CHUNK_LOADING_STATE_LOAD_MODELS,
|
||||
ASSET_CHUNK_LOADING_STATE_DONE
|
||||
} assetchunkloadingstate_t;
|
||||
|
||||
typedef struct {
|
||||
assetfile_t file;
|
||||
assetchunkloadingstate_t state;
|
||||
uint8_t *data;
|
||||
|
||||
// Index into assetchunkoutput_t.modelNames/modelEntries the external
|
||||
// (non-terrain) model polling loop has reached - see
|
||||
// ASSET_CHUNK_LOADING_STATE_LOAD_MODELS.
|
||||
uint8_t modelIndex;
|
||||
} assetchunkloaderloading_t;
|
||||
|
||||
@@ -61,6 +60,27 @@ typedef struct {
|
||||
vec3 meshOffsets[CHUNK_MESH_COUNT_MAX];
|
||||
assetentry_t *modelEntries[CHUNK_MESH_COUNT_MAX];
|
||||
|
||||
// Terrain mesh generated at load time from the tile grid (no baked
|
||||
// .dmf/.json - see assetChunkBuildTerrain in assetchunkloader.c). NULL
|
||||
// (with hasTerrain false) for a chunk with no non-null tiles, in which
|
||||
// case modelEntries[0] (if meshCount > 0) is the first external mesh
|
||||
// instead - matches the old baked pipeline's "only write a terrain
|
||||
// model if it has vertices" behavior.
|
||||
//
|
||||
// terrainMeshEntry/terrainModelEntry are heap-allocated, plain
|
||||
// assetentry_t values that are never passed to assetLock/assetGetEntry/
|
||||
// assetUnlockEntry (only a real, name-keyed, ref-counted entry may be)
|
||||
// - they exist purely so modelEntries[0] can point at something with
|
||||
// the same ->state/->data.model/->data.mesh.mesh shape every other
|
||||
// model/mesh entry has, so chunk.c/map.c/sceneoverworld.c don't need to
|
||||
// know terrain isn't file-backed. Freed directly (not assetUnlockEntry)
|
||||
// in assetChunkDispose. terrainTexEntry is a real, ref-counted texture
|
||||
// entry (the shared "tiles.png") and must be assetUnlockEntry'd there.
|
||||
bool_t hasTerrain;
|
||||
assetentry_t *terrainMeshEntry;
|
||||
assetentry_t *terrainModelEntry;
|
||||
assetentry_t *terrainTexEntry;
|
||||
|
||||
uint8_t entitySpawnCount;
|
||||
chunkentityspawn_t entitySpawns[CHUNK_ENTITY_SPAWN_COUNT_MAX];
|
||||
|
||||
@@ -69,9 +89,10 @@ typedef struct {
|
||||
} assetchunkoutput_t;
|
||||
|
||||
/**
|
||||
* Asynchronous loader for chunk assets. Reads the raw DCF file bytes into
|
||||
* the loading buffer so the sync phase can parse without blocking the
|
||||
* main thread on I/O.
|
||||
* Async loader stub for chunk assets. Chunk loading is performed entirely
|
||||
* on the main thread (it delegates to the JSON asset loader and to
|
||||
* meshInit/meshFlush, both main-thread-only); this callback is never
|
||||
* reached.
|
||||
*
|
||||
* @param loading Loading information for the asset being loaded.
|
||||
* @return Error code indicating success or failure of the load operation.
|
||||
@@ -79,9 +100,11 @@ typedef struct {
|
||||
errorret_t assetChunkLoaderAsync(assetloading_t *loading);
|
||||
|
||||
/**
|
||||
* Synchronous loader for chunk assets. Validates the DCF binary previously
|
||||
* read by the async phase and populates the output assetchunkoutput_t with
|
||||
* tile data and model paths.
|
||||
* Synchronous loader for chunk assets. Locks the chunk's JSON descriptor
|
||||
* as a sub-asset, parses tiles/external mesh references/entity spawns/
|
||||
* area spawns, generates the terrain mesh directly from the tile grid,
|
||||
* and locks/waits for every referenced model (and the terrain's shared
|
||||
* tileset texture) to finish loading.
|
||||
*
|
||||
* @param loading Loading information for the asset being loaded.
|
||||
* @return Error code indicating success or failure of the load operation.
|
||||
|
||||
@@ -76,20 +76,13 @@ size_t assetCutsceneComputePoolSize(yyjson_val *itemsArr) {
|
||||
return size;
|
||||
}
|
||||
|
||||
void assetCutsceneFreeParsed(assetcutsceneoutput_t *out) {
|
||||
if(out->items != NULL) {
|
||||
memoryFree(out->items);
|
||||
out->items = NULL;
|
||||
}
|
||||
if(out->pool != NULL) {
|
||||
memoryFree(out->pool);
|
||||
out->pool = NULL;
|
||||
}
|
||||
if(out->doc != NULL) {
|
||||
yyjson_doc_free(out->doc);
|
||||
out->doc = NULL;
|
||||
}
|
||||
}
|
||||
// Raw file-read scratch space - fixed-size (ASSET_CUTSCENE_FILE_SIZE_MAX is
|
||||
// already a hard cap below) rather than malloc'd per load. Safe to share:
|
||||
// ASSET only ever runs one async load at a time on its single load thread
|
||||
// (see assetUpdateAsync), and yyjson_read copies everything it needs out
|
||||
// of this buffer into the doc before this function returns, so it's free
|
||||
// to be overwritten by the next load.
|
||||
static uint8_t CUTSCENE_FILE_BUFFER[ASSET_CUTSCENE_FILE_SIZE_MAX];
|
||||
|
||||
errorret_t assetCutsceneLoaderAsync(assetloading_t *loading) {
|
||||
assertNotNull(loading, "Loading cannot be NULL");
|
||||
@@ -101,8 +94,6 @@ errorret_t assetCutsceneLoaderAsync(assetloading_t *loading) {
|
||||
errorOk();
|
||||
}
|
||||
|
||||
assertNull(loading->loading.cutscene.buffer, "Buffer already defined?");
|
||||
|
||||
assetfile_t *file = &loading->loading.cutscene.file;
|
||||
assetLoaderErrorChain(loading,
|
||||
assetFileInit(file, loading->entry->name, NULL, NULL)
|
||||
@@ -115,9 +106,10 @@ errorret_t assetCutsceneLoaderAsync(assetloading_t *loading) {
|
||||
}
|
||||
|
||||
size_t fileSize = (size_t)file->size;
|
||||
uint8_t *buffer = memoryAllocate(fileSize);
|
||||
assetLoaderErrorChain(loading, assetFileOpen(file));
|
||||
assetLoaderErrorChain(loading, assetFileRead(file, buffer, fileSize));
|
||||
assetLoaderErrorChain(
|
||||
loading, assetFileRead(file, CUTSCENE_FILE_BUFFER, fileSize)
|
||||
);
|
||||
assertTrue(
|
||||
file->lastRead == file->size,
|
||||
"Failed to read entire cutscene file."
|
||||
@@ -125,8 +117,85 @@ errorret_t assetCutsceneLoaderAsync(assetloading_t *loading) {
|
||||
assetLoaderErrorChain(loading, assetFileClose(file));
|
||||
assetLoaderErrorChain(loading, assetFileDispose(file));
|
||||
|
||||
loading->loading.cutscene.buffer = buffer;
|
||||
loading->loading.cutscene.size = fileSize;
|
||||
// Parsing is pure CPU work with no main-thread dependency (every item
|
||||
// type's load callback just parses fields - see cutsceneCutsceneLoad's
|
||||
// doc comment for how CUTSCENE items avoid needing one), so it happens
|
||||
// right here instead of bouncing to the sync phase.
|
||||
yyjson_doc *doc = yyjson_read(
|
||||
(char *)CUTSCENE_FILE_BUFFER, fileSize,
|
||||
YYJSON_READ_ALLOW_COMMENTS | YYJSON_READ_ALLOW_TRAILING_COMMAS
|
||||
);
|
||||
if(doc == NULL) {
|
||||
assetLoaderErrorThrow(loading, "Failed to parse cutscene JSON");
|
||||
}
|
||||
|
||||
yyjson_val *root = yyjson_doc_get_root(doc);
|
||||
yyjson_val *itemsArr = yyjson_obj_get(root, "items");
|
||||
if(!yyjson_is_arr(itemsArr)) {
|
||||
yyjson_doc_free(doc);
|
||||
assetLoaderErrorThrow(loading, "Cutscene JSON is missing an 'items' array");
|
||||
}
|
||||
|
||||
size_t itemCount = yyjson_arr_size(itemsArr);
|
||||
if(itemCount > CUTSCENE_LOADED_ITEMS_MAX) {
|
||||
yyjson_doc_free(doc);
|
||||
assetLoaderErrorThrow(
|
||||
loading, "Cutscene has more than CUTSCENE_LOADED_ITEMS_MAX items"
|
||||
);
|
||||
}
|
||||
|
||||
cutscenepause_t pause = CUTSCENE_PAUSE_DEFAULT;
|
||||
yyjson_val *pauseArr = yyjson_obj_get(root, "pause");
|
||||
if(yyjson_is_arr(pauseArr)) {
|
||||
if(!cutsceneJsonParsePauseFlags(pauseArr, &pause)) {
|
||||
yyjson_doc_free(doc);
|
||||
assetLoaderErrorThrow(
|
||||
loading, "Cutscene JSON has an invalid 'pause' flag"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
size_t poolSize = assetCutsceneComputePoolSize(itemsArr);
|
||||
if(poolSize > CUTSCENE_LOADED_POOL_SIZE_MAX) {
|
||||
yyjson_doc_free(doc);
|
||||
assetLoaderErrorThrow(
|
||||
loading, "Cutscene needs more pool space than CUTSCENE_LOADED_POOL_SIZE_MAX"
|
||||
);
|
||||
}
|
||||
|
||||
// Everything structural has validated by this point, so it's safe to
|
||||
// start overwriting the shared CUTSCENE_LOADED_ITEMS/POOL buffers - a
|
||||
// per-item parse failure past this point still leaves them partially
|
||||
// overwritten, but that's fine: any load failure here already sends the
|
||||
// game into the fatal-error overlay (see cutsceneSystemLoad/
|
||||
// cutsceneCutsceneResolve), so nothing keeps running against stale data.
|
||||
memoryZero(CUTSCENE_LOADED_ITEMS, itemCount * sizeof(cutsceneitem_t));
|
||||
|
||||
size_t poolOffset = 0;
|
||||
yyjson_arr_iter itemIter = yyjson_arr_iter_with(itemsArr);
|
||||
yyjson_val *itemVal;
|
||||
uint8_t index = 0;
|
||||
while((itemVal = yyjson_arr_iter_next(&itemIter)) != NULL) {
|
||||
errorret_t itemResult = assetCutsceneParseItem(
|
||||
loading, itemVal, &CUTSCENE_LOADED_ITEMS[index],
|
||||
CUTSCENE_LOADED_POOL, &poolOffset, index
|
||||
);
|
||||
if(errorIsNotOk(itemResult)) {
|
||||
yyjson_doc_free(doc);
|
||||
errorChain(itemResult);
|
||||
}
|
||||
index++;
|
||||
}
|
||||
|
||||
// Takes ownership of doc - marker/cutscene-reference name fields point
|
||||
// directly into it (see cutsceneCutsceneRefLoad/cutsceneMarkerLoad), so
|
||||
// it must outlive this load, replacing whatever the previously loaded
|
||||
// cutscene left behind.
|
||||
cutsceneLoadedSetDoc(doc);
|
||||
CUTSCENE_LOADED_SCENE.itemCount = (uint8_t)itemCount;
|
||||
CUTSCENE_LOADED_SCENE.pause = pause;
|
||||
CUTSCENE_LOADED_SCENE.dataSize = 0;
|
||||
|
||||
loading->loading.cutscene.state = ASSET_CUTSCENE_LOADING_STATE_PARSE;
|
||||
loading->entry->state = ASSET_ENTRY_STATE_PENDING_SYNC;
|
||||
errorOk();
|
||||
@@ -143,73 +212,15 @@ errorret_t assetCutsceneLoaderSync(assetloading_t *loading) {
|
||||
errorOk();
|
||||
}
|
||||
|
||||
assetcutsceneoutput_t *out = &loading->entry->data.cutscene;
|
||||
uint8_t *buffer = loading->loading.cutscene.buffer;
|
||||
assertNotNull(buffer, "Cutscene data should have been loaded by now.");
|
||||
size_t bufferSize = loading->loading.cutscene.size;
|
||||
|
||||
yyjson_doc *doc = yyjson_read(
|
||||
(char *)buffer, bufferSize,
|
||||
YYJSON_READ_ALLOW_COMMENTS | YYJSON_READ_ALLOW_TRAILING_COMMAS
|
||||
// Everything else already happened in the async phase - see
|
||||
// assetCutsceneLoaderAsync. This flip still has to happen from here
|
||||
// rather than the async phase setting LOADED directly, since
|
||||
// assetUpdate() only fires an entry's onLoaded callback for entries
|
||||
// that finish via this sync path.
|
||||
assertTrue(
|
||||
loading->loading.cutscene.state == ASSET_CUTSCENE_LOADING_STATE_PARSE,
|
||||
"Unexpected cutscene loading state."
|
||||
);
|
||||
memoryFree(buffer);
|
||||
loading->loading.cutscene.buffer = NULL;
|
||||
|
||||
if(doc == NULL) {
|
||||
assetLoaderErrorThrow(loading, "Failed to parse cutscene JSON");
|
||||
}
|
||||
out->doc = doc;
|
||||
|
||||
yyjson_val *root = yyjson_doc_get_root(doc);
|
||||
yyjson_val *itemsArr = yyjson_obj_get(root, "items");
|
||||
if(!yyjson_is_arr(itemsArr)) {
|
||||
assetCutsceneFreeParsed(out);
|
||||
assetLoaderErrorThrow(loading, "Cutscene JSON is missing an 'items' array");
|
||||
}
|
||||
|
||||
size_t itemCount = yyjson_arr_size(itemsArr);
|
||||
if(itemCount > UINT8_MAX) {
|
||||
assetCutsceneFreeParsed(out);
|
||||
assetLoaderErrorThrow(loading, "Cutscene has more than 255 items");
|
||||
}
|
||||
|
||||
cutscenepause_t pause = CUTSCENE_PAUSE_DEFAULT;
|
||||
yyjson_val *pauseArr = yyjson_obj_get(root, "pause");
|
||||
if(yyjson_is_arr(pauseArr)) {
|
||||
if(!cutsceneJsonParsePauseFlags(pauseArr, &pause)) {
|
||||
assetCutsceneFreeParsed(out);
|
||||
assetLoaderErrorThrow(
|
||||
loading, "Cutscene JSON has an invalid 'pause' flag"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
out->items = memoryAllocate(itemCount * sizeof(cutsceneitem_t));
|
||||
memoryZero(out->items, itemCount * sizeof(cutsceneitem_t));
|
||||
|
||||
size_t poolSize = assetCutsceneComputePoolSize(itemsArr);
|
||||
out->pool = poolSize > 0 ? memoryAllocate(poolSize) : NULL;
|
||||
|
||||
size_t poolOffset = 0;
|
||||
yyjson_arr_iter itemIter = yyjson_arr_iter_with(itemsArr);
|
||||
yyjson_val *itemVal;
|
||||
uint8_t index = 0;
|
||||
while((itemVal = yyjson_arr_iter_next(&itemIter)) != NULL) {
|
||||
errorret_t itemResult = assetCutsceneParseItem(
|
||||
loading, itemVal, &out->items[index], out->pool, &poolOffset, index
|
||||
);
|
||||
if(errorIsNotOk(itemResult)) {
|
||||
assetCutsceneFreeParsed(out);
|
||||
errorChain(itemResult);
|
||||
}
|
||||
index++;
|
||||
}
|
||||
|
||||
out->cutscene.items = out->items;
|
||||
out->cutscene.itemCount = (uint8_t)itemCount;
|
||||
out->cutscene.pause = pause;
|
||||
out->cutscene.dataSize = 0;
|
||||
|
||||
loading->entry->state = ASSET_ENTRY_STATE_LOADED;
|
||||
errorOk();
|
||||
}
|
||||
@@ -219,7 +230,10 @@ errorret_t assetCutsceneDispose(assetentry_t *entry) {
|
||||
assertTrue(entry->type == ASSET_LOADER_TYPE_CUTSCENE, "Invalid type.");
|
||||
assertIsMainThread("Must be called from the main thread.");
|
||||
|
||||
assetCutsceneFreeParsed(&entry->data.cutscene);
|
||||
// Nothing to free here - a loaded cutscene's data lives in the fixed,
|
||||
// shared CUTSCENE_LOADED_SCENE/ITEMS/POOL globals (see cutscenesystem.h),
|
||||
// not per-entry storage; this entry only ever drove the read+parse
|
||||
// pipeline into them.
|
||||
|
||||
errorOk();
|
||||
}
|
||||
@@ -8,6 +8,7 @@
|
||||
#pragma once
|
||||
#include "asset/assetfile.h"
|
||||
#include "rpg/cutscene/cutscene.h"
|
||||
#include "rpg/cutscene/cutscenesystem.h"
|
||||
#include "rpg/cutscene/item/cutsceneitem.h"
|
||||
#include "rpg/cutscene/item/json/cutscenejsonpool.h"
|
||||
#include "yyjson.h"
|
||||
@@ -30,15 +31,16 @@ typedef enum {
|
||||
typedef struct {
|
||||
assetfile_t file;
|
||||
assetcutsceneloadingstate_t state;
|
||||
uint8_t *buffer;
|
||||
size_t size;
|
||||
} assetcutsceneloaderloading_t;
|
||||
|
||||
typedef struct {
|
||||
cutscene_t cutscene;
|
||||
cutsceneitem_t *items;
|
||||
uint8_t *pool;
|
||||
yyjson_doc *doc;
|
||||
// Nothing - a loaded cutscene's data lives entirely in the fixed,
|
||||
// shared CUTSCENE_LOADED_SCENE/ITEMS/POOL globals (see cutscenesystem.h)
|
||||
// that assetCutsceneLoaderAsync parses directly into, not per-entry
|
||||
// storage. This entry only ever exists to drive the read+parse
|
||||
// pipeline, and is unlocked (see cutsceneSystemLoad/
|
||||
// cutsceneCutsceneResolve) the instant that finishes.
|
||||
uint8_t unused;
|
||||
} assetcutsceneoutput_t;
|
||||
|
||||
/**
|
||||
@@ -69,19 +71,15 @@ errorret_t assetCutsceneParseItem(
|
||||
const uint8_t index
|
||||
);
|
||||
|
||||
/**
|
||||
* Frees whatever of out->items/out->pool/out->doc is currently non-NULL
|
||||
* and clears them - shared by both the normal disposer and every parse
|
||||
* failure path's cleanup.
|
||||
*
|
||||
* @param out The output to free.
|
||||
*/
|
||||
void assetCutsceneFreeParsed(assetcutsceneoutput_t *out);
|
||||
|
||||
/**
|
||||
* Asynchronous loader for cutscene assets. Reads the raw JSONC file bytes
|
||||
* into the loading buffer so the sync phase can parse without blocking the
|
||||
* main thread on I/O.
|
||||
* and, in the same call, parses them directly into the fixed, shared
|
||||
* CUTSCENE_LOADED_ITEMS/CUTSCENE_LOADED_POOL buffers (see cutscenesystem.h)
|
||||
* - no heap allocation at all, since only one cutscene is ever resident.
|
||||
* None of that work touches the main thread (every item type's load
|
||||
* callback is pure parsing now; CUTSCENE items defer their nested asset
|
||||
* resolution to cutsceneCutsceneStart), so doing it all here keeps a large
|
||||
* cutscene from ever blocking a frame.
|
||||
*
|
||||
* @param loading Loading information for the asset being loaded.
|
||||
* @return Error code indicating success or failure of the load operation.
|
||||
@@ -89,8 +87,11 @@ void assetCutsceneFreeParsed(assetcutsceneoutput_t *out);
|
||||
errorret_t assetCutsceneLoaderAsync(assetloading_t *loading);
|
||||
|
||||
/**
|
||||
* Synchronous loader for cutscene assets. Parses the JSONC previously read
|
||||
* by the async phase into a heap-allocated cutsceneitem_t array + pool.
|
||||
* Synchronous loader for cutscene assets. All actual work already
|
||||
* happened in the async phase - this only flips the entry to LOADED,
|
||||
* which must happen through this sync callback (rather than the async
|
||||
* phase setting it directly) so assetUpdate()'s onLoaded dispatch, which
|
||||
* only fires for entries finishing via the sync path, still runs.
|
||||
*
|
||||
* @param loading Loading information for the asset being loaded.
|
||||
* @return Error code indicating success or failure of the load operation.
|
||||
|
||||
@@ -87,10 +87,10 @@ errorret_t audioStreamPcmSeek(audiostream_t *stream, const size_t frame) {
|
||||
|
||||
const size_t currentByte = (size_t) stream->pcm.file.position;
|
||||
if(targetByte < currentByte) {
|
||||
// Only a full rewind can move a read cursor earlier once it's already
|
||||
// advanced past a point - a compressed archive entry can't be decoded
|
||||
// backward. See this function's own doc comment for the performance
|
||||
// implications of a deep loopTo.
|
||||
// A rewind is needed to move the read cursor earlier once it's
|
||||
// already advanced past a point - assetFileRewind() takes the cheap
|
||||
// in-place seek path since every dusk.dsk entry is stored
|
||||
// uncompressed.
|
||||
errorChain(assetFileRewind(&stream->pcm.file));
|
||||
errorChain(assetFileRead(&stream->pcm.file, NULL, targetByte));
|
||||
} else if(targetByte > currentByte) {
|
||||
|
||||
@@ -63,11 +63,8 @@ size_t audioStreamPcmGetTotalFrames(const audiostream_t *stream);
|
||||
* (relative to the start of the PCM data - the same units as
|
||||
* audiostream_t's startFrame/loopStart/loopTo, once converted from
|
||||
* seconds). Seeking backward re-reads from the start of the underlying
|
||||
* asset file (see assetFileRewind()) since a compressed archive entry can
|
||||
* only be decoded forward - this makes a loop with a deep loopTo more
|
||||
* expensive to restart than one near the start, which is a real
|
||||
* performance caveat, not just a theoretical one, for anything backed by
|
||||
* a compressed (not stored) asset archive entry.
|
||||
* asset file (see assetFileRewind()), which is a cheap in-place seek
|
||||
* since every dusk.dsk entry is stored uncompressed.
|
||||
*
|
||||
* @param stream The audio stream to seek. Must be AUDIO_STREAM_TYPE_PCM.
|
||||
* @param frame Frame offset to seek to, relative to the start of the PCM
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#include "engine.h"
|
||||
#include "util/memory.h"
|
||||
#include "perf/perf.h"
|
||||
#include "time/time.h"
|
||||
#include "input/input.h"
|
||||
#include "locale/localemanager.h"
|
||||
@@ -36,6 +37,7 @@ errorret_t engineInit(const int32_t argc, const char_t **argv) {
|
||||
ENGINE.version = DUSK_VERSION;
|
||||
|
||||
// Init systems. Order is important.
|
||||
perfInit();
|
||||
timeInit();
|
||||
consoleInit();
|
||||
errorChain(systemInit());
|
||||
@@ -104,6 +106,9 @@ errorret_t engineDispose(void) {
|
||||
errorChain(displayDispose());
|
||||
errorChain(saveDispose());
|
||||
errorChain(assetDispose());
|
||||
perfDispose();
|
||||
|
||||
memoryCheckUnfreed();
|
||||
|
||||
errorOk();
|
||||
}
|
||||
@@ -6,5 +6,5 @@
|
||||
# Sources
|
||||
target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
||||
PUBLIC
|
||||
testbattle.c
|
||||
perf.c
|
||||
)
|
||||
@@ -0,0 +1,88 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "perf.h"
|
||||
#include "assert/assert.h"
|
||||
#include "util/memory.h"
|
||||
#include "console/console.h"
|
||||
|
||||
#if defined(DUSK_LINUX)
|
||||
#include <time.h>
|
||||
#elif defined(DUSK_PSP)
|
||||
#include <pspthreadman.h>
|
||||
#endif
|
||||
|
||||
perf_t PERF;
|
||||
|
||||
void perfInit(void) {
|
||||
assertIsMainThread("Must be called from the main thread.");
|
||||
memoryZero(&PERF, sizeof(perf_t));
|
||||
}
|
||||
|
||||
void perfDispose(void) {
|
||||
assertIsMainThread("Must be called from the main thread.");
|
||||
}
|
||||
|
||||
uint64_t perfGetTick(void) {
|
||||
assertIsMainThread("Must be called from the main thread.");
|
||||
|
||||
#if defined(DUSK_LINUX)
|
||||
// TEST - CLOCK_MONOTONIC via clock_gettime(), Linux desktop only for
|
||||
// now. Not a cross-platform answer yet (see perfGetTick's doc
|
||||
// comment in perf.h) - just something real to look at while that
|
||||
// gets settled. Returns nanoseconds since some unspecified starting
|
||||
// point, so only differences between two calls are meaningful.
|
||||
struct timespec ts;
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
return (uint64_t)ts.tv_sec * 1000000000ull + (uint64_t)ts.tv_nsec;
|
||||
#elif defined(DUSK_PSP)
|
||||
// TEST - sceKernelGetSystemTimeWide(), microseconds since boot at
|
||||
// ~1us resolution (the standard PSP homebrew idiom for elapsed-time
|
||||
// measurement - psprtc.h's sceRtcGetCurrentTick is for wall-clock
|
||||
// date/time instead, already used by timepsp.c for that purpose).
|
||||
// Scaled to nanoseconds to match every other platform's tick unit.
|
||||
return (uint64_t)sceKernelGetSystemTimeWide() * 1000ull;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void perfPushItem(
|
||||
const char_t *label, const char_t *file, const int32_t line
|
||||
) {
|
||||
assertIsMainThread("Must be called from the main thread.");
|
||||
assertNotNull(label, "Perf item label cannot be NULL.");
|
||||
assertNotNull(file, "Perf item file cannot be NULL.");
|
||||
assertTrue(PERF.stackSize < PERF_STACK_SIZE, "Perf stack overflow.");
|
||||
|
||||
PERF.stack[PERF.stackSize++] = (perfitem_t){
|
||||
.label = label,
|
||||
.file = file,
|
||||
.line = line,
|
||||
.tick = perfGetTick()
|
||||
};
|
||||
}
|
||||
|
||||
void perfPopItem(void) {
|
||||
assertIsMainThread("Must be called from the main thread.");
|
||||
assertTrue(PERF.stackSize > 0, "Perf stack underflow.");
|
||||
PERF.stackSize--;
|
||||
}
|
||||
|
||||
void perfReport(void) {
|
||||
assertIsMainThread("Must be called from the main thread.");
|
||||
|
||||
if(PERF.stackSize == 0) return;
|
||||
|
||||
const perfitem_t *item = &PERF.stack[PERF.stackSize - 1];
|
||||
uint64_t elapsedNs = perfGetTick() - item->tick;
|
||||
double_t elapsedMs = (double_t)elapsedNs / 1000000.0;
|
||||
consolePrint(
|
||||
"perf: %s (%s:%d, %.4fms)",
|
||||
item->label, item->file, item->line, elapsedMs
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "perfitem.h"
|
||||
|
||||
#define PERF_STACK_SIZE 256
|
||||
|
||||
typedef struct {
|
||||
perfitem_t stack[PERF_STACK_SIZE];
|
||||
uint32_t stackSize;
|
||||
} perf_t;
|
||||
|
||||
extern perf_t PERF;
|
||||
|
||||
/**
|
||||
* Initializes the perf system.
|
||||
*/
|
||||
void perfInit(void);
|
||||
|
||||
/**
|
||||
* Disposes/cleans up the perf system. Currently a no-op - here so
|
||||
* engine.c has a symmetric call to make once this needs real cleanup.
|
||||
*/
|
||||
void perfDispose(void);
|
||||
|
||||
/**
|
||||
* Returns a tick value representing "now", for measuring the duration
|
||||
* between a perfPush/perfPushItem and its matching perfPopItem. Always
|
||||
* nanoseconds since some unspecified starting point, on every platform
|
||||
* that implements it, so perfReport's ms conversion stays correct
|
||||
* everywhere without per-platform special-casing.
|
||||
*
|
||||
* PLACEHOLDER - currently only reads a real value on DUSK_LINUX desktop
|
||||
* builds (via clock_gettime(CLOCK_MONOTONIC)) and DUSK_PSP (via
|
||||
* sceKernelGetSystemTimeWide(), scaled from microseconds), as a test;
|
||||
* every other platform still gets a meaningless 0. A common,
|
||||
* cross-platform way of reading CPU cycles/time hasn't been settled on
|
||||
* yet - don't treat results as comparable across platforms until this is
|
||||
* replaced with a real per-platform implementation. Only the difference
|
||||
* between two calls is meaningful, never the raw value itself.
|
||||
*
|
||||
* @return A tick value, in nanoseconds. 0 on unimplemented platforms.
|
||||
*/
|
||||
uint64_t perfGetTick(void);
|
||||
|
||||
/**
|
||||
* Pushes a new item onto the perf stack, capturing the current tick (see
|
||||
* perfGetTick) as its start time. Prefer the perfPush() macro, which
|
||||
* supplies file/line automatically.
|
||||
*
|
||||
* @param label Short caller-supplied memo of what this item represents
|
||||
* (e.g. "frame start") - stored by pointer, not copied, so pass a
|
||||
* string literal or something that otherwise outlives the push.
|
||||
* @param file Source file the push originated from (e.g. __FILE__).
|
||||
* @param line Source line the push originated from (e.g. __LINE__).
|
||||
*/
|
||||
void perfPushItem(
|
||||
const char_t *label, const char_t *file, const int32_t line
|
||||
);
|
||||
|
||||
/**
|
||||
* Pops the most recently pushed perf item off the stack.
|
||||
*/
|
||||
void perfPopItem(void);
|
||||
|
||||
/**
|
||||
* Reports on the item currently at the top of the perf stack (the most
|
||||
* recently pushed one still awaiting its perfPopItem), if any.
|
||||
*/
|
||||
void perfReport(void);
|
||||
|
||||
/**
|
||||
* Pushes a new perf item onto the stack, tagged with the call site this
|
||||
* macro is expanded at.
|
||||
*
|
||||
* @param label Short memo of what this item represents (e.g. "frame
|
||||
* start") - see perfPushItem.
|
||||
*/
|
||||
#define perfPush(label) perfPushItem(label, __FILE__, __LINE__)
|
||||
|
||||
/**
|
||||
* Pops the most recently pushed perf item off the stack.
|
||||
*/
|
||||
#define perfPop() perfPopItem()
|
||||
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* 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 {
|
||||
const char_t *label;
|
||||
int32_t line;
|
||||
const char_t *file;
|
||||
uint64_t tick;
|
||||
} perfitem_t;
|
||||
@@ -10,6 +10,3 @@ target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
||||
battlefighter.c
|
||||
party.c
|
||||
)
|
||||
|
||||
# Subdirs
|
||||
add_subdirectory(testbattle)
|
||||
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* 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 enum {
|
||||
BATTLE_ABILITY_NULL,
|
||||
|
||||
BATTLE_ABILITY_FIRE,
|
||||
|
||||
BATTLE_ABILITY_COUNT
|
||||
} battleability_t;
|
||||
@@ -7,6 +7,9 @@
|
||||
|
||||
#pragma once
|
||||
#include "error/error.h"
|
||||
#include "battleability.h"
|
||||
|
||||
#define BATTLE_FIGHTER_ABILITY_COUNT_MAX 8
|
||||
|
||||
// An empty status means the slot in BATTLE.fighters is unused.
|
||||
typedef enum {
|
||||
@@ -55,6 +58,7 @@ typedef struct {
|
||||
uint16_t mpMax;
|
||||
|
||||
battlefighterstats_t stats;
|
||||
battleability_t abilities[BATTLE_FIGHTER_ABILITY_COUNT_MAX];
|
||||
} battlefighter_t;
|
||||
|
||||
/**
|
||||
|
||||
+18
-12
@@ -8,22 +8,25 @@
|
||||
#include "party.h"
|
||||
#include "assert/assert.h"
|
||||
#include "util/memory.h"
|
||||
|
||||
party_t PARTY;
|
||||
#include "save/save.h"
|
||||
|
||||
void partyInit(void) {
|
||||
memoryZero(&PARTY, sizeof(party_t));
|
||||
party_t *party = &SAVE.slot.party;
|
||||
|
||||
memoryZero(party, sizeof(party_t));
|
||||
for(uint8_t i = 0; i < PARTY_MEMBER_COUNT_MAX; i++) {
|
||||
PARTY.members[i].id = i;
|
||||
party->members[i].id = i;
|
||||
}
|
||||
for(uint8_t i = 0; i < PARTY_ACTIVE_SIZE_MAX; i++) {
|
||||
PARTY.order[i] = PARTY_ORDER_EMPTY;
|
||||
party->order[i] = PARTY_ORDER_EMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t partyGetAvailableMember(void) {
|
||||
const party_t *party = &SAVE.slot.party;
|
||||
|
||||
for(uint8_t i = 0; i < PARTY_MEMBER_COUNT_MAX; i++) {
|
||||
if(PARTY.members[i].status == BATTLE_FIGHTER_STATUS_NULL) return i;
|
||||
if(party->members[i].status == BATTLE_FIGHTER_STATUS_NULL) return i;
|
||||
}
|
||||
|
||||
return 0xFF;
|
||||
@@ -34,18 +37,20 @@ battlefighter_t *partyAddMember(
|
||||
const uint16_t healthMax,
|
||||
const uint16_t mpMax
|
||||
) {
|
||||
party_t *party = &SAVE.slot.party;
|
||||
|
||||
const uint8_t index = partyGetAvailableMember();
|
||||
if(index == 0xFF) return NULL;
|
||||
|
||||
battlefighter_t *member = &PARTY.members[index];
|
||||
battlefighter_t *member = &party->members[index];
|
||||
battleFighterInit(
|
||||
member, BATTLE_FIGHTER_TEAM_ALLY, BATTLE_FIGHTER_CONTROLLER_PLAYER,
|
||||
stats, healthMax, mpMax
|
||||
);
|
||||
|
||||
for(uint8_t i = 0; i < PARTY_ACTIVE_SIZE_MAX; i++) {
|
||||
if(PARTY.order[i] != PARTY_ORDER_EMPTY) continue;
|
||||
PARTY.order[i] = index;
|
||||
if(party->order[i] != PARTY_ORDER_EMPTY) continue;
|
||||
party->order[i] = index;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -55,9 +60,10 @@ battlefighter_t *partyAddMember(
|
||||
battlefighter_t *partyGetOrderMember(const uint8_t slot) {
|
||||
assertTrue(slot < PARTY_ACTIVE_SIZE_MAX, "Invalid party order slot");
|
||||
|
||||
const uint8_t index = PARTY.order[slot];
|
||||
party_t *party = &SAVE.slot.party;
|
||||
const uint8_t index = party->order[slot];
|
||||
if(index == PARTY_ORDER_EMPTY) return NULL;
|
||||
return &PARTY.members[index];
|
||||
return &party->members[index];
|
||||
}
|
||||
|
||||
void partySetOrder(const uint8_t slot, const uint8_t memberIndex) {
|
||||
@@ -67,5 +73,5 @@ void partySetOrder(const uint8_t slot, const uint8_t memberIndex) {
|
||||
"Invalid party member index"
|
||||
);
|
||||
|
||||
PARTY.order[slot] = memberIndex;
|
||||
SAVE.slot.party.order[slot] = memberIndex;
|
||||
}
|
||||
+13
-10
@@ -22,24 +22,25 @@ typedef struct {
|
||||
uint8_t order[PARTY_ACTIVE_SIZE_MAX];
|
||||
} party_t;
|
||||
|
||||
extern party_t PARTY;
|
||||
|
||||
/**
|
||||
* Initializes the party system with an empty roster and order.
|
||||
* Initializes the current save slot's party (SAVE.slot.party) with an
|
||||
* empty roster and order.
|
||||
*/
|
||||
void partyInit(void);
|
||||
|
||||
/**
|
||||
* Gets an available (unused) party member slot index.
|
||||
* Gets an available (unused) member slot index in the current save slot's
|
||||
* party.
|
||||
*
|
||||
* @return The index of an available slot, or 0xFF if the party is full.
|
||||
*/
|
||||
uint8_t partyGetAvailableMember(void);
|
||||
|
||||
/**
|
||||
* Adds a member to the party roster in the next available slot. Party
|
||||
* members are always allies controlled by the player. If there is a
|
||||
* free active order slot, the new member is placed into it.
|
||||
* Adds a member to the current save slot's party roster in the next
|
||||
* available slot. Party members are always allies controlled by the
|
||||
* player. If there is a free active order slot, the new member is placed
|
||||
* into it.
|
||||
*
|
||||
* @param stats The member's base combat stats.
|
||||
* @param healthMax The member's maximum health.
|
||||
@@ -54,7 +55,8 @@ battlefighter_t *partyAddMember(
|
||||
);
|
||||
|
||||
/**
|
||||
* Gets the roster member currently occupying an active order slot.
|
||||
* Gets the roster member currently occupying an active order slot in the
|
||||
* current save slot's party.
|
||||
*
|
||||
* @param slot The active order slot to query.
|
||||
* @return Pointer to the member in that slot, or NULL if the slot is
|
||||
@@ -63,8 +65,9 @@ battlefighter_t *partyAddMember(
|
||||
battlefighter_t *partyGetOrderMember(const uint8_t slot);
|
||||
|
||||
/**
|
||||
* Assigns a roster member to an active order slot, replacing whatever
|
||||
* was there. Use PARTY_ORDER_EMPTY to clear a slot.
|
||||
* Assigns a roster member to an active order slot in the current save
|
||||
* slot's party, replacing whatever was there. Use PARTY_ORDER_EMPTY to
|
||||
* clear a slot.
|
||||
*
|
||||
* @param slot The active order slot to assign.
|
||||
* @param memberIndex The roster member index to place there, or
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "testbattle.h"
|
||||
#include "rpg/battle/battle.h"
|
||||
#include "scene/scene.h"
|
||||
|
||||
void testBattleStart(void) {
|
||||
battleInit();
|
||||
|
||||
const battlefighterstats_t allyOneStats =
|
||||
{ .attack = 10, .defense = 5, .magic = 0, .speed = 10, .luck = 0 };
|
||||
const battlefighterstats_t allyTwoStats =
|
||||
{ .attack = 8, .defense = 4, .magic = 0, .speed = 8, .luck = 0 };
|
||||
const battlefighterstats_t enemyOneStats =
|
||||
{ .attack = 6, .defense = 3, .magic = 0, .speed = 6, .luck = 0 };
|
||||
const battlefighterstats_t enemyTwoStats =
|
||||
{ .attack = 7, .defense = 3, .magic = 0, .speed = 5, .luck = 0 };
|
||||
|
||||
battleAddFighter(
|
||||
BATTLE_FIGHTER_TEAM_ALLY, BATTLE_FIGHTER_CONTROLLER_PLAYER,
|
||||
allyOneStats, 30, 10
|
||||
);
|
||||
battleAddFighter(
|
||||
BATTLE_FIGHTER_TEAM_ALLY, BATTLE_FIGHTER_CONTROLLER_PLAYER,
|
||||
allyTwoStats, 25, 10
|
||||
);
|
||||
battleAddFighter(
|
||||
BATTLE_FIGHTER_TEAM_ENEMY, BATTLE_FIGHTER_CONTROLLER_AI,
|
||||
enemyOneStats, 20, 5
|
||||
);
|
||||
battleAddFighter(
|
||||
BATTLE_FIGHTER_TEAM_ENEMY, BATTLE_FIGHTER_CONTROLLER_AI,
|
||||
enemyTwoStats, 20, 5
|
||||
);
|
||||
|
||||
battleStart(BATTLE_ENCOUNTER_REGULAR, true);
|
||||
sceneSet(SCENE_TYPE_BATTLE);
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "error/error.h"
|
||||
|
||||
/**
|
||||
* TEMPORARY test hook: sets up a hardcoded mock battle and switches to the
|
||||
* battle scene, so the battle scene (camera/fighters/HUD) can be seen and
|
||||
* played without a real encounter trigger yet.
|
||||
*/
|
||||
void testBattleStart(void);
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
@@ -19,6 +19,18 @@ typedef struct cutscene_s {
|
||||
size_t dataSize;
|
||||
} cutscene_t;
|
||||
|
||||
/**
|
||||
* Declares a standalone, named cutscene_t (and its backing item array) -
|
||||
* the entry point for a C-authored cutscene.
|
||||
*
|
||||
* @param NAME Suffix for the generated CUTSCENE_##NAME cutscene/items
|
||||
* statics.
|
||||
* @param SIZE Bytes of custom user data this cutscene needs, carved out
|
||||
* of CUTSCENE_SYSTEM.data while it runs.
|
||||
* @param PAUSE_TYPE Suffix of the CUTSCENE_PAUSE_* flag(s) to apply
|
||||
* while this cutscene runs (e.g. NONE, ALL).
|
||||
* @param ... The cutscene's cutsceneitem_t entries, in order.
|
||||
*/
|
||||
#define CUTSCENE(NAME, SIZE, PAUSE_TYPE, ...) \
|
||||
static const cutsceneitem_t CUTSCENE_##NAME##_ITEMS[] = { __VA_ARGS__ }; \
|
||||
static const cutscene_t CUTSCENE_##NAME = { \
|
||||
@@ -28,486 +40,25 @@ typedef struct cutscene_s {
|
||||
.dataSize = SIZE \
|
||||
};
|
||||
|
||||
/**
|
||||
* References a CUTSCENE(NAME, ...)-declared cutscene by name.
|
||||
*
|
||||
* @param CUTSCENE The cutscene's NAME, as passed to CUTSCENE(...).
|
||||
*/
|
||||
#define CUTSCENE_REFERENCE(CUTSCENE) \
|
||||
&CUTSCENE_##CUTSCENE
|
||||
|
||||
#define CUTSCENE_TEXT(TEXT) \
|
||||
{ .type = CUTSCENE_ITEM_TYPE_TEXT, .text = { .text = TEXT } }
|
||||
|
||||
#define CUTSCENE_TEXT_MINI(TEXT, X, Y, Z, DURATION) \
|
||||
{ \
|
||||
.type = CUTSCENE_ITEM_TYPE_TEXT_MINI, \
|
||||
.textMini = { \
|
||||
.text = TEXT, \
|
||||
.position = { X, Y, Z }, \
|
||||
.duration = DURATION \
|
||||
} \
|
||||
}
|
||||
|
||||
#define CUTSCENE_TEXT_MINI_HIDE(INDEX) \
|
||||
{ \
|
||||
.type = CUTSCENE_ITEM_TYPE_TEXT_MINI_HIDE, \
|
||||
.textMiniHide = { .index = INDEX } \
|
||||
}
|
||||
|
||||
#define CUTSCENE_WAIT(WAIT) \
|
||||
{ .type = CUTSCENE_ITEM_TYPE_WAIT, .wait = WAIT }
|
||||
|
||||
// A named, otherwise no-op position in the item list that cutsceneGoTo
|
||||
// can jump execution straight to. NAME is matched with stringEquals,
|
||||
// not pointer identity, so it's safe to use separate string literals
|
||||
// with the same contents at the marker and at each call site.
|
||||
#define CUTSCENE_MARKER(NAME) \
|
||||
{ .type = CUTSCENE_ITEM_TYPE_MARKER, .marker = { .name = NAME } }
|
||||
|
||||
// Restarts the currently running cutscene from its first item,
|
||||
// preserving whatever interact/interacted entities triggered it.
|
||||
#define CUTSCENE_RESTART() \
|
||||
{ .type = CUTSCENE_ITEM_TYPE_RESTART }
|
||||
|
||||
// Blocks the cutscene here indefinitely - it never completes on its own,
|
||||
// only cutsceneGoTo (called externally, e.g. from a UI callback) can move
|
||||
// execution past it.
|
||||
#define CUTSCENE_IDLE() \
|
||||
{ .type = CUTSCENE_ITEM_TYPE_IDLE }
|
||||
|
||||
// Opens a full-screen UI panel (e.g. the main menu) declaratively, then
|
||||
// immediately continues on to whatever follows this item.
|
||||
#define CUTSCENE_UI_SHOW(SCREEN) \
|
||||
{ .type = CUTSCENE_ITEM_TYPE_UI_SHOW, .uiShow = { .screen = SCREEN } }
|
||||
|
||||
// Requests a switch to a different SCENE_TYPE via sceneSet, then
|
||||
// immediately continues on to whatever follows this item - the switch
|
||||
// itself doesn't happen until the next sceneUpdate() tick, so it does
|
||||
// not take effect this frame.
|
||||
#define CUTSCENE_SCENE(TYPE) \
|
||||
{ .type = CUTSCENE_ITEM_TYPE_SCENE, .sceneChange = { .type = TYPE } }
|
||||
|
||||
/**
|
||||
* Hands control over to another CUTSCENE(NAME, ...)-declared cutscene.
|
||||
* Has no dedicated item header of its own - cutscenecutsceneref_t is
|
||||
* defined inline in cutsceneitem.h, tightly bound to the asset/loader
|
||||
* system, so this shorthand stays here too.
|
||||
*
|
||||
* @param CUTSCENE The referenced cutscene's NAME, as passed to
|
||||
* CUTSCENE(...).
|
||||
*/
|
||||
#define CUTSCENE_CUTSCENE(CUTSCENE) \
|
||||
{ \
|
||||
.type = CUTSCENE_ITEM_TYPE_CUTSCENE, \
|
||||
.cutscene = CUTSCENE_REFERENCE(CUTSCENE) \
|
||||
}
|
||||
|
||||
#define CUTSCENE_CALLBACK(CALLBACK) \
|
||||
{ .type = CUTSCENE_ITEM_TYPE_CALLBACK, .callback = CALLBACK }
|
||||
|
||||
#define CUTSCENE_PRINT(TEXT) \
|
||||
{ .type = CUTSCENE_ITEM_TYPE_PRINT, .print = { .text = TEXT } }
|
||||
|
||||
// Shows a message-only modal (no option buttons) and immediately
|
||||
// continues on to whatever follows this item - it does not wait for
|
||||
// the dialog to be dismissed. Script the rest of the interaction (e.g.
|
||||
// CUTSCENE_CALLBACK to kick off work, CUTSCENE_WAIT, then
|
||||
// CUTSCENE_MODAL_CLOSE) as later items in the same cutscene.
|
||||
// TITLE and MESSAGE are each displayed as-is unless they match a
|
||||
// locale message ID, in which case the translated string is shown
|
||||
// instead - see uiModalLocalize.
|
||||
#define CUTSCENE_MODAL(TITLE, MESSAGE) \
|
||||
{ \
|
||||
.type = CUTSCENE_ITEM_TYPE_MODAL, \
|
||||
.modal = { .title = TITLE, .message = MESSAGE } \
|
||||
}
|
||||
|
||||
// Shows a modal with option buttons and immediately continues on, same
|
||||
// as CUTSCENE_MODAL - it does not block waiting for a selection.
|
||||
// Back/cancel input is disabled while it's open (see
|
||||
// uiMenuSetDisableBack), so it must be dismissed by picking one; CALLBACK
|
||||
// then fires with the selected option index once the dialog closes.
|
||||
// Option labels are passed as trailing arguments, e.g.
|
||||
// CUTSCENE_MODAL_OPTIONS(title, message, callback, "Retry", "Cancel") -
|
||||
// their strings are not copied by this item, so they must stay valid
|
||||
// until the modal opens (string literals are fine). Like TITLE and
|
||||
// MESSAGE, each option is translated if it matches a locale message ID.
|
||||
#define CUTSCENE_MODAL_OPTIONS(TITLE, MESSAGE, CALLBACK, ...) \
|
||||
{ \
|
||||
.type = CUTSCENE_ITEM_TYPE_MODAL, \
|
||||
.modal = { \
|
||||
.title = TITLE, .message = MESSAGE, \
|
||||
.options = (const char_t *[]){ __VA_ARGS__ }, \
|
||||
.optionCount = (uint8_t)( \
|
||||
sizeof((const char_t *[]){ __VA_ARGS__ }) / sizeof(const char_t *) \
|
||||
), \
|
||||
.callback = CALLBACK \
|
||||
} \
|
||||
}
|
||||
|
||||
// Same as CUTSCENE_MODAL_OPTIONS, but fixed to exactly one option and
|
||||
// MARKER1 to jump straight to via cutsceneGoTo once it's selected - no
|
||||
// callback function to write. Does not fall through to whatever follows
|
||||
// this item, so MARKER1 must be scripted elsewhere in the same cutscene.
|
||||
#define CUTSCENE_MODAL_OPTIONS_ONE(TITLE, MESSAGE, OPTION1, MARKER1) \
|
||||
{ \
|
||||
.type = CUTSCENE_ITEM_TYPE_MODAL_OPTIONS_MARKERS, \
|
||||
.modalOptionsMarkers = { \
|
||||
.title = TITLE, .message = MESSAGE, \
|
||||
.options = { OPTION1 }, \
|
||||
.markers = { MARKER1 }, \
|
||||
.optionCount = 1 \
|
||||
} \
|
||||
}
|
||||
|
||||
// Same as CUTSCENE_MODAL_OPTIONS, but fixed to exactly two options,
|
||||
// jumping straight to OPTION1_MARKER or OPTION2_MARKER via cutsceneGoTo
|
||||
// once the corresponding option is selected - no callback function to
|
||||
// write. Does not fall through to whatever follows this item, so both
|
||||
// markers must be scripted elsewhere in the same cutscene.
|
||||
#define CUTSCENE_MODAL_OPTIONS_TWO( \
|
||||
TITLE, MESSAGE, OPTION1, OPTION1_MARKER, OPTION2, OPTION2_MARKER \
|
||||
) \
|
||||
{ \
|
||||
.type = CUTSCENE_ITEM_TYPE_MODAL_OPTIONS_MARKERS, \
|
||||
.modalOptionsMarkers = { \
|
||||
.title = TITLE, .message = MESSAGE, \
|
||||
.options = { OPTION1, OPTION2 }, \
|
||||
.markers = { OPTION1_MARKER, OPTION2_MARKER }, \
|
||||
.optionCount = 2 \
|
||||
} \
|
||||
}
|
||||
|
||||
// Closes the currently open modal (if any). Useful when a modal was
|
||||
// opened outside of a blocking CUTSCENE_MODAL item (e.g. directly via
|
||||
// uiModalOpen) and this cutscene just needs to dismiss it and continue
|
||||
// on to whatever follows this item in the sequence.
|
||||
#define CUTSCENE_MODAL_CLOSE() \
|
||||
{ .type = CUTSCENE_ITEM_TYPE_MODAL_CLOSE }
|
||||
|
||||
// Opens the on-screen keyboard and blocks the cutscene until it closes,
|
||||
// then caches whatever was typed - see cutsceneSystemGetTextCache to
|
||||
// read it back afterwards. __VA_ARGS__ are uikeyboardopen_t designated
|
||||
// initializers, e.g. CUTSCENE_KEYBOARD(.cancel = true, .maxLength = 8).
|
||||
#define CUTSCENE_KEYBOARD(...) \
|
||||
{ \
|
||||
.type = CUTSCENE_ITEM_TYPE_KEYBOARD, \
|
||||
.keyboard = { .open = { __VA_ARGS__ } } \
|
||||
}
|
||||
|
||||
// (Re)requests an available save device and jumps straight to
|
||||
// SUCCESS_MARKER or FAILURE_MARKER once it resolves, same as a
|
||||
// CUTSCENE_MODAL_OPTIONS callback - it does not fall through to
|
||||
// whatever follows this item, so both markers must be scripted
|
||||
// elsewhere in the same cutscene.
|
||||
#define CUTSCENE_SAVE_DEVICE_CHECK(SUCCESS_MARKER, FAILURE_MARKER) \
|
||||
{ \
|
||||
.type = CUTSCENE_ITEM_TYPE_SAVE_DEVICE_CHECK, \
|
||||
.saveDeviceCheck = { \
|
||||
.successMarker = SUCCESS_MARKER, \
|
||||
.failureMarker = FAILURE_MARKER \
|
||||
} \
|
||||
}
|
||||
|
||||
// (Re)loads every save slot via saveLoadAllSlots() and jumps straight to
|
||||
// SUCCESS_MARKER or FAILURE_MARKER once it resolves, same shape as
|
||||
// CUTSCENE_SAVE_DEVICE_CHECK - it does not fall through to whatever
|
||||
// follows this item, so both markers must be scripted elsewhere in the
|
||||
// same cutscene.
|
||||
#define CUTSCENE_SAVE_LOAD_ALL_SLOTS(SUCCESS_MARKER, FAILURE_MARKER) \
|
||||
{ \
|
||||
.type = CUTSCENE_ITEM_TYPE_SAVE_LOAD_ALL_SLOTS, \
|
||||
.saveLoadAllSlots = { \
|
||||
.successMarker = SUCCESS_MARKER, \
|
||||
.failureMarker = FAILURE_MARKER \
|
||||
} \
|
||||
}
|
||||
|
||||
#define CUTSCENE_ENTITY_WALK_TO(ENTITY_INDEX, X, Y, Z) \
|
||||
{ \
|
||||
.type = CUTSCENE_ITEM_TYPE_ENTITY_WALK_TO, \
|
||||
.entityWalkTo = { \
|
||||
.entityIndex = ENTITY_INDEX, \
|
||||
.positions = (const worldpos_t[]){ { X, Y, Z } }, \
|
||||
.count = 1, \
|
||||
.walkAround = true \
|
||||
} \
|
||||
}
|
||||
|
||||
#define CUTSCENE_ENTITY_WALK_PATH(NAME, ENTITY_INDEX, ...) \
|
||||
static const worldpos_t CUTSCENE_##NAME##_POSITIONS[] = { __VA_ARGS__ }; \
|
||||
static const cutsceneitem_t CUTSCENE_##NAME = { \
|
||||
.type = CUTSCENE_ITEM_TYPE_ENTITY_WALK_TO, \
|
||||
.entityWalkTo = { \
|
||||
.entityIndex = ENTITY_INDEX, \
|
||||
.positions = CUTSCENE_##NAME##_POSITIONS, \
|
||||
.count = sizeof(CUTSCENE_##NAME##_POSITIONS) / sizeof(worldpos_t), \
|
||||
.walkAround = true \
|
||||
} \
|
||||
}
|
||||
|
||||
#define CUTSCENE_ENTITY_REMOVE(ENTITY_INDEX) \
|
||||
{ \
|
||||
.type = CUTSCENE_ITEM_TYPE_ENTITY_REMOVE, \
|
||||
.entityRemove = { .entityIndex = ENTITY_INDEX } \
|
||||
}
|
||||
|
||||
#define CUTSCENE_ENTITY_ADD(TYPE, X, Y, Z) \
|
||||
{ \
|
||||
.type = CUTSCENE_ITEM_TYPE_ENTITY_ADD, \
|
||||
.entityAdd = { .entityType = TYPE, .position = { X, Y, Z } } \
|
||||
}
|
||||
|
||||
#define CUTSCENE_ENTITY_TURN(ENTITY_INDEX, DIRECTION) \
|
||||
{ \
|
||||
.type = CUTSCENE_ITEM_TYPE_ENTITY_TURN, \
|
||||
.entityTurn = { .entityIndex = ENTITY_INDEX, .direction = DIRECTION } \
|
||||
}
|
||||
|
||||
// Walks ENTITY_INDEX to stand beside TARGET_ENTITY_INDEX, offset by
|
||||
// (OFFSET_X, OFFSET_Y) on the 2D plane. The destination Z is resolved
|
||||
// from nearby terrain each frame, so ramps between the two entities are
|
||||
// accounted for automatically.
|
||||
#define CUTSCENE_ENTITY_WALK_TO_ENTITY( \
|
||||
ENTITY_INDEX, TARGET_ENTITY_INDEX, OFFSET_X, OFFSET_Y \
|
||||
) \
|
||||
{ \
|
||||
.type = CUTSCENE_ITEM_TYPE_ENTITY_WALK_TO_ENTITY, \
|
||||
.entityWalkToEntity = { \
|
||||
.entityIndex = ENTITY_INDEX, \
|
||||
.targetEntityIndex = TARGET_ENTITY_INDEX, \
|
||||
.offsetX = OFFSET_X, \
|
||||
.offsetY = OFFSET_Y \
|
||||
} \
|
||||
}
|
||||
|
||||
#define CUTSCENE_ENTITY_TELEPORT(ENTITY_INDEX, X, Y, Z) \
|
||||
{ \
|
||||
.type = CUTSCENE_ITEM_TYPE_ENTITY_TELEPORT, \
|
||||
.entityTeleport = { .entityIndex = ENTITY_INDEX, .target = { X, Y, Z } } \
|
||||
}
|
||||
|
||||
#define CUTSCENE_FADE(FROM, TO, DURATION, EASING) \
|
||||
{ \
|
||||
.type = CUTSCENE_ITEM_TYPE_FADE, \
|
||||
.fade = { .from = FROM, .to = TO, .duration = DURATION, .easing = EASING } \
|
||||
}
|
||||
|
||||
#define CUTSCENE_FADE_TO_BLACK(DURATION) \
|
||||
CUTSCENE_FADE(COLOR_TRANSPARENT_BLACK, COLOR_BLACK, DURATION, EASING_LINEAR)
|
||||
|
||||
#define CUTSCENE_FADE_FROM_BLACK(DURATION) \
|
||||
CUTSCENE_FADE(COLOR_BLACK, COLOR_TRANSPARENT_BLACK, DURATION, EASING_LINEAR)
|
||||
|
||||
#define CUTSCENE_FADE_TO_WHITE(DURATION) \
|
||||
CUTSCENE_FADE(COLOR_TRANSPARENT_WHITE, COLOR_WHITE, DURATION, EASING_LINEAR)
|
||||
|
||||
#define CUTSCENE_FADE_FROM_WHITE(DURATION) \
|
||||
CUTSCENE_FADE(COLOR_WHITE, COLOR_TRANSPARENT_WHITE, DURATION, EASING_LINEAR)
|
||||
|
||||
#define CUTSCENE_EMOJI(ENTITY_INDEX, EMOJI_TYPE, DURATION) \
|
||||
{ \
|
||||
.type = CUTSCENE_ITEM_TYPE_EMOJI, \
|
||||
.emoji = { \
|
||||
.entityIndex = ENTITY_INDEX, \
|
||||
.emojiType = EMOJI_TYPE, \
|
||||
.duration = DURATION \
|
||||
} \
|
||||
}
|
||||
|
||||
// AMOUNT ranges 0 (no shake) to 4 (three tiles): 1 is half a tile, 2 is
|
||||
// a full tile, 3 is two tiles, and 4 is three tiles.
|
||||
#define CUTSCENE_SHAKE(AMOUNT, DURATION) \
|
||||
{ \
|
||||
.type = CUTSCENE_ITEM_TYPE_SHAKE, \
|
||||
.shake = { .amount = AMOUNT, .duration = DURATION } \
|
||||
}
|
||||
|
||||
// Waits until BATTLE.state reaches STATE. Put this BEFORE
|
||||
// CUTSCENE_SET_PAUSE(CUTSCENE_PAUSE_BATTLE), not after -- pausing first
|
||||
// freezes BATTLE.state wherever it already is, so it would never reach
|
||||
// STATE on its own to satisfy the wait. Waiting unpaused, then pausing the
|
||||
// moment it's satisfied, catches the battle right at STATE before it can
|
||||
// advance further.
|
||||
#define CUTSCENE_BATTLE_WAIT_STATE(STATE) \
|
||||
{ \
|
||||
.type = CUTSCENE_ITEM_TYPE_BATTLE_WAIT_STATE, \
|
||||
.battleWaitState = { .state = STATE } \
|
||||
}
|
||||
|
||||
// Immediately queues an attack for FIGHTER_INDEX against TARGET_INDEX,
|
||||
// bypassing normal player/AI selection for that fighter this round.
|
||||
#define CUTSCENE_BATTLE_FORCE_ACTION(FIGHTER_INDEX, TARGET_INDEX) \
|
||||
{ \
|
||||
.type = CUTSCENE_ITEM_TYPE_BATTLE_FORCE_ACTION, \
|
||||
.battleForceAction = { \
|
||||
.fighterIndex = FIGHTER_INDEX, .targetIndex = TARGET_INDEX \
|
||||
} \
|
||||
}
|
||||
|
||||
#define CUTSCENE_SET_PAUSE(FLAGS) \
|
||||
{ .type = CUTSCENE_ITEM_TYPE_SET_PAUSE, .setPause = (FLAGS) }
|
||||
|
||||
#define CUTSCENE_ITEM_GIVE(ITEM_ID, QUANTITY) \
|
||||
{ \
|
||||
.type = CUTSCENE_ITEM_TYPE_ITEM_GIVE, \
|
||||
.itemGive = { .item = ITEM_ID, .quantity = QUANTITY } \
|
||||
}
|
||||
|
||||
// Runs all listed items simultaneously and waits until all are done.
|
||||
// Concurrent items cannot be nested inside another CUTSCENE_CONCURRENT.
|
||||
#define CUTSCENE_CONCURRENT(...) \
|
||||
{ \
|
||||
.type = CUTSCENE_ITEM_TYPE_CONCURRENT, \
|
||||
.concurrent = { \
|
||||
.items = (const cutsceneitem_t[]){ __VA_ARGS__ }, \
|
||||
.count = (uint8_t)( \
|
||||
sizeof((cutsceneitem_t[]){ __VA_ARGS__ }) / \
|
||||
sizeof(cutsceneitem_t) \
|
||||
) \
|
||||
} \
|
||||
}
|
||||
|
||||
#define CUTSCENE_MAP_AREA_ADD( \
|
||||
MIN_X, MIN_Y, MIN_Z, MAX_X, MAX_Y, MAX_Z, CALLBACK, NOTIFY, TRIGGER \
|
||||
) \
|
||||
{ \
|
||||
.type = CUTSCENE_ITEM_TYPE_MAP_AREA_ADD, \
|
||||
.mapAreaAdd = { \
|
||||
.min = { MIN_X, MIN_Y, MIN_Z }, \
|
||||
.max = { MAX_X, MAX_Y, MAX_Z }, \
|
||||
.callback = CALLBACK, \
|
||||
.notify = NOTIFY, \
|
||||
.trigger = TRIGGER \
|
||||
} \
|
||||
}
|
||||
|
||||
#define CUTSCENE_MAP_AREA_REMOVE(AREA_ID) \
|
||||
{ \
|
||||
.type = CUTSCENE_ITEM_TYPE_MAP_AREA_REMOVE, \
|
||||
.mapAreaRemove = { .areaId = AREA_ID } \
|
||||
}
|
||||
|
||||
// Waits until any one of the given map area IDs has its callback invoked.
|
||||
// Accepts CUTSCENE_AREA_LAST_CREATED in place of a literal area ID.
|
||||
#define CUTSCENE_MAP_AREA_WAIT(...) \
|
||||
{ \
|
||||
.type = CUTSCENE_ITEM_TYPE_MAP_AREA_WAIT, \
|
||||
.mapAreaWait = { \
|
||||
.areaIds = (const uint8_t[]){ __VA_ARGS__ }, \
|
||||
.count = (uint8_t)( \
|
||||
sizeof((const uint8_t[]){ __VA_ARGS__ }) / sizeof(uint8_t) \
|
||||
) \
|
||||
} \
|
||||
}
|
||||
|
||||
// Adds a map area, waits for it to be triggered once, then removes it
|
||||
// before the cutscene continues. Uses a no-op callback since the wait is
|
||||
// driven by the area's trigger count rather than callback logic.
|
||||
#define CUTSCENE_MAP_AREA_TRIGGER_ONCE( \
|
||||
MIN_X, MIN_Y, MIN_Z, MAX_X, MAX_Y, MAX_Z, NOTIFY, TRIGGER \
|
||||
) \
|
||||
CUTSCENE_MAP_AREA_ADD( \
|
||||
MIN_X, MIN_Y, MIN_Z, MAX_X, MAX_Y, MAX_Z, \
|
||||
mapAreaNoopCallback, NOTIFY, TRIGGER \
|
||||
), \
|
||||
CUTSCENE_MAP_AREA_WAIT(CUTSCENE_AREA_LAST_CREATED), \
|
||||
CUTSCENE_MAP_AREA_REMOVE(CUTSCENE_AREA_LAST_CREATED)
|
||||
|
||||
// Longhand - every audioMixerQueuePlay() parameter. See
|
||||
// CUTSCENE_AUDIO_PLAY_SIMPLE/CUTSCENE_AUDIO_PLAY_LOOPED below for the
|
||||
// shorthands.
|
||||
#define CUTSCENE_AUDIO_PLAY( \
|
||||
FILE, CHANNEL, VOLUME, PAN, LOOPING, LOOP_COUNT, LOOP_START, LOOP_TO \
|
||||
) \
|
||||
{ \
|
||||
.type = CUTSCENE_ITEM_TYPE_AUDIO_PLAY, \
|
||||
.audioPlay = { \
|
||||
.file = FILE, \
|
||||
.channel = CHANNEL, \
|
||||
.volume = VOLUME, \
|
||||
.pan = PAN, \
|
||||
.looping = LOOPING, \
|
||||
.loopCount = LOOP_COUNT, \
|
||||
.loopStart = LOOP_START, \
|
||||
.loopTo = LOOP_TO \
|
||||
} \
|
||||
}
|
||||
|
||||
// Shorthand: play FILE on CHANNEL once, full volume, centered (0.0f, same
|
||||
// as AUDIO_STREAM_CENTER), no loop.
|
||||
#define CUTSCENE_AUDIO_PLAY_SIMPLE(FILE, CHANNEL) \
|
||||
CUTSCENE_AUDIO_PLAY(FILE, CHANNEL, 1.0f, 0.0f, false, 0, -1.0f, 0.0f)
|
||||
|
||||
// Shorthand: play FILE on CHANNEL looping the whole clip forever, full
|
||||
// volume, centered (0.0f, same as AUDIO_STREAM_CENTER).
|
||||
#define CUTSCENE_AUDIO_PLAY_LOOPED(FILE, CHANNEL) \
|
||||
CUTSCENE_AUDIO_PLAY(FILE, CHANNEL, 1.0f, 0.0f, true, 0, -1.0f, 0.0f)
|
||||
|
||||
#define CUTSCENE_AUDIO_STOP(CHANNEL) \
|
||||
{ .type = CUTSCENE_ITEM_TYPE_AUDIO_STOP, .audioStopChannel = CHANNEL }
|
||||
|
||||
#define CUTSCENE_AUDIO_PAUSE(CHANNEL) \
|
||||
{ .type = CUTSCENE_ITEM_TYPE_AUDIO_PAUSE, .audioPauseChannel = CHANNEL }
|
||||
|
||||
#define CUTSCENE_AUDIO_RESUME(CHANNEL) \
|
||||
{ .type = CUTSCENE_ITEM_TYPE_AUDIO_RESUME, .audioResumeChannel = CHANNEL }
|
||||
|
||||
// Longhand - starts CHANNEL fading from FROM to TO over DURATION seconds,
|
||||
// eased by EASING. Doesn't wait for it - pair with
|
||||
// CUTSCENE_AUDIO_FADE_WAIT(CHANNEL) to block until it finishes. See
|
||||
// CUTSCENE_AUDIO_FADE_OUT/CUTSCENE_AUDIO_FADE_IN below for the shorthands;
|
||||
// use this directly for a custom range, e.g.
|
||||
// CUTSCENE_AUDIO_FADE(CHANNEL, 1.0f, 0.3f, 5.0f, EASING_LINEAR) to fade
|
||||
// down to "playing quietly" rather than silent.
|
||||
#define CUTSCENE_AUDIO_FADE(CHANNEL, FROM, TO, DURATION, EASING) \
|
||||
{ \
|
||||
.type = CUTSCENE_ITEM_TYPE_AUDIO_FADE, \
|
||||
.audioFade = { \
|
||||
.channel = CHANNEL, \
|
||||
.from = FROM, \
|
||||
.to = TO, \
|
||||
.duration = DURATION, \
|
||||
.easing = EASING \
|
||||
} \
|
||||
}
|
||||
|
||||
// Shorthand: fade CHANNEL from full volume to silent over DURATION seconds.
|
||||
#define CUTSCENE_AUDIO_FADE_OUT(CHANNEL, DURATION) \
|
||||
CUTSCENE_AUDIO_FADE(CHANNEL, 1.0f, 0.0f, DURATION, EASING_LINEAR)
|
||||
|
||||
// Shorthand: fade CHANNEL from silent to full volume over DURATION seconds.
|
||||
#define CUTSCENE_AUDIO_FADE_IN(CHANNEL, DURATION) \
|
||||
CUTSCENE_AUDIO_FADE(CHANNEL, 0.0f, 1.0f, DURATION, EASING_LINEAR)
|
||||
|
||||
// Waits until CHANNEL's fade (started elsewhere by CUTSCENE_AUDIO_FADE)
|
||||
// has finished - a no-op wait if CHANNEL isn't fading.
|
||||
#define CUTSCENE_AUDIO_FADE_WAIT(CHANNEL) \
|
||||
{ \
|
||||
.type = CUTSCENE_ITEM_TYPE_AUDIO_FADE_WAIT, \
|
||||
.audioFadeWaitChannel = CHANNEL \
|
||||
}
|
||||
|
||||
#define CUTSCENE_AUDIO_SET_PAN(CHANNEL, PAN) \
|
||||
{ \
|
||||
.type = CUTSCENE_ITEM_TYPE_AUDIO_SET_PAN, \
|
||||
.audioSetPan = { .channel = CHANNEL, .pan = PAN } \
|
||||
}
|
||||
|
||||
#define CUTSCENE_AUDIO_SET_LOOP( \
|
||||
CHANNEL, LOOPING, LOOP_COUNT, LOOP_START, LOOP_TO \
|
||||
) \
|
||||
{ \
|
||||
.type = CUTSCENE_ITEM_TYPE_AUDIO_SET_LOOP, \
|
||||
.audioSetLoop = { \
|
||||
.channel = CHANNEL, \
|
||||
.looping = LOOPING, \
|
||||
.loopCount = LOOP_COUNT, \
|
||||
.loopStart = LOOP_START, \
|
||||
.loopTo = LOOP_TO \
|
||||
} \
|
||||
}
|
||||
|
||||
// Combined form of CUTSCENE_AUDIO_SET_PAN + CUTSCENE_AUDIO_SET_LOOP, for
|
||||
// setting both at once rather than as two separate items.
|
||||
#define CUTSCENE_AUDIO_SET( \
|
||||
CHANNEL, PAN, LOOPING, LOOP_COUNT, LOOP_START, LOOP_TO \
|
||||
) \
|
||||
{ \
|
||||
.type = CUTSCENE_ITEM_TYPE_AUDIO_SET, \
|
||||
.audioSet = { \
|
||||
.channel = CHANNEL, \
|
||||
.pan = PAN, \
|
||||
.looping = LOOPING, \
|
||||
.loopCount = LOOP_COUNT, \
|
||||
.loopStart = LOOP_START, \
|
||||
.loopTo = LOOP_TO \
|
||||
} \
|
||||
.cutsceneRef = { .cutscene = CUTSCENE_REFERENCE(CUTSCENE), .name = NULL } \
|
||||
}
|
||||
@@ -15,6 +15,21 @@
|
||||
|
||||
cutscenesystem_t CUTSCENE_SYSTEM;
|
||||
|
||||
cutsceneitem_t CUTSCENE_LOADED_ITEMS[CUTSCENE_LOADED_ITEMS_MAX];
|
||||
uint8_t CUTSCENE_LOADED_POOL[CUTSCENE_LOADED_POOL_SIZE_MAX];
|
||||
cutscene_t CUTSCENE_LOADED_SCENE = {
|
||||
.items = CUTSCENE_LOADED_ITEMS,
|
||||
.itemCount = 0,
|
||||
.pause = CUTSCENE_PAUSE_NONE,
|
||||
.dataSize = 0
|
||||
};
|
||||
static yyjson_doc *CUTSCENE_LOADED_DOC = NULL;
|
||||
|
||||
void cutsceneLoadedSetDoc(yyjson_doc *doc) {
|
||||
if(CUTSCENE_LOADED_DOC != NULL) yyjson_doc_free(CUTSCENE_LOADED_DOC);
|
||||
CUTSCENE_LOADED_DOC = doc;
|
||||
}
|
||||
|
||||
void cutsceneSystemInit() {
|
||||
memoryZero(&CUTSCENE_SYSTEM, sizeof(cutscenesystem_t));
|
||||
}
|
||||
@@ -69,13 +84,18 @@ void cutsceneSystemLoad(const char_t *file) {
|
||||
|
||||
assetentry_t *entry = assetLock(path, ASSET_LOADER_TYPE_CUTSCENE, NULL);
|
||||
errorret_t result = assetRequireLoaded(entry);
|
||||
// Released the instant loading finishes - the loader already parsed
|
||||
// everything we need into CUTSCENE_LOADED_SCENE/ITEMS/POOL, so nothing
|
||||
// further depends on this entry (see cutscenesystem.h's doc comment on
|
||||
// CUTSCENE_LOADED_ITEMS_MAX for why only one cutscene stays resident).
|
||||
assetUnlockEntry(entry);
|
||||
if(errorIsNotOk(result)) {
|
||||
errorCatch(errorPrint(result));
|
||||
uiFatalErrorOpen(NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
cutsceneSystemStartCutscene(&entry->data.cutscene.cutscene);
|
||||
cutsceneSystemStartCutscene(&CUTSCENE_LOADED_SCENE);
|
||||
}
|
||||
|
||||
void cutsceneRestart(void) {
|
||||
@@ -259,4 +279,6 @@ void cutsceneSystemDispose() {
|
||||
CUTSCENE_SYSTEM.textMiniLastCreated = CUTSCENE_TEXT_MINI_LAST_CREATED;
|
||||
CUTSCENE_SYSTEM.textCache[0] = '\0';
|
||||
CUTSCENE_SYSTEM.onComplete = NULL;
|
||||
|
||||
cutsceneLoadedSetDoc(NULL);
|
||||
}
|
||||
@@ -26,6 +26,39 @@ typedef struct entity_s entity_t;
|
||||
// CUTSCENE_ITEM_TYPE_KEYBOARD item is never truncated caching it here.
|
||||
#define CUTSCENE_TEXT_CACHE_MAX 64
|
||||
|
||||
// Only one JSON-authored cutscene is ever loaded/playing at a time - a
|
||||
// CUTSCENE item hands control off completely (see cutsceneCutsceneStart)
|
||||
// and cutsceneSystemLoad/cutsceneCutsceneResolve release their asset lock
|
||||
// the instant loading finishes - so there's no benefit to malloc'ing a
|
||||
// fresh items/pool buffer per load. Instead the asset loader
|
||||
// (assetCutsceneLoaderAsync) parses directly into these fixed, static
|
||||
// buffers. Bump these if a real cutscene ever needs more; C-authored
|
||||
// cutscenes (the CUTSCENE(...) macro) don't use these at all - they're
|
||||
// compiled directly into their own static const arrays.
|
||||
#define CUTSCENE_LOADED_ITEMS_MAX 128
|
||||
#define CUTSCENE_LOADED_POOL_SIZE_MAX 4096
|
||||
|
||||
extern cutsceneitem_t CUTSCENE_LOADED_ITEMS[CUTSCENE_LOADED_ITEMS_MAX];
|
||||
extern uint8_t CUTSCENE_LOADED_POOL[CUTSCENE_LOADED_POOL_SIZE_MAX];
|
||||
|
||||
// The cutscene_t for whatever was last parsed into CUTSCENE_LOADED_ITEMS/
|
||||
// CUTSCENE_LOADED_POOL - .items always points at CUTSCENE_LOADED_ITEMS;
|
||||
// itemCount/pause/dataSize are overwritten by the loader on each load.
|
||||
extern cutscene_t CUTSCENE_LOADED_SCENE;
|
||||
|
||||
/**
|
||||
* Frees whatever yyjson_doc currently backs CUTSCENE_LOADED_ITEMS' string
|
||||
* fields (marker/cutscene-reference names point directly into it - see
|
||||
* cutsceneCutsceneRefLoad/cutsceneMarkerLoad) and takes ownership of doc
|
||||
* instead. Called by the cutscene asset loader once a fresh parse into
|
||||
* CUTSCENE_LOADED_ITEMS/CUTSCENE_LOADED_POOL completes successfully, and
|
||||
* from cutsceneSystemDispose to release the last one at shutdown.
|
||||
*
|
||||
* @param doc The new doc to take ownership of (NULL just frees/clears the
|
||||
* current one).
|
||||
*/
|
||||
void cutsceneLoadedSetDoc(yyjson_doc *doc);
|
||||
|
||||
typedef struct {
|
||||
const cutscene_t *scene;
|
||||
uint8_t currentItem;
|
||||
|
||||
@@ -18,6 +18,50 @@ typedef struct {
|
||||
easingtype_t easing;
|
||||
} cutsceneaudiofade_t;
|
||||
|
||||
/**
|
||||
* Longhand - starts CHANNEL fading from FROM to TO over DURATION seconds,
|
||||
* eased by EASING. Doesn't wait for it - pair with
|
||||
* CUTSCENE_AUDIO_FADE_WAIT(CHANNEL) to block until it finishes. See
|
||||
* CUTSCENE_AUDIO_FADE_OUT/CUTSCENE_AUDIO_FADE_IN below for the
|
||||
* shorthands; use this directly for a custom range, e.g.
|
||||
* CUTSCENE_AUDIO_FADE(CHANNEL, 1.0f, 0.3f, 5.0f, EASING_LINEAR) to fade
|
||||
* down to "playing quietly" rather than silent.
|
||||
*
|
||||
* @param CHANNEL audiomixerchannel_t to fade.
|
||||
* @param FROM Starting volume (0.0-1.0).
|
||||
* @param TO Ending volume (0.0-1.0).
|
||||
* @param DURATION Duration in seconds.
|
||||
* @param EASING easingtype_t to apply.
|
||||
*/
|
||||
#define CUTSCENE_AUDIO_FADE(CHANNEL, FROM, TO, DURATION, EASING) \
|
||||
CUTSCENE_ITEM(CUTSCENE_ITEM_TYPE_AUDIO_FADE, audioFade, { \
|
||||
.channel = CHANNEL, \
|
||||
.from = FROM, \
|
||||
.to = TO, \
|
||||
.duration = DURATION, \
|
||||
.easing = EASING \
|
||||
})
|
||||
|
||||
/**
|
||||
* Shorthand: fade CHANNEL from full volume to silent over DURATION
|
||||
* seconds.
|
||||
*
|
||||
* @param CHANNEL audiomixerchannel_t to fade.
|
||||
* @param DURATION Duration in seconds.
|
||||
*/
|
||||
#define CUTSCENE_AUDIO_FADE_OUT(CHANNEL, DURATION) \
|
||||
CUTSCENE_AUDIO_FADE(CHANNEL, 1.0f, 0.0f, DURATION, EASING_LINEAR)
|
||||
|
||||
/**
|
||||
* Shorthand: fade CHANNEL from silent to full volume over DURATION
|
||||
* seconds.
|
||||
*
|
||||
* @param CHANNEL audiomixerchannel_t to fade.
|
||||
* @param DURATION Duration in seconds.
|
||||
*/
|
||||
#define CUTSCENE_AUDIO_FADE_IN(CHANNEL, DURATION) \
|
||||
CUTSCENE_AUDIO_FADE(CHANNEL, 0.0f, 1.0f, DURATION, EASING_LINEAR)
|
||||
|
||||
/**
|
||||
* Starts an audio fade step (starts the fade via audioMixerFadeTo() -
|
||||
* doesn't wait for it; pair with CUTSCENE_AUDIO_FADE_WAIT to block on it).
|
||||
|
||||
@@ -9,6 +9,15 @@
|
||||
#include "audio/mixer/audiomixerchannel.h"
|
||||
#include "rpg/cutscene/item/cutsceneitembase.h"
|
||||
|
||||
/**
|
||||
* Waits until CHANNEL's fade (started elsewhere by CUTSCENE_AUDIO_FADE)
|
||||
* has finished - a no-op wait if CHANNEL isn't fading.
|
||||
*
|
||||
* @param CHANNEL audiomixerchannel_t to wait on.
|
||||
*/
|
||||
#define CUTSCENE_AUDIO_FADE_WAIT(CHANNEL) \
|
||||
CUTSCENE_ITEM(CUTSCENE_ITEM_TYPE_AUDIO_FADE_WAIT, audioFadeWaitChannel, CHANNEL)
|
||||
|
||||
/**
|
||||
* Updates an audio fade-wait step, completing once the watched channel's
|
||||
* fade (started by a CUTSCENE_AUDIO_FADE elsewhere) finishes. Has no Start
|
||||
|
||||
@@ -9,6 +9,14 @@
|
||||
#include "audio/mixer/audiomixerchannel.h"
|
||||
#include "rpg/cutscene/item/cutsceneitembase.h"
|
||||
|
||||
/**
|
||||
* Pauses CHANNEL immediately.
|
||||
*
|
||||
* @param CHANNEL audiomixerchannel_t to pause.
|
||||
*/
|
||||
#define CUTSCENE_AUDIO_PAUSE(CHANNEL) \
|
||||
CUTSCENE_ITEM(CUTSCENE_ITEM_TYPE_AUDIO_PAUSE, audioPauseChannel, CHANNEL)
|
||||
|
||||
/**
|
||||
* Starts an audio pause step (pauses the channel immediately).
|
||||
*
|
||||
|
||||
@@ -20,6 +20,55 @@ typedef struct {
|
||||
float_t loopTo;
|
||||
} cutsceneaudioplay_t;
|
||||
|
||||
/**
|
||||
* Longhand - queues a sound via audioMixerQueuePlay() (see its own
|
||||
* comment on when it actually starts). See CUTSCENE_AUDIO_PLAY_SIMPLE/
|
||||
* CUTSCENE_AUDIO_PLAY_LOOPED below for the shorthands.
|
||||
*
|
||||
* @param FILE Audio file path.
|
||||
* @param CHANNEL audiomixerchannel_t to play on.
|
||||
* @param VOLUME Playback volume (0.0-1.0).
|
||||
* @param PAN Stereo pan (-1.0 left to 1.0 right, 0.0 centered).
|
||||
* @param LOOPING Whether the clip loops.
|
||||
* @param LOOP_COUNT Number of loop repeats (0 = infinite, if LOOPING).
|
||||
* @param LOOP_START Loop region start in seconds, or -1.0f for the clip
|
||||
* start.
|
||||
* @param LOOP_TO Loop region end/return point in seconds.
|
||||
*/
|
||||
#define CUTSCENE_AUDIO_PLAY( \
|
||||
FILE, CHANNEL, VOLUME, PAN, LOOPING, LOOP_COUNT, LOOP_START, LOOP_TO \
|
||||
) \
|
||||
CUTSCENE_ITEM(CUTSCENE_ITEM_TYPE_AUDIO_PLAY, audioPlay, { \
|
||||
.file = FILE, \
|
||||
.channel = CHANNEL, \
|
||||
.volume = VOLUME, \
|
||||
.pan = PAN, \
|
||||
.looping = LOOPING, \
|
||||
.loopCount = LOOP_COUNT, \
|
||||
.loopStart = LOOP_START, \
|
||||
.loopTo = LOOP_TO \
|
||||
})
|
||||
|
||||
/**
|
||||
* Shorthand: play FILE on CHANNEL once, full volume, centered (0.0f, same
|
||||
* as AUDIO_STREAM_CENTER), no loop.
|
||||
*
|
||||
* @param FILE Audio file path.
|
||||
* @param CHANNEL audiomixerchannel_t to play on.
|
||||
*/
|
||||
#define CUTSCENE_AUDIO_PLAY_SIMPLE(FILE, CHANNEL) \
|
||||
CUTSCENE_AUDIO_PLAY(FILE, CHANNEL, 1.0f, 0.0f, false, 0, -1.0f, 0.0f)
|
||||
|
||||
/**
|
||||
* Shorthand: play FILE on CHANNEL looping the whole clip forever, full
|
||||
* volume, centered (0.0f, same as AUDIO_STREAM_CENTER).
|
||||
*
|
||||
* @param FILE Audio file path.
|
||||
* @param CHANNEL audiomixerchannel_t to play on.
|
||||
*/
|
||||
#define CUTSCENE_AUDIO_PLAY_LOOPED(FILE, CHANNEL) \
|
||||
CUTSCENE_AUDIO_PLAY(FILE, CHANNEL, 1.0f, 0.0f, true, 0, -1.0f, 0.0f)
|
||||
|
||||
/**
|
||||
* Starts an audio play step (queues the sound via audioMixerQueuePlay() -
|
||||
* see its own comment on when it actually starts).
|
||||
|
||||
@@ -9,6 +9,14 @@
|
||||
#include "audio/mixer/audiomixerchannel.h"
|
||||
#include "rpg/cutscene/item/cutsceneitembase.h"
|
||||
|
||||
/**
|
||||
* Resumes CHANNEL immediately.
|
||||
*
|
||||
* @param CHANNEL audiomixerchannel_t to resume.
|
||||
*/
|
||||
#define CUTSCENE_AUDIO_RESUME(CHANNEL) \
|
||||
CUTSCENE_ITEM(CUTSCENE_ITEM_TYPE_AUDIO_RESUME, audioResumeChannel, CHANNEL)
|
||||
|
||||
/**
|
||||
* Starts an audio resume step (resumes the channel immediately).
|
||||
*
|
||||
|
||||
@@ -18,6 +18,30 @@ typedef struct {
|
||||
float_t loopTo;
|
||||
} cutsceneaudioset_t;
|
||||
|
||||
/**
|
||||
* Combined form of CUTSCENE_AUDIO_SET_PAN + CUTSCENE_AUDIO_SET_LOOP, for
|
||||
* setting both at once rather than as two separate items.
|
||||
*
|
||||
* @param CHANNEL audiomixerchannel_t to adjust.
|
||||
* @param PAN Stereo pan (-1.0 left to 1.0 right, 0.0 centered).
|
||||
* @param LOOPING Whether the clip loops.
|
||||
* @param LOOP_COUNT Number of loop repeats (0 = infinite, if LOOPING).
|
||||
* @param LOOP_START Loop region start in seconds, or -1.0f for the clip
|
||||
* start.
|
||||
* @param LOOP_TO Loop region end/return point in seconds.
|
||||
*/
|
||||
#define CUTSCENE_AUDIO_SET( \
|
||||
CHANNEL, PAN, LOOPING, LOOP_COUNT, LOOP_START, LOOP_TO \
|
||||
) \
|
||||
CUTSCENE_ITEM(CUTSCENE_ITEM_TYPE_AUDIO_SET, audioSet, { \
|
||||
.channel = CHANNEL, \
|
||||
.pan = PAN, \
|
||||
.looping = LOOPING, \
|
||||
.loopCount = LOOP_COUNT, \
|
||||
.loopStart = LOOP_START, \
|
||||
.loopTo = LOOP_TO \
|
||||
})
|
||||
|
||||
/**
|
||||
* Starts an audio set step - applies pan and looping behaviour together in
|
||||
* one item (via audioMixerSetPan()/audioMixerSetLoop()), for when you want
|
||||
|
||||
@@ -17,6 +17,27 @@ typedef struct {
|
||||
float_t loopTo;
|
||||
} cutsceneaudiosetloop_t;
|
||||
|
||||
/**
|
||||
* Applies new looping behaviour immediately, via audioMixerSetLoop().
|
||||
*
|
||||
* @param CHANNEL audiomixerchannel_t to adjust.
|
||||
* @param LOOPING Whether the clip loops.
|
||||
* @param LOOP_COUNT Number of loop repeats (0 = infinite, if LOOPING).
|
||||
* @param LOOP_START Loop region start in seconds, or -1.0f for the clip
|
||||
* start.
|
||||
* @param LOOP_TO Loop region end/return point in seconds.
|
||||
*/
|
||||
#define CUTSCENE_AUDIO_SET_LOOP( \
|
||||
CHANNEL, LOOPING, LOOP_COUNT, LOOP_START, LOOP_TO \
|
||||
) \
|
||||
CUTSCENE_ITEM(CUTSCENE_ITEM_TYPE_AUDIO_SET_LOOP, audioSetLoop, { \
|
||||
.channel = CHANNEL, \
|
||||
.looping = LOOPING, \
|
||||
.loopCount = LOOP_COUNT, \
|
||||
.loopStart = LOOP_START, \
|
||||
.loopTo = LOOP_TO \
|
||||
})
|
||||
|
||||
/**
|
||||
* Starts an audio set-loop step (applies the new looping behaviour
|
||||
* immediately, via audioMixerSetLoop()).
|
||||
|
||||
@@ -14,6 +14,17 @@ typedef struct {
|
||||
float_t pan;
|
||||
} cutsceneaudiosetpan_t;
|
||||
|
||||
/**
|
||||
* Applies a new pan immediately, via audioMixerSetPan().
|
||||
*
|
||||
* @param CHANNEL audiomixerchannel_t to adjust.
|
||||
* @param PAN Stereo pan (-1.0 left to 1.0 right, 0.0 centered).
|
||||
*/
|
||||
#define CUTSCENE_AUDIO_SET_PAN(CHANNEL, PAN) \
|
||||
CUTSCENE_ITEM(CUTSCENE_ITEM_TYPE_AUDIO_SET_PAN, audioSetPan, { \
|
||||
.channel = CHANNEL, .pan = PAN \
|
||||
})
|
||||
|
||||
/**
|
||||
* Starts an audio set-pan step (applies the new pan immediately, via
|
||||
* audioMixerSetPan()).
|
||||
|
||||
@@ -9,6 +9,14 @@
|
||||
#include "audio/mixer/audiomixerchannel.h"
|
||||
#include "rpg/cutscene/item/cutsceneitembase.h"
|
||||
|
||||
/**
|
||||
* Stops CHANNEL immediately.
|
||||
*
|
||||
* @param CHANNEL audiomixerchannel_t to stop.
|
||||
*/
|
||||
#define CUTSCENE_AUDIO_STOP(CHANNEL) \
|
||||
CUTSCENE_ITEM(CUTSCENE_ITEM_TYPE_AUDIO_STOP, audioStopChannel, CHANNEL)
|
||||
|
||||
/**
|
||||
* Starts an audio stop step (stops the channel immediately).
|
||||
*
|
||||
|
||||
@@ -8,4 +8,5 @@ target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
||||
cutscenestartbattle.c
|
||||
cutscenebattlewaitstate.c
|
||||
cutscenebattleforceaction.c
|
||||
cutsceneregularbattle.c
|
||||
)
|
||||
@@ -14,6 +14,18 @@ typedef struct {
|
||||
uint8_t targetIndex;
|
||||
} cutscenebattleforceaction_t;
|
||||
|
||||
/**
|
||||
* Immediately queues an attack for FIGHTER_INDEX against TARGET_INDEX,
|
||||
* bypassing normal player/AI selection for that fighter this round.
|
||||
*
|
||||
* @param FIGHTER_INDEX Attacking fighter's battle index.
|
||||
* @param TARGET_INDEX Target fighter's battle index.
|
||||
*/
|
||||
#define CUTSCENE_BATTLE_FORCE_ACTION(FIGHTER_INDEX, TARGET_INDEX) \
|
||||
CUTSCENE_ITEM(CUTSCENE_ITEM_TYPE_BATTLE_FORCE_ACTION, battleForceAction, { \
|
||||
.fighterIndex = FIGHTER_INDEX, .targetIndex = TARGET_INDEX \
|
||||
})
|
||||
|
||||
/**
|
||||
* Starts a battle force-action step: immediately queues an attack for the
|
||||
* given fighter against the given target, bypassing normal player/AI
|
||||
|
||||
@@ -13,6 +13,21 @@ typedef struct {
|
||||
battlestate_t state;
|
||||
} cutscenebattlewaitstate_t;
|
||||
|
||||
/**
|
||||
* Waits until BATTLE.state reaches STATE. Put this BEFORE
|
||||
* CUTSCENE_SET_PAUSE(CUTSCENE_PAUSE_BATTLE), not after -- pausing first
|
||||
* freezes BATTLE.state wherever it already is, so it would never reach
|
||||
* STATE on its own to satisfy the wait. Waiting unpaused, then pausing
|
||||
* the moment it's satisfied, catches the battle right at STATE before it
|
||||
* can advance further.
|
||||
*
|
||||
* @param STATE battlestate_t to wait for.
|
||||
*/
|
||||
#define CUTSCENE_BATTLE_WAIT_STATE(STATE) \
|
||||
CUTSCENE_ITEM(CUTSCENE_ITEM_TYPE_BATTLE_WAIT_STATE, battleWaitState, { \
|
||||
.state = STATE \
|
||||
})
|
||||
|
||||
/**
|
||||
* Updates a battle wait-state step, completing once BATTLE.state reaches
|
||||
* the watched state. Has no Start callback -- there's nothing to do until
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "rpg/cutscene/item/cutsceneitem.h"
|
||||
|
||||
bool_t cutsceneRegularBattleUpdate(
|
||||
const cutsceneitem_t *item,
|
||||
cutsceneitemdata_t *data
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
@@ -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 "rpg/cutscene/item/cutsceneitembase.h"
|
||||
|
||||
/**
|
||||
* Updates a regular-battle step. By the time this item runs, the preceding
|
||||
* START_BATTLE item has already waited out the whole encounter, synced
|
||||
* party HP/MP, and returned to the overworld scene - so this is currently
|
||||
* just a completes-immediately hook point for whatever regular-battle-
|
||||
* specific follow-up (loot, post-battle dialogue, etc.) gets added later.
|
||||
*
|
||||
* @param item The cutscene item.
|
||||
* @param data Runtime data storage.
|
||||
* @returns true always.
|
||||
*/
|
||||
bool_t cutsceneRegularBattleUpdate(
|
||||
const cutsceneitem_t *item,
|
||||
cutsceneitemdata_t *data
|
||||
);
|
||||
|
||||
// REGULAR_BATTLE has no fields of its own to parse yet - see
|
||||
// cutsceneItemLoadNoop (cutsceneitembase.h), used directly as its .load
|
||||
// callback.
|
||||
@@ -8,8 +8,11 @@
|
||||
#include "rpg/cutscene/item/cutsceneitem.h"
|
||||
#include "rpg/battle/party.h"
|
||||
#include "scene/scene.h"
|
||||
#include "save/save.h"
|
||||
#include "rpg/cutscene/item/json/cutscenejsonbattleencounter.h"
|
||||
#include "rpg/cutscene/item/json/cutscenejsonbattleability.h"
|
||||
#include "rpg/cutscene/item/json/cutscenejsonfield.h"
|
||||
#include "util/memory.h"
|
||||
|
||||
void cutsceneStartBattleStart(
|
||||
const cutsceneitem_t *item,
|
||||
@@ -19,8 +22,9 @@ void cutsceneStartBattleStart(
|
||||
|
||||
battleInit();
|
||||
|
||||
for(uint8_t i = 0; i < PARTY_ACTIVE_SIZE_MAX; i++) {
|
||||
battlefighter_t *member = partyGetOrderMember(i);
|
||||
for(uint8_t i = 0; i < config->playerCount; i++) {
|
||||
battlefighter_t *member =
|
||||
partyGetOrderMember(config->players[i]);
|
||||
if(member == NULL) continue;
|
||||
|
||||
battlefighter_t *fighter = battleAddFighter(
|
||||
@@ -32,14 +36,18 @@ void cutsceneStartBattleStart(
|
||||
fighter->health = member->health;
|
||||
fighter->mp = member->mp;
|
||||
fighter->status = member->status;
|
||||
memoryCopy(fighter->abilities, member->abilities, sizeof(fighter->abilities));
|
||||
}
|
||||
|
||||
for(uint8_t i = 0; i < config->enemyCount; i++) {
|
||||
const cutscenestartbattleenemy_t *enemy = &config->enemies[i];
|
||||
battleAddFighter(
|
||||
battlefighter_t *fighter = battleAddFighter(
|
||||
BATTLE_FIGHTER_TEAM_ENEMY, BATTLE_FIGHTER_CONTROLLER_AI,
|
||||
enemy->stats, enemy->healthMax, enemy->mpMax
|
||||
);
|
||||
if(fighter == NULL) continue;
|
||||
|
||||
memoryCopy(fighter->abilities, enemy->abilities, sizeof(fighter->abilities));
|
||||
}
|
||||
|
||||
battleStart(config->encounterType, config->fleeAvailable);
|
||||
@@ -52,13 +60,15 @@ bool_t cutsceneStartBattleUpdate(
|
||||
) {
|
||||
if(BATTLE.result == BATTLE_RESULT_NONE) return false;
|
||||
|
||||
const cutscenestartbattle_t *config = &item->startBattle;
|
||||
|
||||
// Sync ally HP/MP back to the persistent party roster. Relies on
|
||||
// ally fighters having been added to BATTLE.fighters in the same
|
||||
// order partyGetOrderMember() iterates, starting at index 0 (see
|
||||
// cutsceneStartBattleStart).
|
||||
// order config->players iterates (see cutsceneStartBattleStart).
|
||||
uint8_t allySlot = 0;
|
||||
for(uint8_t i = 0; i < PARTY_ACTIVE_SIZE_MAX; i++) {
|
||||
battlefighter_t *member = partyGetOrderMember(i);
|
||||
for(uint8_t i = 0; i < config->playerCount; i++) {
|
||||
battlefighter_t *member =
|
||||
partyGetOrderMember(config->players[i]);
|
||||
if(member == NULL) continue;
|
||||
|
||||
battlefighter_t *fighter = &BATTLE.fighters[allySlot++];
|
||||
@@ -89,6 +99,38 @@ errorret_t cutsceneStartBattleLoad(
|
||||
item->startBattle.fleeAvailable =
|
||||
cutsceneJsonGetBool(itemObj, "fleeAvailable", true);
|
||||
|
||||
yyjson_val *players = yyjson_obj_get(itemObj, "players");
|
||||
if(players == NULL) {
|
||||
item->startBattle.playerCount = PARTY_ACTIVE_SIZE_MAX;
|
||||
for(uint8_t i = 0; i < PARTY_ACTIVE_SIZE_MAX; i++) {
|
||||
item->startBattle.players[i] = i;
|
||||
}
|
||||
} else {
|
||||
size_t playerCount = yyjson_arr_size(players);
|
||||
if(!yyjson_is_arr(players) || playerCount > PARTY_ACTIVE_SIZE_MAX) {
|
||||
errorThrow(
|
||||
"Cutscene item (START_BATTLE): 'players' must have 0-%u entries",
|
||||
(uint32_t)PARTY_ACTIVE_SIZE_MAX
|
||||
);
|
||||
}
|
||||
item->startBattle.playerCount = (uint8_t)playerCount;
|
||||
|
||||
yyjson_arr_iter playerIter = yyjson_arr_iter_with(players);
|
||||
yyjson_val *playerVal;
|
||||
size_t p = 0;
|
||||
while((playerVal = yyjson_arr_iter_next(&playerIter)) != NULL) {
|
||||
int64_t index = yyjson_get_int(playerVal);
|
||||
if(index < 0 || index >= PARTY_ACTIVE_SIZE_MAX) {
|
||||
errorThrow(
|
||||
"Cutscene item (START_BATTLE): players[%u] must be 0-%u",
|
||||
(uint32_t)p, (uint32_t)(PARTY_ACTIVE_SIZE_MAX - 1)
|
||||
);
|
||||
}
|
||||
item->startBattle.players[p] = (uint8_t)index;
|
||||
p++;
|
||||
}
|
||||
}
|
||||
|
||||
yyjson_val *enemies = yyjson_obj_get(itemObj, "enemies");
|
||||
size_t enemyCount = yyjson_arr_size(enemies);
|
||||
if(!yyjson_is_arr(enemies) || enemyCount == 0 ||
|
||||
@@ -126,6 +168,37 @@ errorret_t cutsceneStartBattleLoad(
|
||||
(uint16_t)yyjson_get_int(yyjson_obj_get(enemyVal, "healthMax"));
|
||||
enemy->mpMax =
|
||||
(uint16_t)yyjson_get_int(yyjson_obj_get(enemyVal, "mpMax"));
|
||||
|
||||
yyjson_val *abilities = yyjson_obj_get(enemyVal, "abilities");
|
||||
if(abilities != NULL) {
|
||||
size_t abilityCount = yyjson_arr_size(abilities);
|
||||
if(!yyjson_is_arr(abilities) ||
|
||||
abilityCount > BATTLE_FIGHTER_ABILITY_COUNT_MAX) {
|
||||
errorThrow(
|
||||
"Cutscene item (START_BATTLE): enemies[%u].abilities must have "
|
||||
"0-%u entries",
|
||||
(uint32_t)e, (uint32_t)BATTLE_FIGHTER_ABILITY_COUNT_MAX
|
||||
);
|
||||
}
|
||||
|
||||
yyjson_arr_iter abilityIter = yyjson_arr_iter_with(abilities);
|
||||
yyjson_val *abilityVal;
|
||||
size_t a = 0;
|
||||
while((abilityVal = yyjson_arr_iter_next(&abilityIter)) != NULL) {
|
||||
battleability_t ability;
|
||||
if(!cutsceneJsonLookupBattleAbility(
|
||||
yyjson_get_str(abilityVal), &ability
|
||||
)) {
|
||||
errorThrow(
|
||||
"Cutscene item (START_BATTLE): enemies[%u].abilities[%u] is "
|
||||
"invalid",
|
||||
(uint32_t)e, (uint32_t)a
|
||||
);
|
||||
}
|
||||
enemy->abilities[a] = ability;
|
||||
a++;
|
||||
}
|
||||
}
|
||||
e++;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#pragma once
|
||||
#include "rpg/battle/battle.h"
|
||||
#include "rpg/battle/party.h"
|
||||
#include "rpg/cutscene/item/cutsceneitembase.h"
|
||||
|
||||
#define CUTSCENE_START_BATTLE_ENEMY_COUNT_MAX 4
|
||||
@@ -15,6 +16,7 @@ typedef struct {
|
||||
battlefighterstats_t stats;
|
||||
uint16_t healthMax;
|
||||
uint16_t mpMax;
|
||||
battleability_t abilities[BATTLE_FIGHTER_ABILITY_COUNT_MAX];
|
||||
} cutscenestartbattleenemy_t;
|
||||
|
||||
typedef struct {
|
||||
@@ -22,6 +24,13 @@ typedef struct {
|
||||
bool_t fleeAvailable;
|
||||
uint8_t enemyCount;
|
||||
cutscenestartbattleenemy_t enemies[CUTSCENE_START_BATTLE_ENEMY_COUNT_MAX];
|
||||
|
||||
// Active party order slots (see party.h) to bring into the battle, in
|
||||
// the order they should be added. Defaults to every active slot, 0
|
||||
// through PARTY_ACTIVE_SIZE_MAX - 1 in order, when the item's JSON
|
||||
// omits "players" - see cutsceneStartBattleLoad.
|
||||
uint8_t players[PARTY_ACTIVE_SIZE_MAX];
|
||||
uint8_t playerCount;
|
||||
} cutscenestartbattle_t;
|
||||
|
||||
/**
|
||||
|
||||
@@ -13,6 +13,22 @@
|
||||
/** Maximum number of items that may run inside a CUTSCENE_CONCURRENT. */
|
||||
#define CUTSCENE_CONCURRENT_MAX 8
|
||||
|
||||
/**
|
||||
* Runs all listed items simultaneously and waits until all are done.
|
||||
* Concurrent items cannot be nested inside another CUTSCENE_CONCURRENT.
|
||||
*
|
||||
* @param ... Child cutsceneitem_t entries (e.g. CUTSCENE_WAIT(...),
|
||||
* CUTSCENE_ENTITY_WALK_TO(...)) to run at the same time.
|
||||
*/
|
||||
#define CUTSCENE_CONCURRENT(...) \
|
||||
CUTSCENE_ITEM(CUTSCENE_ITEM_TYPE_CONCURRENT, concurrent, { \
|
||||
.items = (const cutsceneitem_t[]){ __VA_ARGS__ }, \
|
||||
.count = (uint8_t)( \
|
||||
sizeof((cutsceneitem_t[]){ __VA_ARGS__ }) / \
|
||||
sizeof(cutsceneitem_t) \
|
||||
) \
|
||||
})
|
||||
|
||||
/**
|
||||
* Static (const) data for a concurrent cutscene item.
|
||||
*/
|
||||
|
||||
@@ -8,6 +8,14 @@
|
||||
#pragma once
|
||||
#include "rpg/cutscene/item/cutsceneitembase.h"
|
||||
|
||||
/**
|
||||
* Blocks the cutscene here indefinitely - it never completes on its own,
|
||||
* only cutsceneGoTo (called externally, e.g. from a UI callback) can move
|
||||
* execution past it.
|
||||
*/
|
||||
#define CUTSCENE_IDLE() \
|
||||
{ .type = CUTSCENE_ITEM_TYPE_IDLE }
|
||||
|
||||
/**
|
||||
* Updates an idle item. Never completes on its own - the cutscene blocks
|
||||
* here indefinitely until something external (e.g. a UI callback) calls
|
||||
|
||||
@@ -12,6 +12,17 @@ typedef struct {
|
||||
const char_t *name;
|
||||
} cutscenemarker_t;
|
||||
|
||||
/**
|
||||
* A named, otherwise no-op position in the item list that cutsceneGoTo
|
||||
* can jump execution straight to.
|
||||
*
|
||||
* @param NAME Marker name, matched with stringEquals (not pointer
|
||||
* identity) - safe to use separate string literals with the same
|
||||
* contents at the marker and at each call site.
|
||||
*/
|
||||
#define CUTSCENE_MARKER(NAME) \
|
||||
CUTSCENE_ITEM(CUTSCENE_ITEM_TYPE_MARKER, marker, { .name = NAME })
|
||||
|
||||
/**
|
||||
* Starts a marker item. A marker does nothing on its own - it exists
|
||||
* purely as a named position for cutsceneGoTo to jump to.
|
||||
|
||||
@@ -8,6 +8,13 @@
|
||||
#pragma once
|
||||
#include "rpg/cutscene/item/cutsceneitembase.h"
|
||||
|
||||
/**
|
||||
* Restarts the currently running cutscene from its first item,
|
||||
* preserving whatever interact/interacted entities triggered it.
|
||||
*/
|
||||
#define CUTSCENE_RESTART() \
|
||||
{ .type = CUTSCENE_ITEM_TYPE_RESTART }
|
||||
|
||||
/**
|
||||
* Starts a restart item (restarts the currently running cutscene from
|
||||
* its first item via cutsceneRestart).
|
||||
|
||||
@@ -13,6 +13,17 @@ typedef struct {
|
||||
scenetype_t type;
|
||||
} cutscenescene_t;
|
||||
|
||||
/**
|
||||
* Requests a switch to a different SCENE_TYPE via sceneSet, then
|
||||
* immediately continues on to whatever follows this item - the switch
|
||||
* itself doesn't happen until the next sceneUpdate() tick, so it does
|
||||
* not take effect this frame.
|
||||
*
|
||||
* @param TYPE Target scenetype_t to switch to.
|
||||
*/
|
||||
#define CUTSCENE_SCENE(TYPE) \
|
||||
CUTSCENE_ITEM(CUTSCENE_ITEM_TYPE_SCENE, sceneChange, { .type = TYPE })
|
||||
|
||||
/**
|
||||
* Starts a scene item (requests a switch to the given scene via
|
||||
* sceneSet). The switch itself doesn't happen until the next
|
||||
|
||||
@@ -9,6 +9,14 @@
|
||||
#include "rpg/cutscene/cutscenepause.h"
|
||||
#include "rpg/cutscene/item/cutsceneitembase.h"
|
||||
|
||||
/**
|
||||
* Applies the given pause flags immediately.
|
||||
*
|
||||
* @param FLAGS CUTSCENE_PAUSE_* flags, OR'd together.
|
||||
*/
|
||||
#define CUTSCENE_SET_PAUSE(FLAGS) \
|
||||
CUTSCENE_ITEM(CUTSCENE_ITEM_TYPE_SET_PAUSE, setPause, (FLAGS))
|
||||
|
||||
/**
|
||||
* Starts a set-pause item (applies the new pause flags immediately).
|
||||
*
|
||||
|
||||
@@ -11,6 +11,14 @@
|
||||
typedef float_t cutscenewait_t;
|
||||
typedef float_t cutscenewaitdata_t;
|
||||
|
||||
/**
|
||||
* Waits WAIT seconds before continuing.
|
||||
*
|
||||
* @param WAIT Duration in seconds.
|
||||
*/
|
||||
#define CUTSCENE_WAIT(WAIT) \
|
||||
CUTSCENE_ITEM(CUTSCENE_ITEM_TYPE_WAIT, wait, WAIT)
|
||||
|
||||
/**
|
||||
* Starts a wait item (stores the duration in data).
|
||||
*
|
||||
|
||||
@@ -10,6 +10,15 @@
|
||||
|
||||
typedef void (*cutscenecallback_t)(void *userData);
|
||||
|
||||
/**
|
||||
* Invokes CALLBACK immediately, then continues on to whatever follows
|
||||
* this item.
|
||||
*
|
||||
* @param CALLBACK A cutscenecallback_t function pointer.
|
||||
*/
|
||||
#define CUTSCENE_CALLBACK(CALLBACK) \
|
||||
CUTSCENE_ITEM(CUTSCENE_ITEM_TYPE_CALLBACK, callback, CALLBACK)
|
||||
|
||||
/**
|
||||
* Starts a callback item (invokes the callback immediately).
|
||||
*
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "asset/assetfile.h"
|
||||
#include "asset/loader/assetloader.h"
|
||||
#include "util/string.h"
|
||||
#include "ui/overlay/uifatalerror.h"
|
||||
|
||||
cutsceneitemcallbacks_t CUTSCENE_ITEM_CALLBACKS[CUTSCENE_ITEM_TYPE_COUNT] = {
|
||||
[CUTSCENE_ITEM_TYPE_NULL] = { 0 },
|
||||
@@ -326,6 +327,12 @@ cutsceneitemcallbacks_t CUTSCENE_ITEM_CALLBACKS[CUTSCENE_ITEM_TYPE_COUNT] = {
|
||||
.update = cutsceneUIShowUpdate,
|
||||
.jsonName = "UI_SHOW",
|
||||
.load = cutsceneUIShowLoad
|
||||
},
|
||||
|
||||
[CUTSCENE_ITEM_TYPE_REGULAR_BATTLE] = {
|
||||
.update = cutsceneRegularBattleUpdate,
|
||||
.jsonName = "REGULAR_BATTLE",
|
||||
.load = cutsceneItemLoadNoop
|
||||
}
|
||||
};
|
||||
|
||||
@@ -364,7 +371,17 @@ void cutsceneCutsceneStart(
|
||||
const cutsceneitem_t *item,
|
||||
cutsceneitemdata_t *data
|
||||
) {
|
||||
if(item->cutscene != NULL) cutsceneSystemStartCutscene(item->cutscene);
|
||||
const cutscene_t *cutscene = item->cutsceneRef.cutscene;
|
||||
if(cutscene == NULL && item->cutsceneRef.name != NULL) {
|
||||
// Not cached back into item - with only one shared, fixed load buffer
|
||||
// (see cutscenesystem.h's CUTSCENE_LOADED_ITEMS_MAX doc comment),
|
||||
// every JSON-authored reference resolves to the same fixed address
|
||||
// every time anyway, and item itself lives inside that very buffer -
|
||||
// caching a pointer into it here would go stale (or, worse, get
|
||||
// clobbered mid-resolve) the moment a later load overwrites it.
|
||||
cutscene = cutsceneCutsceneResolve(item->cutsceneRef.name);
|
||||
}
|
||||
if(cutscene != NULL) cutsceneSystemStartCutscene(cutscene);
|
||||
}
|
||||
|
||||
bool_t cutsceneCutsceneUpdate(
|
||||
@@ -374,6 +391,24 @@ bool_t cutsceneCutsceneUpdate(
|
||||
return false;
|
||||
}
|
||||
|
||||
const cutscene_t * cutsceneCutsceneResolve(const char_t *name) {
|
||||
char_t path[ASSET_FILE_NAME_MAX];
|
||||
stringFormat(path, sizeof(path), "cutscenes/%s.jsonc", name);
|
||||
|
||||
assetentry_t *entry = assetLock(path, ASSET_LOADER_TYPE_CUTSCENE, NULL);
|
||||
errorret_t result = assetRequireLoaded(entry);
|
||||
// Released the instant loading finishes - see cutsceneSystemLoad's doc
|
||||
// comment for why nothing further depends on this entry once loaded.
|
||||
assetUnlockEntry(entry);
|
||||
if(errorIsNotOk(result)) {
|
||||
errorCatch(errorPrint(result));
|
||||
uiFatalErrorOpen(NULL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return &CUTSCENE_LOADED_SCENE;
|
||||
}
|
||||
|
||||
errorret_t cutsceneCutsceneLoad(
|
||||
yyjson_val *itemObj,
|
||||
cutsceneitem_t *item,
|
||||
@@ -385,23 +420,16 @@ errorret_t cutsceneCutsceneLoad(
|
||||
errorThrow("Cutscene item (CUTSCENE): missing 'name'");
|
||||
}
|
||||
|
||||
// Referenced cutscene is a sibling asset (assets/cutscenes/<name>.jsonc),
|
||||
// resolved to a stable pointer right now rather than deferred to
|
||||
// runtime - assetRequireLoaded re-enters assetUpdate() safely from
|
||||
// within this sync load (see its ASSET_ENTRY_STATE_LOADING_SYNC case),
|
||||
// and the entry is locked forever (never unlocked) so the pointer
|
||||
// stays valid for the process lifetime, same convention as
|
||||
// ui/screen/mainmenu/uimainmenu.c's MAIN_MENU_CUTSCENE_ENTRY.
|
||||
char_t path[ASSET_FILE_NAME_MAX];
|
||||
// Only validate that the eventual "cutscenes/<name>.jsonc" path would
|
||||
// fit - the reference itself is not resolved/locked until this item
|
||||
// actually runs (see cutsceneCutsceneStart/cutsceneCutsceneResolve).
|
||||
int32_t pathLen = stringFormat(NULL, 0, "cutscenes/%s.jsonc", name);
|
||||
if(pathLen < 0 || (size_t)pathLen >= ASSET_FILE_NAME_MAX) {
|
||||
errorThrow("Cutscene item (CUTSCENE): 'name' too long");
|
||||
}
|
||||
stringFormat(path, sizeof(path), "cutscenes/%s.jsonc", name);
|
||||
|
||||
assetentry_t *refEntry = assetLock(path, ASSET_LOADER_TYPE_CUTSCENE, NULL);
|
||||
errorChain(assetRequireLoaded(refEntry));
|
||||
item->cutscene = &refEntry->data.cutscene.cutscene;
|
||||
item->cutsceneRef.cutscene = NULL;
|
||||
item->cutsceneRef.name = name;
|
||||
|
||||
errorOk();
|
||||
}
|
||||
@@ -8,6 +8,7 @@
|
||||
#pragma once
|
||||
#include "error/error.h"
|
||||
#include "yyjson.h"
|
||||
#include "cutsceneitembase.h"
|
||||
#include "cutscenecallback.h"
|
||||
#include "cutsceneprint.h"
|
||||
#include "control/cutscenewait.h"
|
||||
@@ -41,6 +42,7 @@
|
||||
#include "battle/cutscenestartbattle.h"
|
||||
#include "battle/cutscenebattlewaitstate.h"
|
||||
#include "battle/cutscenebattleforceaction.h"
|
||||
#include "battle/cutsceneregularbattle.h"
|
||||
#include "save/cutscenesavedevicecheck.h"
|
||||
#include "save/cutscenesaveloadallslots.h"
|
||||
#include "audio/cutsceneaudioplay.h"
|
||||
@@ -55,58 +57,19 @@
|
||||
|
||||
typedef struct cutscene_s cutscene_t;
|
||||
|
||||
typedef enum {
|
||||
CUTSCENE_ITEM_TYPE_NULL,
|
||||
|
||||
CUTSCENE_ITEM_TYPE_TEXT,
|
||||
CUTSCENE_ITEM_TYPE_TEXT_MINI,
|
||||
CUTSCENE_ITEM_TYPE_TEXT_MINI_HIDE,
|
||||
CUTSCENE_ITEM_TYPE_CALLBACK,
|
||||
CUTSCENE_ITEM_TYPE_WAIT,
|
||||
CUTSCENE_ITEM_TYPE_CUTSCENE,
|
||||
CUTSCENE_ITEM_TYPE_ENTITY_TELEPORT,
|
||||
CUTSCENE_ITEM_TYPE_ENTITY_WALK_TO,
|
||||
CUTSCENE_ITEM_TYPE_FADE,
|
||||
CUTSCENE_ITEM_TYPE_SET_PAUSE,
|
||||
CUTSCENE_ITEM_TYPE_CONCURRENT,
|
||||
CUTSCENE_ITEM_TYPE_ITEM_GIVE,
|
||||
CUTSCENE_ITEM_TYPE_ENTITY_REMOVE,
|
||||
CUTSCENE_ITEM_TYPE_ENTITY_ADD,
|
||||
CUTSCENE_ITEM_TYPE_ENTITY_TURN,
|
||||
CUTSCENE_ITEM_TYPE_ENTITY_WALK_TO_ENTITY,
|
||||
CUTSCENE_ITEM_TYPE_MAP_AREA_ADD,
|
||||
CUTSCENE_ITEM_TYPE_MAP_AREA_REMOVE,
|
||||
CUTSCENE_ITEM_TYPE_MAP_AREA_WAIT,
|
||||
CUTSCENE_ITEM_TYPE_START_BATTLE,
|
||||
CUTSCENE_ITEM_TYPE_EMOJI,
|
||||
CUTSCENE_ITEM_TYPE_SHAKE,
|
||||
CUTSCENE_ITEM_TYPE_BATTLE_WAIT_STATE,
|
||||
CUTSCENE_ITEM_TYPE_BATTLE_FORCE_ACTION,
|
||||
CUTSCENE_ITEM_TYPE_MODAL,
|
||||
CUTSCENE_ITEM_TYPE_MODAL_OPTIONS_MARKERS,
|
||||
CUTSCENE_ITEM_TYPE_MODAL_CLOSE,
|
||||
CUTSCENE_ITEM_TYPE_PRINT,
|
||||
CUTSCENE_ITEM_TYPE_MARKER,
|
||||
CUTSCENE_ITEM_TYPE_RESTART,
|
||||
CUTSCENE_ITEM_TYPE_QUIT_GAME,
|
||||
CUTSCENE_ITEM_TYPE_SCENE,
|
||||
CUTSCENE_ITEM_TYPE_SAVE_DEVICE_CHECK,
|
||||
CUTSCENE_ITEM_TYPE_SAVE_LOAD_ALL_SLOTS,
|
||||
CUTSCENE_ITEM_TYPE_KEYBOARD,
|
||||
CUTSCENE_ITEM_TYPE_AUDIO_PLAY,
|
||||
CUTSCENE_ITEM_TYPE_AUDIO_STOP,
|
||||
CUTSCENE_ITEM_TYPE_AUDIO_PAUSE,
|
||||
CUTSCENE_ITEM_TYPE_AUDIO_RESUME,
|
||||
CUTSCENE_ITEM_TYPE_AUDIO_FADE,
|
||||
CUTSCENE_ITEM_TYPE_AUDIO_FADE_WAIT,
|
||||
CUTSCENE_ITEM_TYPE_AUDIO_SET_PAN,
|
||||
CUTSCENE_ITEM_TYPE_AUDIO_SET_LOOP,
|
||||
CUTSCENE_ITEM_TYPE_AUDIO_SET,
|
||||
CUTSCENE_ITEM_TYPE_IDLE,
|
||||
CUTSCENE_ITEM_TYPE_UI_SHOW,
|
||||
|
||||
CUTSCENE_ITEM_TYPE_COUNT
|
||||
} cutsceneitemtype_t;
|
||||
// A CUTSCENE item's target. C-authored cutscenes (the CUTSCENE_CUTSCENE
|
||||
// macro in cutscene.h) resolve cutscene at compile time and leave name
|
||||
// NULL. JSON-authored cutscenes (cutsceneCutsceneLoad) do the opposite -
|
||||
// only name is set at parse time, since resolving/locking the referenced
|
||||
// asset there would eagerly load every cutscene a cutscene merely
|
||||
// references, even ones never played. cutsceneCutsceneStart resolves
|
||||
// name to cutscene the first time this item actually runs (via
|
||||
// cutsceneCutsceneResolve) and caches the result back into this field so
|
||||
// replaying the same item never re-resolves it.
|
||||
typedef struct {
|
||||
const cutscene_t *cutscene;
|
||||
const char_t *name;
|
||||
} cutscenecutsceneref_t;
|
||||
|
||||
struct cutsceneitem_s {
|
||||
cutsceneitemtype_t type;
|
||||
@@ -117,7 +80,7 @@ struct cutsceneitem_s {
|
||||
cutscenetextminihide_t textMiniHide;
|
||||
cutscenecallback_t callback;
|
||||
cutscenewait_t wait;
|
||||
const cutscene_t *cutscene;
|
||||
cutscenecutsceneref_t cutsceneRef;
|
||||
cutsceneentityteleport_t entityTeleport;
|
||||
cutsceneentitywalkto_t entityWalkTo;
|
||||
cutscenefade_t fade;
|
||||
@@ -235,7 +198,9 @@ bool_t cutsceneItemLookupType(
|
||||
|
||||
/**
|
||||
* Starts a nested-cutscene item, handing control over to the
|
||||
* referenced cutscene.
|
||||
* referenced cutscene. If item->cutsceneRef.cutscene hasn't been
|
||||
* resolved yet (a JSON-authored reference, only known by name so far),
|
||||
* resolves and caches it first via cutsceneCutsceneResolve.
|
||||
*
|
||||
* @param item The cutscene item.
|
||||
* @param data Runtime data storage.
|
||||
@@ -245,6 +210,22 @@ void cutsceneCutsceneStart(
|
||||
cutsceneitemdata_t *data
|
||||
);
|
||||
|
||||
/**
|
||||
* Resolves a JSON-authored CUTSCENE item's referenced cutscene by name,
|
||||
* locking (forever - never unlocked, matching cutsceneCutsceneLoad's old
|
||||
* convention) and blocking on assets/cutscenes/<name>.jsonc. Called
|
||||
* lazily from cutsceneCutsceneStart the first time the item actually
|
||||
* runs, not at parse time, so a cutscene referencing many others doesn't
|
||||
* load every one of them up front. On failure, opens the fatal error
|
||||
* overlay (matching cutsceneSystemLoad's runtime-failure handling) and
|
||||
* returns NULL.
|
||||
*
|
||||
* @param name Bare cutscene name (without "cutscenes/" prefix or
|
||||
* ".jsonc" suffix).
|
||||
* @return The resolved cutscene, or NULL on failure.
|
||||
*/
|
||||
const cutscene_t * cutsceneCutsceneResolve(const char_t *name);
|
||||
|
||||
/**
|
||||
* Updates a nested-cutscene item. By the time this would run, control
|
||||
* has already moved on to the referenced cutscene, so this always
|
||||
@@ -262,10 +243,12 @@ bool_t cutsceneCutsceneUpdate(
|
||||
/**
|
||||
* Parses a CUTSCENE cutscene item's JSON fields into item. Kept inline here
|
||||
* (rather than its own file) since it's tightly bound to the asset/loader
|
||||
* system itself - it resolves its 'name' to a sibling
|
||||
* assets/cutscenes/<name>.jsonc asset at parse time, mirroring how
|
||||
* cutsceneCutsceneStart/cutsceneCutsceneUpdate stay inline in
|
||||
* cutsceneitem.c rather than getting their own file.
|
||||
* system itself. Only stores the 'name' string (which points into the
|
||||
* cutscene asset's still-alive yyjson doc, so no copy is needed) -
|
||||
* resolving it to the referenced assets/cutscenes/<name>.jsonc asset is
|
||||
* deferred to cutsceneCutsceneStart, the first time this item actually
|
||||
* runs, so a cutscene referencing many others doesn't pay to load every
|
||||
* one of them up front.
|
||||
*
|
||||
* @param itemObj The item's JSON object.
|
||||
* @param item Destination item, already zeroed by the caller.
|
||||
|
||||
@@ -13,6 +13,75 @@
|
||||
typedef struct cutsceneitem_s cutsceneitem_t;
|
||||
typedef union cutsceneitemdata_u cutsceneitemdata_t;
|
||||
|
||||
typedef enum {
|
||||
CUTSCENE_ITEM_TYPE_NULL,
|
||||
|
||||
CUTSCENE_ITEM_TYPE_TEXT,
|
||||
CUTSCENE_ITEM_TYPE_TEXT_MINI,
|
||||
CUTSCENE_ITEM_TYPE_TEXT_MINI_HIDE,
|
||||
CUTSCENE_ITEM_TYPE_CALLBACK,
|
||||
CUTSCENE_ITEM_TYPE_WAIT,
|
||||
CUTSCENE_ITEM_TYPE_CUTSCENE,
|
||||
CUTSCENE_ITEM_TYPE_ENTITY_TELEPORT,
|
||||
CUTSCENE_ITEM_TYPE_ENTITY_WALK_TO,
|
||||
CUTSCENE_ITEM_TYPE_FADE,
|
||||
CUTSCENE_ITEM_TYPE_SET_PAUSE,
|
||||
CUTSCENE_ITEM_TYPE_CONCURRENT,
|
||||
CUTSCENE_ITEM_TYPE_ITEM_GIVE,
|
||||
CUTSCENE_ITEM_TYPE_ENTITY_REMOVE,
|
||||
CUTSCENE_ITEM_TYPE_ENTITY_ADD,
|
||||
CUTSCENE_ITEM_TYPE_ENTITY_TURN,
|
||||
CUTSCENE_ITEM_TYPE_ENTITY_WALK_TO_ENTITY,
|
||||
CUTSCENE_ITEM_TYPE_MAP_AREA_ADD,
|
||||
CUTSCENE_ITEM_TYPE_MAP_AREA_REMOVE,
|
||||
CUTSCENE_ITEM_TYPE_MAP_AREA_WAIT,
|
||||
CUTSCENE_ITEM_TYPE_START_BATTLE,
|
||||
CUTSCENE_ITEM_TYPE_EMOJI,
|
||||
CUTSCENE_ITEM_TYPE_SHAKE,
|
||||
CUTSCENE_ITEM_TYPE_BATTLE_WAIT_STATE,
|
||||
CUTSCENE_ITEM_TYPE_BATTLE_FORCE_ACTION,
|
||||
CUTSCENE_ITEM_TYPE_MODAL,
|
||||
CUTSCENE_ITEM_TYPE_MODAL_OPTIONS_MARKERS,
|
||||
CUTSCENE_ITEM_TYPE_MODAL_CLOSE,
|
||||
CUTSCENE_ITEM_TYPE_PRINT,
|
||||
CUTSCENE_ITEM_TYPE_MARKER,
|
||||
CUTSCENE_ITEM_TYPE_RESTART,
|
||||
CUTSCENE_ITEM_TYPE_QUIT_GAME,
|
||||
CUTSCENE_ITEM_TYPE_SCENE,
|
||||
CUTSCENE_ITEM_TYPE_SAVE_DEVICE_CHECK,
|
||||
CUTSCENE_ITEM_TYPE_SAVE_LOAD_ALL_SLOTS,
|
||||
CUTSCENE_ITEM_TYPE_KEYBOARD,
|
||||
CUTSCENE_ITEM_TYPE_AUDIO_PLAY,
|
||||
CUTSCENE_ITEM_TYPE_AUDIO_STOP,
|
||||
CUTSCENE_ITEM_TYPE_AUDIO_PAUSE,
|
||||
CUTSCENE_ITEM_TYPE_AUDIO_RESUME,
|
||||
CUTSCENE_ITEM_TYPE_AUDIO_FADE,
|
||||
CUTSCENE_ITEM_TYPE_AUDIO_FADE_WAIT,
|
||||
CUTSCENE_ITEM_TYPE_AUDIO_SET_PAN,
|
||||
CUTSCENE_ITEM_TYPE_AUDIO_SET_LOOP,
|
||||
CUTSCENE_ITEM_TYPE_AUDIO_SET,
|
||||
CUTSCENE_ITEM_TYPE_IDLE,
|
||||
CUTSCENE_ITEM_TYPE_UI_SHOW,
|
||||
CUTSCENE_ITEM_TYPE_REGULAR_BATTLE,
|
||||
|
||||
CUTSCENE_ITEM_TYPE_COUNT
|
||||
} cutsceneitemtype_t;
|
||||
|
||||
/**
|
||||
* Shorthand for a cutsceneitem_t literal - used by each item type's own
|
||||
* authoring macro (e.g. CUTSCENE_WAIT in cutscenewait.h) to fill in .type
|
||||
* and its union member together.
|
||||
*
|
||||
* @param TYPE The item's CUTSCENE_ITEM_TYPE_* enum value.
|
||||
* @param UNION_NAME Name of the cutsceneitem_t union member to fill.
|
||||
* @param ... The union member's value. Passed through __VA_ARGS__ (rather
|
||||
* than a single named parameter) so it may itself be a brace initializer
|
||||
* with top-level commas, e.g.
|
||||
* CUTSCENE_ITEM(CUTSCENE_ITEM_TYPE_FADE, fade, { .from = A, .to = B }).
|
||||
*/
|
||||
#define CUTSCENE_ITEM(TYPE, UNION_NAME, ...) \
|
||||
{ .type = TYPE, .UNION_NAME = __VA_ARGS__ }
|
||||
|
||||
/**
|
||||
* Shared no-op Load for item types with no JSON fields of their own to
|
||||
* parse (IDLE, RESTART, MODAL_CLOSE) - always succeeds without touching
|
||||
|
||||
@@ -14,6 +14,14 @@ typedef struct {
|
||||
char_t text[CUTSCENE_PRINT_MAX_CHARS];
|
||||
} cutsceneprint_t;
|
||||
|
||||
/**
|
||||
* Prints TEXT to the console.
|
||||
*
|
||||
* @param TEXT Text to print.
|
||||
*/
|
||||
#define CUTSCENE_PRINT(TEXT) \
|
||||
CUTSCENE_ITEM(CUTSCENE_ITEM_TYPE_PRINT, print, { .text = TEXT })
|
||||
|
||||
/**
|
||||
* Starts a print item (prints the item's text to the console).
|
||||
*
|
||||
|
||||
@@ -15,6 +15,19 @@ typedef struct {
|
||||
worldpos_t position;
|
||||
} cutsceneentityadd_t;
|
||||
|
||||
/**
|
||||
* Spawns a new entity into the world immediately.
|
||||
*
|
||||
* @param TYPE Entity type to spawn.
|
||||
* @param X Spawn world X.
|
||||
* @param Y Spawn world Y.
|
||||
* @param Z Spawn world Z.
|
||||
*/
|
||||
#define CUTSCENE_ENTITY_ADD(TYPE, X, Y, Z) \
|
||||
CUTSCENE_ITEM(CUTSCENE_ITEM_TYPE_ENTITY_ADD, entityAdd, { \
|
||||
.entityType = TYPE, .position = { X, Y, Z } \
|
||||
})
|
||||
|
||||
/**
|
||||
* Starts an entity add step (spawns the entity into the world immediately).
|
||||
*
|
||||
|
||||
@@ -12,6 +12,16 @@ typedef struct {
|
||||
uint8_t entityIndex;
|
||||
} cutsceneentityremove_t;
|
||||
|
||||
/**
|
||||
* Removes an entity from the world immediately.
|
||||
*
|
||||
* @param ENTITY_INDEX Entity index to remove.
|
||||
*/
|
||||
#define CUTSCENE_ENTITY_REMOVE(ENTITY_INDEX) \
|
||||
CUTSCENE_ITEM(CUTSCENE_ITEM_TYPE_ENTITY_REMOVE, entityRemove, { \
|
||||
.entityIndex = ENTITY_INDEX \
|
||||
})
|
||||
|
||||
/**
|
||||
* Starts an entity remove step (removes the entity from the world immediately).
|
||||
*
|
||||
|
||||
@@ -14,6 +14,19 @@ typedef struct {
|
||||
worldpos_t target;
|
||||
} cutsceneentityteleport_t;
|
||||
|
||||
/**
|
||||
* Teleports an entity to a world position immediately.
|
||||
*
|
||||
* @param ENTITY_INDEX Entity index to teleport.
|
||||
* @param X Target world X.
|
||||
* @param Y Target world Y.
|
||||
* @param Z Target world Z.
|
||||
*/
|
||||
#define CUTSCENE_ENTITY_TELEPORT(ENTITY_INDEX, X, Y, Z) \
|
||||
CUTSCENE_ITEM(CUTSCENE_ITEM_TYPE_ENTITY_TELEPORT, entityTeleport, { \
|
||||
.entityIndex = ENTITY_INDEX, .target = { X, Y, Z } \
|
||||
})
|
||||
|
||||
/**
|
||||
* Starts an entity teleport item (teleports the entity immediately).
|
||||
*
|
||||
|
||||
@@ -14,6 +14,17 @@ typedef struct {
|
||||
entitydir_t direction;
|
||||
} cutsceneentityturn_t;
|
||||
|
||||
/**
|
||||
* Turns an entity to face a direction.
|
||||
*
|
||||
* @param ENTITY_INDEX Entity index to turn.
|
||||
* @param DIRECTION Target entitydir_t to face.
|
||||
*/
|
||||
#define CUTSCENE_ENTITY_TURN(ENTITY_INDEX, DIRECTION) \
|
||||
CUTSCENE_ITEM(CUTSCENE_ITEM_TYPE_ENTITY_TURN, entityTurn, { \
|
||||
.entityIndex = ENTITY_INDEX, .direction = DIRECTION \
|
||||
})
|
||||
|
||||
/**
|
||||
* Starts an entity turn step. The turn itself is driven from Update, since
|
||||
* the entity may still be finishing a previous action.
|
||||
|
||||
@@ -20,6 +20,45 @@ typedef struct {
|
||||
uint8_t currentIndex;
|
||||
} cutsceneentitywalktodata_t;
|
||||
|
||||
/**
|
||||
* Walks an entity to a single world position, navigating around
|
||||
* obstacles.
|
||||
*
|
||||
* @param ENTITY_INDEX Entity index to move.
|
||||
* @param X Target world X.
|
||||
* @param Y Target world Y.
|
||||
* @param Z Target world Z.
|
||||
*/
|
||||
#define CUTSCENE_ENTITY_WALK_TO(ENTITY_INDEX, X, Y, Z) \
|
||||
CUTSCENE_ITEM(CUTSCENE_ITEM_TYPE_ENTITY_WALK_TO, entityWalkTo, { \
|
||||
.entityIndex = ENTITY_INDEX, \
|
||||
.positions = (const worldpos_t[]){ { X, Y, Z } }, \
|
||||
.count = 1, \
|
||||
.walkAround = true \
|
||||
})
|
||||
|
||||
/**
|
||||
* Declares a standalone, named cutsceneitem_t (not a list entry) that
|
||||
* walks an entity through a fixed sequence of waypoints.
|
||||
*
|
||||
* @param NAME Suffix for the generated CUTSCENE_##NAME item/positions
|
||||
* statics.
|
||||
* @param ENTITY_INDEX Entity index to move.
|
||||
* @param ... One or more worldpos_t-shaped waypoint initializers, e.g.
|
||||
* { X, Y, Z }, { X2, Y2, Z2 }.
|
||||
*/
|
||||
#define CUTSCENE_ENTITY_WALK_PATH(NAME, ENTITY_INDEX, ...) \
|
||||
static const worldpos_t CUTSCENE_##NAME##_POSITIONS[] = { __VA_ARGS__ }; \
|
||||
static const cutsceneitem_t CUTSCENE_##NAME = { \
|
||||
.type = CUTSCENE_ITEM_TYPE_ENTITY_WALK_TO, \
|
||||
.entityWalkTo = { \
|
||||
.entityIndex = ENTITY_INDEX, \
|
||||
.positions = CUTSCENE_##NAME##_POSITIONS, \
|
||||
.count = sizeof(CUTSCENE_##NAME##_POSITIONS) / sizeof(worldpos_t), \
|
||||
.walkAround = true \
|
||||
} \
|
||||
};
|
||||
|
||||
/**
|
||||
* Starts an entity walk-to item (resets the waypoint index).
|
||||
*
|
||||
|
||||
@@ -16,6 +16,27 @@ typedef struct {
|
||||
worldunit_t offsetY;
|
||||
} cutsceneentitywalktoentity_t;
|
||||
|
||||
/**
|
||||
* Walks ENTITY_INDEX to stand beside TARGET_ENTITY_INDEX, offset by
|
||||
* (OFFSET_X, OFFSET_Y) on the 2D plane. The destination Z is resolved
|
||||
* from nearby terrain each frame, so ramps between the two entities are
|
||||
* accounted for automatically.
|
||||
*
|
||||
* @param ENTITY_INDEX Entity index to move.
|
||||
* @param TARGET_ENTITY_INDEX Entity index to walk toward.
|
||||
* @param OFFSET_X X offset from the target entity's position.
|
||||
* @param OFFSET_Y Y offset from the target entity's position.
|
||||
*/
|
||||
#define CUTSCENE_ENTITY_WALK_TO_ENTITY( \
|
||||
ENTITY_INDEX, TARGET_ENTITY_INDEX, OFFSET_X, OFFSET_Y \
|
||||
) \
|
||||
CUTSCENE_ITEM(CUTSCENE_ITEM_TYPE_ENTITY_WALK_TO_ENTITY, entityWalkToEntity, { \
|
||||
.entityIndex = ENTITY_INDEX, \
|
||||
.targetEntityIndex = TARGET_ENTITY_INDEX, \
|
||||
.offsetX = OFFSET_X, \
|
||||
.offsetY = OFFSET_Y \
|
||||
})
|
||||
|
||||
/**
|
||||
* Starts an entity walk-to-entity item. No setup is needed, the destination
|
||||
* is recomputed from the target's live position every Update.
|
||||
|
||||
@@ -14,6 +14,17 @@ typedef struct {
|
||||
uint8_t quantity;
|
||||
} cutsceneitemgive_t;
|
||||
|
||||
/**
|
||||
* Adds an item to the player's backpack immediately.
|
||||
*
|
||||
* @param ITEM_ID Item ID to give.
|
||||
* @param QUANTITY Quantity to give.
|
||||
*/
|
||||
#define CUTSCENE_ITEM_GIVE(ITEM_ID, QUANTITY) \
|
||||
CUTSCENE_ITEM(CUTSCENE_ITEM_TYPE_ITEM_GIVE, itemGive, { \
|
||||
.item = ITEM_ID, .quantity = QUANTITY \
|
||||
})
|
||||
|
||||
/**
|
||||
* Starts a give-item step (adds the item to the player's backpack immediately).
|
||||
*
|
||||
|
||||
@@ -16,6 +16,7 @@ target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
||||
cutscenejsonentitytype.c
|
||||
cutscenejsonentitydir.c
|
||||
cutscenejsonbattleencounter.c
|
||||
cutscenejsonbattleability.c
|
||||
cutscenejsonbattlestate.c
|
||||
cutscenejsonscenetype.c
|
||||
cutscenejsonuiscreentype.c
|
||||
|
||||
Loaded 100 of 172 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user