Remove rpg, ui, editor and scene subfolders; split scripts by platform

Delete src/dusk/rpg, src/dusk/ui, the animation/keyframe modules, the
scene subfolders, the chunk asset loader and ./editor, and strip the
dependent save slot, scene type, engine and test code so the main
binary and tests build again. Add scene/node.c/.h skeleton and move
build scripts into scripts/<platform>/.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
YourWishesandClaude Sonnet 5.5 committed 2026-11-03 07:29:25 -06:00
1 parent 3948607b1e
commit 31ee7989de
464 files changed
+70 -33009

No files matched your search

-2
View File
@@ -81,11 +81,9 @@ add_subdirectory(error)
add_subdirectory(input)
add_subdirectory(locale)
add_subdirectory(perf)
add_subdirectory(rpg)
add_subdirectory(scene)
add_subdirectory(system)
add_subdirectory(time)
add_subdirectory(ui)
add_subdirectory(save)
add_subdirectory(util)
add_subdirectory(thread)
-2
View File
@@ -6,6 +6,4 @@
target_sources(${DUSK_LIBRARY_TARGET_NAME}
PUBLIC
easing.c
animation.c
keyframe.c
)
-132
View File
@@ -1,132 +0,0 @@
// Copyright (c) 2026 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "animation.h"
#include "assert/assert.h"
#include "util/memory.h"
#include "util/math.h"
void animationInit(
animation_t *anim,
keyframe_t *keyframes,
uint16_t *keyframeCounts,
const uint16_t layerCount
) {
assertNotNull(anim, "Animation pointer cannot be null.");
assertNotNull(keyframes, "Keyframes pointer cannot be null.");
assertNotNull(keyframeCounts, "Keyframe counts pointer cannot be null.");
assertTrue(layerCount > 0, "Layer count must be greater than zero.");
memoryZero(anim, sizeof(animation_t));
anim->keyframes = keyframes;
anim->keyframeCounts = keyframeCounts;
anim->layerCount = layerCount;
// Determine duration
float_t duration = 0.0f;
for(uint16_t layer = 0; layer < layerCount; layer++) {
uint16_t keyframeCount = keyframeCounts[layer];
assertTrue(keyframeCount > 0, "Keyframe count invalid.");
keyframe_t *layerKeyframes = keyframes + layer * keyframeCount;
#ifdef DUSK_ASSERTIONS
// Check that the keyframes are sorted by time.
for(uint16_t i = 1; i < keyframeCount; i++) {
assertTrue(
layerKeyframes[i].time >= layerKeyframes[i - 1].time,
"Keyframes must be sorted by time."
);
}
#endif
keyframe_t *lastKeyframe = layerKeyframes + keyframeCount - 1;
duration = mathMax(duration, lastKeyframe->time);
}
assertTrue(duration > 0, "Animation duration must be greater than 0.");
anim->duration = duration;
}
float_t animationGetLayerValue(const animation_t *anim, const uint16_t layer) {
assertNotNull(anim, "Animation pointer cannot be null.");
assertTrue(layer < anim->layerCount, "Layer index out of bounds.");
uint16_t keyframeCount = anim->keyframeCounts[layer];
keyframe_t *layerKeyframes = anim->keyframes + layer * keyframeCount;
return keyframeGetValue(layerKeyframes, keyframeCount, anim->time);
}
void animationUpdate(
animation_t *anim,
const float_t deltaTime
) {
assertNotNull(anim, "Animation pointer cannot be null.");
assertTrue(deltaTime >= 0, "Delta time must be non-negative.");
bool_t justCompleted = false;
if(!(anim->flags & ANIMATION_FLAG_INTERNAL_COMPLETED)) {
bool_t loop = (anim->flags & ANIMATION_FLAG_LOOP) != 0;
bool_t pingpong = (anim->flags & ANIMATION_FLAG_PINGPONG) != 0;
assertFalse(
loop && pingpong,
"Cannot set both ANIMATION_FLAG_LOOP and ANIMATION_FLAG_PINGPONG."
);
bool_t backward;
if(pingpong) {
backward = (anim->flags & ANIMATION_FLAG_INTERNAL_PINGPONG_BACKWARD) != 0;
} else {
backward = (anim->flags & ANIMATION_FLAG_REVERSE) != 0;
}
// Resolve boundary crossings one at a time, so a single large deltaTime
// can correctly loop/pingpong across multiple boundaries in one call.
float_t remaining = deltaTime;
while(remaining > 0.0f) {
float_t toBoundary = (
backward ? anim->time : (anim->duration - anim->time)
);
if(remaining < toBoundary) {
anim->time += backward ? -remaining : remaining;
break;
}
remaining -= toBoundary;
anim->time = backward ? 0.0f : anim->duration;
bool_t stopHere;
if(backward) {
stopHere = (anim->flags & ANIMATION_FLAG_STOP_BEGINNING) != 0;
} else {
stopHere = (anim->flags & ANIMATION_FLAG_STOP_END) != 0;
}
if(stopHere) {
justCompleted = true;
break;
} else if(pingpong) {
backward = !backward;
if(backward) anim->flags |= ANIMATION_FLAG_INTERNAL_PINGPONG_BACKWARD;
else anim->flags &= ~ANIMATION_FLAG_INTERNAL_PINGPONG_BACKWARD;
} else if(loop) {
anim->time = backward ? anim->duration : 0.0f;
if(anim->onLoop) anim->onLoop(anim->user);
} else {
justCompleted = true;
break;
}
}
if(justCompleted) anim->flags |= ANIMATION_FLAG_INTERNAL_COMPLETED;
}
// Call onUpdate for each layer.
for(uint16_t layer = 0; layer < anim->layerCount; layer++) {
float_t value = animationGetLayerValue(anim, layer);
if(anim->onUpdate) anim->onUpdate(layer, value, anim->user);
}
if(justCompleted && anim->onComplete) anim->onComplete(anim->user);
}
-94
View File
@@ -1,94 +0,0 @@
// Copyright (c) 2026 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "keyframe.h"
#define ANIMATION_FLAG_LOOP (1 << 0)
#define ANIMATION_FLAG_REVERSE (1 << 1)
#define ANIMATION_FLAG_PINGPONG (1 << 2)
#define ANIMATION_FLAG_STOP_BEGINNING (1 << 3)
#define ANIMATION_FLAG_STOP_END (1 << 4)
// Internal - tracks which direction a pingponging animation is currently
// travelling. Do not set this manually, it is managed by animationUpdate().
#define ANIMATION_FLAG_INTERNAL_PINGPONG_BACKWARD (1 << 7)
// Internal - set once the animation has stopped advancing (see
// animationUpdate()). Do not set this manually. There is currently no way to
// restart a completed animation short of clearing this bit and resetting
// anim->time by hand.
#define ANIMATION_FLAG_INTERNAL_COMPLETED (1 << 6)
typedef struct {
keyframe_t *keyframes;
uint16_t *keyframeCounts;
uint16_t layerCount;
float_t time;
float_t duration;
uint8_t flags;
void *user;
void (*onUpdate)(const uint16_t layer, const float_t value, void *user);
void (*onComplete)(void *user);
void (*onLoop)(void *user);
} animation_t;
/**
* Initializes an animation with the given keyframes and layer count.
*
* @param anim Pointer to the animation to initialize.
* @param keyframes Pointer to the array of keyframes for each layer.
* @param keyframeCount Number of keyframes in each layer.
* @param layerCount Number of layers in the animation.
*/
void animationInit(
animation_t *anim,
keyframe_t *keyframes,
uint16_t *keyframeCounts,
const uint16_t layerCount
);
/**
* Sets the current time of the animation, clamping it to the valid range.
* This will call the onUpdate callback but none of the other callbacks.
*
* @param anim Pointer to the animation to set the time for.
* @param time The new time to set for the animation.
*/
void animationSetTime(animation_t *anim, const float_t time);
/**
* Gets the current value of a specific layer in the animation based on the
* current animation time.
*/
float_t animationGetLayerValue(const animation_t *anim, const uint16_t layer);
/**
* Updates the animation state based on the elapsed time. Advances anim->time
* by deltaTime (or against it, if ANIMATION_FLAG_REVERSE is set), then
* resolves whatever happens when it reaches the 0 or duration boundary:
*
* - ANIMATION_FLAG_PINGPONG: reflects off the boundary and continues playing
* in the opposite direction, forever, unless stopped (see below).
* - ANIMATION_FLAG_LOOP: wraps back around to the other boundary and keeps
* playing in the same direction, forever, unless stopped (see below).
* - ANIMATION_FLAG_STOP_BEGINNING / ANIMATION_FLAG_STOP_END: when the
* animation reaches that specific boundary, it clamps there and stops
* (firing onComplete) instead of looping/pingponging past it.
* - If none of the above apply at a boundary, the animation clamps there and
* stops, firing onComplete.
*
* onUpdate is called for every layer on every call. onLoop is called each
* time a loop wraps around. onComplete is called at most once, the moment
* the animation stops advancing.
*
* @param anim Pointer to the animation to update.
* @param deltaTime Time elapsed since the last update (in seconds).
*/
void animationUpdate(
animation_t *anim,
const float_t deltaTime
);
-45
View File
@@ -1,45 +0,0 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "keyframe.h"
#include "assert/assert.h"
#include "util/math.h"
float_t keyframeGetValue(
const keyframe_t *keyframes,
const uint32_t keyframeCount,
const float_t time
) {
assertNotNull(keyframes, "Keyframes pointer cannot be null.");
assertTrue(keyframeCount > 0, "Keyframe count must be more than 0.");
assertTrue(time >= 0, "Time must be non-negative.");
#ifdef DUSK_ASSERTIONS
// Checks that the keyframes are sorted by time.
for(uint32_t i = 1; i < keyframeCount; i++) {
assertTrue(
keyframes[i].time >= keyframes[i - 1].time,
"Keyframes must be sorted by time."
);
}
#endif
keyframe_t *last = (keyframe_t *)(keyframes + keyframeCount - 1);
if(time >= last->time) return last->value;
// Since time < last->time (checked above), current is guaranteed to stop
// at or before reaching last, so no separate end-of-array check is needed.
keyframe_t *current = (keyframe_t *)keyframes;
keyframe_t *start = current;
while(current->time <= time) {
start = current;
current++;
}
keyframe_t *end = current;
float_t t = (time - start->time) / (end->time - start->time);
return mathLerp(start->value, end->value, easingApply(start->easing, t));
}
-27
View File
@@ -1,27 +0,0 @@
// Copyright (c) 2026 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "easing.h"
typedef struct {
float_t time;
float_t value;
easingtype_t easing;
} keyframe_t;
/**
* Gets the value of a keyframe at a given time.
*
* @param keyframes The keyframes to get the value from.
* @param keyframeCount The number of keyframes in the array.
* @param time The time at which to get the value, in seconds.
* @return The value of the keyframe at the given time.
*/
float_t keyframeGetValue(
const keyframe_t *keyframes,
const uint32_t keyframeCount,
const float_t time
);
-1
View File
@@ -15,7 +15,6 @@ target_sources(${DUSK_LIBRARY_TARGET_NAME}
add_subdirectory(display)
add_subdirectory(locale)
add_subdirectory(json)
add_subdirectory(chunk)
add_subdirectory(dmf)
add_subdirectory(wav)
add_subdirectory(mp3)
-6
View File
@@ -46,12 +46,6 @@ assetloadercallbacks_t ASSET_LOADER_CALLBACKS[ASSET_LOADER_TYPE_COUNT] = {
.dispose = assetJsonDispose
},
[ASSET_LOADER_TYPE_CHUNK] = {
.loadSync = assetChunkLoaderSync,
.loadAsync = assetChunkLoaderAsync,
.dispose = assetChunkDispose
},
[ASSET_LOADER_TYPE_WAV] = {
.loadSync = assetWavLoaderSync,
.loadAsync = assetWavLoaderAsync,
-5
View File
@@ -12,7 +12,6 @@
#include "asset/loader/display/assettilesetloader.h"
#include "asset/loader/locale/assetlocaleloader.h"
#include "asset/loader/json/assetjsonloader.h"
#include "asset/loader/chunk/assetchunkloader.h"
#include "asset/loader/wav/assetwavloader.h"
#include "asset/loader/mp3/assetmp3loader.h"
@@ -25,7 +24,6 @@ typedef enum {
ASSET_LOADER_TYPE_TILESET,
ASSET_LOADER_TYPE_LOCALE,
ASSET_LOADER_TYPE_JSON,
ASSET_LOADER_TYPE_CHUNK,
ASSET_LOADER_TYPE_WAV,
ASSET_LOADER_TYPE_MP3,
@@ -39,7 +37,6 @@ typedef union {
assettilesetloaderloading_t tileset;
assetlocaleloaderloading_t locale;
assetjsonloaderloading_t json;
assetchunkloaderloading_t chunk;
assetwavloaderloading_t wav;
assetmp3loaderloading_t mp3;
} assetloaderloading_t;
@@ -51,7 +48,6 @@ typedef union {
assettilesetoutput_t tileset;
assetlocaleoutput_t locale;
assetjsonoutput_t json;
assetchunkoutput_t chunk;
assetwavoutput_t wav;
assetmp3output_t mp3;
} assetloaderoutput_t;
@@ -61,7 +57,6 @@ typedef union {
assettilesetloaderinput_t tileset;
assetlocaleloaderinput_t locale;
assetjsonloaderinput_t json;
assetchunkloaderinput_t chunk;
assetwavloaderinput_t wav;
assetmp3loaderinput_t mp3;
} assetloaderinput_t;
@@ -1,10 +0,0 @@
# Copyright (c) 2026 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
# Sources
target_sources(${DUSK_LIBRARY_TARGET_NAME}
PUBLIC
assetchunkloader.c
)
@@ -1,484 +0,0 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "assetchunkloader.h"
#include "assert/assert.h"
#include "util/memory.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/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();
}
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
);
}
}
assertTrue(vertCount > 0, "Terrain build called with no terrain tiles.");
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;
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
errorOk();
}
errorret_t assetChunkLoaderSync(assetloading_t *loading) {
assertNotNull(loading, "Loading cannot be NULL");
assertTrue(loading->type == ASSET_LOADER_TYPE_CHUNK, "Invalid type.");
assertIsMainThread("Must be called from the main thread.");
assetchunkoutput_t *out = &loading->entry->data.chunk;
switch(loading->loading.chunk.state) {
case ASSET_CHUNK_LOADING_STATE_INITIAL:
loading->loading.chunk.state = ASSET_CHUNK_LOADING_STATE_PARSE;
loading->entry->state = ASSET_ENTRY_STATE_PENDING_SYNC;
errorOk();
case ASSET_CHUNK_LOADING_STATE_PARSE:
break;
case ASSET_CHUNK_LOADING_STATE_LOAD_MODELS:
while(loading->loading.chunk.modelIndex < out->meshCount) {
uint8_t m = loading->loading.chunk.modelIndex;
if(out->modelEntries[m] == NULL) {
out->modelEntries[m] = assetLock(
out->modelNames[m], ASSET_LOADER_TYPE_MODEL, NULL
);
assertNotNull(out->modelEntries[m], "Failed to lock model.");
loading->entry->state = ASSET_ENTRY_STATE_PENDING_SYNC;
errorOk();
}
if(out->modelEntries[m]->state == ASSET_ENTRY_STATE_ERROR) {
assetLoaderErrorThrow(
loading, "Model failed to load: %s", out->modelNames[m]
);
}
if(out->modelEntries[m]->state != ASSET_ENTRY_STATE_LOADED) {
loading->entry->state = ASSET_ENTRY_STATE_PENDING_SYNC;
errorOk();
}
loading->loading.chunk.modelIndex++;
}
loading->entry->state = ASSET_ENTRY_STATE_LOADED;
errorOk();
default:
errorOk();
}
// --- 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, "Failed to load chunk JSON: %s", loading->entry->name
);
}
yyjson_val *root = yyjson_doc_get_root(jsonEntry->data.json);
tile_t tiles[CHUNK_TILE_COUNT];
assetChunkParseTiles(root, tiles);
out->hasTerrain = assetChunkTilesHaveTerrain(tiles);
uint8_t meshIndex = out->hasTerrain ? 1 : 0;
assetChunkParseMeshes(root, out, &meshIndex);
out->meshCount = meshIndex;
assetChunkParseEntities(root, out);
assetChunkParseAreas(root, out);
assetUnlockEntry(jsonEntry);
out->tiles = memoryAllocate(CHUNK_TILE_COUNT * sizeof(tile_t));
memoryCopy(out->tiles, tiles, CHUNK_TILE_COUNT * sizeof(tile_t));
// 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
);
}
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;
}
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 = out->hasTerrain ? 1 : 0;
loading->entry->state = ASSET_ENTRY_STATE_PENDING_SYNC;
errorOk();
}
errorret_t assetChunkDispose(assetentry_t *entry) {
assertNotNull(entry, "Entry cannot be NULL");
assertTrue(entry->type == ASSET_LOADER_TYPE_CHUNK, "Invalid type.");
assertIsMainThread("Must be called from the main thread.");
assetchunkoutput_t *out = &entry->data.chunk;
if(out->tiles != NULL) {
memoryFree(out->tiles);
out->tiles = NULL;
}
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();
}
@@ -1,120 +0,0 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "asset/assetfile.h"
#include "rpg/overworld/chunk.h"
typedef struct assetloading_s assetloading_t;
typedef struct assetentry_s assetentry_t;
typedef struct {
void *nothing;
} assetchunkloaderinput_t;
typedef enum {
ASSET_CHUNK_LOADING_STATE_INITIAL,
ASSET_CHUNK_LOADING_STATE_PARSE,
ASSET_CHUNK_LOADING_STATE_LOAD_MODELS,
ASSET_CHUNK_LOADING_STATE_DONE
} assetchunkloadingstate_t;
typedef struct {
assetchunkloadingstate_t state;
// 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;
typedef enum {
CHUNK_ENTITY_SPAWN_KIND_GLOBAL,
CHUNK_ENTITY_SPAWN_KIND_ITEM
} chunkentityspawnkind_t;
typedef struct {
chunkentityspawnkind_t kind;
uint16_t globalId; // Valid when kind == CHUNK_ENTITY_SPAWN_KIND_GLOBAL.
uint16_t itemId; // Valid when kind == CHUNK_ENTITY_SPAWN_KIND_ITEM.
uint8_t itemQuantity; // Valid when kind == CHUNK_ENTITY_SPAWN_KIND_ITEM.
worldpos_t position;
} chunkentityspawn_t;
typedef struct {
worldpos_t min;
worldpos_t max;
uint16_t callbackId; // Index into MAP_AREA_CALLBACK_LIST.
uint8_t notify;
uint8_t trigger;
} chunkareaspawn_t;
typedef struct {
tile_t *tiles;
uint8_t meshCount;
char_t modelNames[CHUNK_MESH_COUNT_MAX][CHUNK_MESH_NAME_MAX];
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];
uint8_t areaSpawnCount;
chunkareaspawn_t areaSpawns[CHUNK_AREA_COUNT_MAX];
} assetchunkoutput_t;
/**
* 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.
*/
errorret_t assetChunkLoaderAsync(assetloading_t *loading);
/**
* 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.
*/
errorret_t assetChunkLoaderSync(assetloading_t *loading);
/**
* Disposer for chunk assets.
*
* @param entry Asset entry containing the chunk data to dispose.
* @return Error code indicating success or failure of the dispose operation.
*/
errorret_t assetChunkDispose(assetentry_t *entry);
-1
View File
@@ -16,7 +16,6 @@
#include "display/mesh/capsule.h"
#include "display/mesh/triprism.h"
#include "display/screen/screen.h"
#include "ui/ui.h"
#include "display/text/text.h"
#include "assert/assert.h"
#include "util/memory.h"
-9
View File
@@ -11,11 +11,9 @@
#include "time/time.h"
#include "input/input.h"
#include "locale/localemanager.h"
#include "rpg/rpg.h"
#include "display/display.h"
#include "scene/scene.h"
#include "asset/asset.h"
#include "ui/ui.h"
#include "assert/assert.h"
#ifdef DUSK_NETWORK
#include "network/network.h"
@@ -47,8 +45,6 @@ errorret_t engineInit(const int32_t argc, const char_t **argv) {
errorChain(localeManagerInit());
errorChain(displayInit());
errorChain(audioInit());
errorChain(rpgInit());
errorChain(uiInit());
#ifdef DUSK_NETWORK
errorChain(networkInit());
#endif
@@ -62,7 +58,6 @@ errorret_t engineInit(const int32_t argc, const char_t **argv) {
consolePrint("Assertions real");
#endif
sceneSet(SCENE_TYPE_INITIAL);
errorOk();
}
@@ -77,10 +72,8 @@ errorret_t engineUpdate(void) {
inputUpdate();
consoleUpdate();
errorChain(audioUpdateEarly());
errorChain(rpgUpdate());
errorChain(sceneUpdate());
errorChain(assetUpdate());
errorChain(uiUpdate());
// Render
errorChain(displayUpdate());
@@ -98,9 +91,7 @@ errorret_t engineDispose(void) {
#ifdef DUSK_NETWORK
errorChain(networkDispose());
#endif
errorChain(rpgDispose());
localeManagerDispose();
errorChain(uiDispose());
errorChain(audioDispose());
consoleDispose();
errorChain(displayDispose());
-4
View File
@@ -9,7 +9,6 @@
#include "util/memory.h"
#include "util/string.h"
#include "assert/assert.h"
#include "ui/ui.h"
#include "system/system.h"
#include "console/console.h"
@@ -39,9 +38,6 @@ errorret_t localeManagerSetLocale(const localeinfo_t *locale) {
assetEntryLock(LOCALE.entry);
errorChain(assetRequireLoaded(LOCALE.entry));
// TODO : Trigger UI update.
errorChain(uiUpdateTranslations());
errorOk();
}
-20
View File
@@ -1,20 +0,0 @@
# Copyright (c) 2025 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
# Sources
target_sources(${DUSK_LIBRARY_TARGET_NAME}
PUBLIC
rpg.c
rpgcamera.c
)
# Subdirs
add_subdirectory(battle)
add_subdirectory(cutscene)
add_subdirectory(entity)
add_subdirectory(overworld)
add_subdirectory(story)
add_subdirectory(item)
-15
View File
@@ -1,15 +0,0 @@
# Copyright (c) 2026 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
# Sources
target_sources(${DUSK_LIBRARY_TARGET_NAME}
PUBLIC
battle.c
party.c
)
add_subdirectory(fighter)
add_subdirectory(move)
add_subdirectory(state)
-79
View File
@@ -1,79 +0,0 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "battle.h"
#include "assert/assert.h"
#include "util/memory.h"
#include "rpg/cutscene/cutscenesystem.h"
#include "scene/scene.h"
battle_t BATTLE;
void battleInit(void) {
memoryZero(&BATTLE, sizeof(battle_t));
}
void battleStart(
battlefighter_t *fighters[BATTLE_FIGHTER_POS_COUNT]
) {
assertNotNull(fighters, "Fighters cannot be NULL");
#if DUSK_ASSERTIONS
// Must be at least two non null fighter present, may need to ensure they
// are from seperate teams also.
uint8_t nonNullCount = 0;
for(uint8_t i = 0; i < BATTLE_FIGHTER_POS_COUNT; i++) {
if(fighters[i] != NULL) nonNullCount++;
}
assertTrue(nonNullCount >= 2, "Must have at least two fighters");
#endif
// TODO: I may not need to zero entire battle.
memoryZero(&BATTLE, sizeof(battle_t));
memoryCopy(
BATTLE.fighters,
fighters,
sizeof(battlefighter_t *) * BATTLE_FIGHTER_POS_COUNT
);
// Enter the opening state.
battleSetState(BATTLE_STATE_OPENING);
// Change scene
sceneSet(SCENE_TYPE_BATTLE);
}
void battleSetState(const battlestate_t next) {
assertTrue(next < BATTLE_STATE_COUNT, "Invalid battle state");
assertNotNull(BATTLE_STATE_FUNCTIONS[next].init, "Missing state init function");
assertNotNull(BATTLE_STATE_FUNCTIONS[next].update, "Missing state update function");
assertNotNull(BATTLE_STATE_FUNCTIONS[next].dispose, "Missing state dispose function");
if(BATTLE.state != BATTLE_STATE_NULL) {
BATTLE_STATE_FUNCTIONS[BATTLE.state].dispose();
}
BATTLE.state = next;
BATTLE_STATE_FUNCTIONS[BATTLE.state].init();
}
void battleUpdate(void) {
if(BATTLE.state == BATTLE_STATE_NULL) return;
assertTrue(BATTLE.state < BATTLE_STATE_COUNT, "Invalid battle state");
assertNotNull(BATTLE_STATE_FUNCTIONS[BATTLE.state].update, "Missing state update function");
BATTLE_STATE_FUNCTIONS[BATTLE.state].update();
}
void battleDispose(void) {
if(BATTLE.state == BATTLE_STATE_NULL) return;
assertTrue(BATTLE.state < BATTLE_STATE_COUNT, "Invalid battle state");
assertNotNull(BATTLE_STATE_FUNCTIONS[BATTLE.state].dispose, "Missing state dispose function");
BATTLE_STATE_FUNCTIONS[BATTLE.state].dispose();
memoryZero(&BATTLE, sizeof(battle_t));
}
-75
View File
@@ -1,75 +0,0 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "rpg/battle/fighter/battlefighter.h"
#include "rpg/battle/move/battlemove.h"
#include "rpg/battle/move/battlemoveaction.h"
#include "rpg/battle/fighter/battlefighterpos.h"
#include "rpg/battle/state/battlestate.h"
typedef enum {
BATTLE_RESULT_NONE,
BATTLE_RESULT_WIN,
BATTLE_RESULT_LOSS,
BATTLE_RESULT_FLED,
BATTLE_RESULT_COUNT
} battleresult_t;
typedef struct {
battlefighter_t *fighters[BATTLE_FIGHTER_POS_COUNT];
// Order of who gets to act.
uint8_t fighterOrder[BATTLE_FIGHTER_POS_COUNT];
uint8_t fighterOrderCount;
// Actions to be executed.
battlemoveaction_t actionsPending[BATTLE_FIGHTER_POS_COUNT];
uint8_t actionsPendingCount;
battlestate_t state;
battlestatedata_t stateData;
// Set once a side has been wiped out (see cutsceneBattlePostMoveStart)
// or the player has fled (see battleStateSelectionPlayerFlee). Stays
// BATTLE_RESULT_NONE for the rest of the battle otherwise.
battleresult_t result;
} battle_t;
extern battle_t BATTLE;
/**
* Initializes the battle system. Marks it as inactive with no fighters.
*/
void battleInit(void);
/**
* Starts a battle.
*
* @param fighters Fighters in the battle.
*/
void battleStart(
battlefighter_t *fighters[BATTLE_FIGHTER_POS_COUNT]
);
/**
* Transitions the battle to a new state: disposes the current state (if
* any) and initializes next.
*
* @param next The state to transition to.
*/
void battleSetState(const battlestate_t next);
/**
* Updates the battle system.
*/
void battleUpdate(void);
/**
* Disposes of the battle, clearing all fighters and marking it inactive.
*/
void battleDispose(void);
@@ -1,10 +0,0 @@
# Copyright (c) 2026 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
# Sources
target_sources(${DUSK_LIBRARY_TARGET_NAME}
PUBLIC
battlefighter.c
)
-230
View File
@@ -1,230 +0,0 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "battlefighter.h"
#include "assert/assert.h"
#include "util/memory.h"
errorret_t battleFighterParseStatField(
yyjson_val *obj,
const char_t *key,
uint16_t *out
) {
yyjson_val *val = yyjson_obj_get(obj, key);
if(!yyjson_is_int(val)) {
errorThrow("Fighter: missing/invalid '%s'", key);
}
const int64_t num = yyjson_get_sint(val);
if(num < 0 || num > UINT16_MAX) {
errorThrow("Fighter: '%s' must be between 0 and %u", key, UINT16_MAX);
}
*out = (uint16_t)num;
errorOk();
}
errorret_t battleFighterParseOptionalIntField(
yyjson_val *obj,
const char_t *key,
const int32_t defaultValue,
int32_t *out
) {
yyjson_val *val = yyjson_obj_get(obj, key);
if(val == NULL) {
*out = defaultValue;
errorOk();
}
if(!yyjson_is_int(val)) errorThrow("Fighter: invalid '%s'", key);
*out = (int32_t)yyjson_get_sint(val);
errorOk();
}
errorret_t battleFighterParse(battlefighter_t *fighter, yyjson_val *obj) {
assertNotNull(fighter, "Fighter cannot be NULL");
assertNotNull(obj, "JSON object cannot be NULL");
int32_t teamNum;
errorChain(battleFighterParseOptionalIntField(
obj, "team", BATTLE_FIGHTER_TEAM_ALLY, &teamNum
));
if(teamNum < 0 || teamNum >= BATTLE_FIGHTER_TEAM_COUNT) {
errorThrow("Fighter: invalid 'team'");
}
int32_t controllerNum;
errorChain(battleFighterParseOptionalIntField(
obj, "controller", BATTLE_FIGHTER_CONTROLLER_PLAYER, &controllerNum
));
if(controllerNum < 0 || controllerNum >= BATTLE_FIGHTER_CONTROLLER_COUNT) {
errorThrow("Fighter: invalid 'controller'");
}
battlefighterstats_t stats;
errorChain(battleFighterParseStatField(obj, "attack", &stats.attack));
errorChain(battleFighterParseStatField(obj, "defense", &stats.defense));
errorChain(battleFighterParseStatField(obj, "magic", &stats.magic));
errorChain(battleFighterParseStatField(obj, "speed", &stats.speed));
errorChain(battleFighterParseStatField(obj, "luck", &stats.luck));
errorChain(battleFighterParseStatField(obj, "healthMax", &stats.healthMax));
errorChain(battleFighterParseStatField(obj, "mpMax", &stats.mpMax));
battleFighterInit(
fighter, (battlefighterteam_t)teamNum,
(battlefightercontroller_t)controllerNum, stats
);
int32_t statusNum;
errorChain(battleFighterParseOptionalIntField(
obj, "status", BATTLE_FIGHTER_STATUS_NORMAL, &statusNum
));
if(statusNum < 0 || statusNum >= BATTLE_FIGHTER_STATUS_COUNT) {
errorThrow("Fighter: invalid 'status'");
}
fighter->status = (battlefighterstatus_t)statusNum;
int32_t health;
errorChain(
battleFighterParseOptionalIntField(obj, "health", stats.healthMax, &health)
);
if(health < 0 || health > stats.healthMax) {
errorThrow("Fighter: 'health' out of range");
}
fighter->stats.health = (uint16_t)health;
int32_t mp;
errorChain(battleFighterParseOptionalIntField(obj, "mp", stats.mpMax, &mp));
if(mp < 0 || mp > stats.mpMax) {
errorThrow("Fighter: 'mp' out of range");
}
fighter->stats.mp = (uint16_t)mp;
yyjson_val *abilities = yyjson_obj_get(obj, "abilities");
if(abilities != NULL) {
if(
!yyjson_is_arr(abilities) ||
yyjson_arr_size(abilities) > BATTLE_FIGHTER_ABILITY_COUNT_MAX
) {
errorThrow(
"Fighter: 'abilities' must have 0-%u entries",
BATTLE_FIGHTER_ABILITY_COUNT_MAX
);
}
yyjson_arr_iter iter = yyjson_arr_iter_with(abilities);
yyjson_val *abilityVal;
while((abilityVal = yyjson_arr_iter_next(&iter)) != NULL) {
const char_t *name = yyjson_get_str(abilityVal);
battlemoveid_t ability =
name == NULL ? BATTLE_MOVE_ID_NULL : battleMoveGetIdByName(name);
if(ability == BATTLE_MOVE_ID_NULL) {
errorThrow("Fighter: invalid entry in 'abilities'");
}
battleFighterAbilityAdd(fighter, ability);
}
}
errorOk();
}
yyjson_mut_val *battleFighterSerialize(
const battlefighter_t *fighter,
yyjson_mut_doc *doc
) {
assertNotNull(fighter, "Fighter cannot be NULL");
assertNotNull(doc, "Doc cannot be NULL");
yyjson_mut_val *obj = yyjson_mut_obj(doc);
yyjson_mut_obj_add_uint(doc, obj, "team", fighter->team);
yyjson_mut_obj_add_uint(doc, obj, "controller", fighter->controller);
yyjson_mut_obj_add_uint(doc, obj, "status", fighter->status);
yyjson_mut_obj_add_uint(doc, obj, "attack", fighter->stats.attack);
yyjson_mut_obj_add_uint(doc, obj, "defense", fighter->stats.defense);
yyjson_mut_obj_add_uint(doc, obj, "magic", fighter->stats.magic);
yyjson_mut_obj_add_uint(doc, obj, "speed", fighter->stats.speed);
yyjson_mut_obj_add_uint(doc, obj, "luck", fighter->stats.luck);
yyjson_mut_obj_add_uint(doc, obj, "healthMax", fighter->stats.healthMax);
yyjson_mut_obj_add_uint(doc, obj, "mpMax", fighter->stats.mpMax);
yyjson_mut_obj_add_uint(doc, obj, "health", fighter->stats.health);
yyjson_mut_obj_add_uint(doc, obj, "mp", fighter->stats.mp);
yyjson_mut_val *abilities = yyjson_mut_arr(doc);
for(uint8_t i = 0; i < fighter->abilityCount; i++) {
yyjson_mut_arr_add_str(doc, abilities, BATTLE_MOVES[fighter->abilities[i]].name);
}
yyjson_mut_obj_add_val(doc, obj, "abilities", abilities);
return obj;
}
void battleFighterInit(
battlefighter_t *fighter,
const battlefighterteam_t team,
const battlefightercontroller_t controller,
const battlefighterstats_t stats
) {
assertNotNull(fighter, "Fighter pointer cannot be NULL");
assertTrue(team < BATTLE_FIGHTER_TEAM_COUNT, "Invalid fighter team");
assertTrue(
controller < BATTLE_FIGHTER_CONTROLLER_COUNT,
"Invalid fighter controller"
);
const uint8_t id = fighter->id;
memoryZero(fighter, sizeof(battlefighter_t));
fighter->id = id;
fighter->status = BATTLE_FIGHTER_STATUS_NORMAL;
fighter->team = team;
fighter->controller = controller;
fighter->stats = stats;
fighter->stats.health = stats.healthMax;
fighter->stats.mp = stats.mpMax;
}
bool_t battleFighterIsAlive(const battlefighter_t *fighter) {
assertNotNull(fighter, "Fighter pointer cannot be NULL");
return fighter->status == BATTLE_FIGHTER_STATUS_NORMAL;
}
void battleFighterAbilityAdd(
battlefighter_t *fighter,
const battlemoveid_t ability
) {
assertNotNull(fighter, "Fighter pointer cannot be NULL");
assertTrue(
fighter->abilityCount < BATTLE_FIGHTER_ABILITY_COUNT_MAX,
"Fighter already has the maximum number of abilities"
);
fighter->abilities[fighter->abilityCount++] = ability;
}
void battleFighterDamage(
battlefighter_t *fighter,
const uint16_t amount
) {
assertNotNull(fighter, "Fighter pointer cannot be NULL");
fighter->stats.health =
amount >= fighter->stats.health ? 0 : fighter->stats.health - amount;
if(fighter->stats.health == 0) fighter->status = BATTLE_FIGHTER_STATUS_DEAD;
}
void battleFighterHeal(
battlefighter_t *fighter,
const uint16_t amount
) {
assertNotNull(fighter, "Fighter pointer cannot be NULL");
if(!battleFighterIsAlive(fighter)) return;
const uint32_t healed = (uint32_t)fighter->stats.health + amount;
fighter->stats.health = healed > fighter->stats.healthMax
? fighter->stats.healthMax : (uint16_t)healed;
}
-127
View File
@@ -1,127 +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"
#include "yyjson.h"
#include "rpg/battle/move/battlemove.h"
#include "rpg/battle/fighter/battlefighterstatus.h"
#include "rpg/battle/fighter/battlefighterteam.h"
#include "rpg/battle/fighter/battlefightercontroller.h"
#include "rpg/battle/fighter/battlefighterstats.h"
#include "rpg/battle/fighter/battlefighterpos.h"
#define BATTLE_FIGHTER_ABILITY_COUNT_MAX 8
typedef struct battlefighter_s {
uint8_t id;
battlefighterstatus_t status;
battlefighterteam_t team;
battlefightercontroller_t controller;
battlefighterstats_t stats;
battlemoveid_t abilities[BATTLE_FIGHTER_ABILITY_COUNT_MAX];
battlemoveid_t abilityCount;
} battlefighter_t;
/**
* Initializes a battle fighter in place, filling health/mp to the maximum
* values carried on stats and setting its status to normal.
*
* @param fighter Pointer to the fighter to initialize.
* @param team The team the fighter belongs to.
* @param controller Who makes decisions for the fighter.
* @param stats The fighter's base combat stats, including healthMax/mpMax.
*/
void battleFighterInit(
battlefighter_t *fighter,
const battlefighterteam_t team,
const battlefightercontroller_t controller,
const battlefighterstats_t stats
);
/**
* Generic battlefighter_t parser, shared by every place that builds a
* fighter from JSON (party.jsonc roster members, BATTLE_START enemy
* definitions, save-file party members) - see battleFighterSerialize for
* the inverse. Reads 'team'/'controller'/'status' as ints (each optional,
* defaulting to ALLY/PLAYER/NORMAL respectively - a caller that needs a
* different team/controller, e.g. BATTLE_START's enemies, sets those
* fields on fighter after this returns), 'attack'/'defense'/'magic'/
* 'speed'/'luck'/'healthMax'/'mpMax' as required ints in [0, UINT16_MAX],
* 'health'/'mp' as optional ints defaulting to healthMax/mpMax (a fresh
* fighter), and an optional 'abilities' array of move name strings. Does
* not touch fighter->id - set it (or leave it) before calling, same as
* battleFighterInit.
*
* @param fighter Pointer to the fighter to fill in.
* @param obj The JSON object to read fields from.
* @return Error if a required field is missing/invalid, or an abilities
* entry doesn't name a real move.
*/
errorret_t battleFighterParse(battlefighter_t *fighter, yyjson_val *obj);
/**
* Inverse of battleFighterParse: builds a new JSON object (not yet
* attached anywhere - the caller attaches it, e.g. via
* yyjson_mut_arr_add_val/yyjson_mut_obj_add_val) with every field
* battleFighterParse reads except id (see its doc comment for why).
*
* @param fighter The fighter to serialize.
* @param doc The mutable document to allocate the object in.
* @return The newly built object.
*/
yyjson_mut_val *battleFighterSerialize(
const battlefighter_t *fighter,
yyjson_mut_doc *doc
);
/**
* Returns true if the fighter is in a state where it can still act (i.e.
* is not dead).
*
* @param fighter Pointer to the fighter to check.
* @returns True if the fighter can act.
*/
bool_t battleFighterIsAlive(const battlefighter_t *fighter);
/**
* Appends an ability to the fighter's ability list.
*
* @param fighter Pointer to the fighter to add the ability to.
* @param ability The ability to add.
*/
void battleFighterAbilityAdd(
battlefighter_t *fighter,
const battlemoveid_t ability
);
/**
* Subtracts amount from the fighter's health (floored at 0), marking it
* dead once health reaches 0.
*
* @param fighter Pointer to the fighter to damage.
* @param amount The amount of damage to apply.
*/
void battleFighterDamage(
battlefighter_t *fighter,
const uint16_t amount
);
/**
* Adds amount to the fighter's health (capped at healthMax). No-op if the
* fighter isn't alive -- healing can't revive a dead fighter.
*
* @param fighter Pointer to the fighter to heal.
* @param amount The amount to heal.
*/
void battleFighterHeal(
battlefighter_t *fighter,
const uint16_t amount
);
@@ -1,18 +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"
typedef enum {
BATTLE_FIGHTER_CONTROLLER_NONE,
BATTLE_FIGHTER_CONTROLLER_PLAYER,
BATTLE_FIGHTER_CONTROLLER_AI,
BATTLE_FIGHTER_CONTROLLER_COUNT
} battlefightercontroller_t;
@@ -1,35 +0,0 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "dusk.h"
typedef uint8_t battlefighterpos_t;
#define BATTLE_FIGHTER_POS(x) ((battlefighterpos_t)(x))
// Left (Enemy side)
#define BATTLE_FIGHTER_POS_0 BATTLE_FIGHTER_POS(0)
#define BATTLE_FIGHTER_POS_1 BATTLE_FIGHTER_POS(1)
#define BATTLE_FIGHTER_POS_2 BATTLE_FIGHTER_POS(2)
#define BATTLE_FIGHTER_POS_3 BATTLE_FIGHTER_POS(3)
// Right (Ally side)
#define BATTLE_FIGHTER_POS_4 BATTLE_FIGHTER_POS(4)
#define BATTLE_FIGHTER_POS_5 BATTLE_FIGHTER_POS(5)
#define BATTLE_FIGHTER_POS_6 BATTLE_FIGHTER_POS(6)
#define BATTLE_FIGHTER_POS_7 BATTLE_FIGHTER_POS(7)
#define BATTLE_FIGHTER_POS_COUNT (BATTLE_FIGHTER_POS_7 + 1)
// Sentinels resolved by battleStateExecutingInit against the currently
// resolving action, for cutscene items authored inside a move's own
// cutscene (e.g. cutscenes/battle/moves/slash.jsonc) that need to refer
// to "whoever is being hit"/"whoever is attacking" without knowing their
// concrete BATTLE.fighters index ahead of time.
#define BATTLE_FIGHTER_POS_TARGET BATTLE_FIGHTER_POS(0xFE)
#define BATTLE_FIGHTER_POS_USER BATTLE_FIGHTER_POS(0xFD)
@@ -1,22 +0,0 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "dusk.h"
#include "rpg/battle/fighter/battlefighterstats.h"
#define BATTLE_FIGHTER_SPECIES_NAME_MAX 16
#define BATTLE_FIGHTER_SPECIES_COUNT_MAX 250
typedef uint8_t battlespeciesid_t;
#define BATTLE_SPECIES_ID_NULL ((battlespeciesid_t)0)
typedef struct {
char_t name[BATTLE_FIGHTER_SPECIES_NAME_MAX];
battlefighterstats_t baseStats;
} battlefighterspecies_t;
@@ -1,22 +0,0 @@
/**
* 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 {
uint16_t health;
uint16_t mp;
uint16_t healthMax;
uint16_t mpMax;
uint16_t attack;
uint16_t defense;
uint16_t magic;
uint16_t speed;
uint16_t luck;
} battlefighterstats_t;
@@ -1,20 +0,0 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "dusk.h"
typedef enum {
BATTLE_FIGHTER_STATUS_NULL,
BATTLE_FIGHTER_STATUS_NORMAL,
BATTLE_FIGHTER_STATUS_DEAD,
// Poisoned, burned, confused, etc.
BATTLE_FIGHTER_STATUS_COUNT
} battlefighterstatus_t;
@@ -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 "dusk.h"
typedef enum {
BATTLE_FIGHTER_TEAM_ALLY,
BATTLE_FIGHTER_TEAM_ENEMY,
BATTLE_FIGHTER_TEAM_COUNT
} battlefighterteam_t;
-10
View File
@@ -1,10 +0,0 @@
# Copyright (c) 2026 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
# Sources
target_sources(${DUSK_LIBRARY_TARGET_NAME}
PUBLIC
battlemove.c
)
-139
View File
@@ -1,139 +0,0 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "battlemove.h"
#include "asset/asset.h"
#include "asset/loader/assetloader.h"
#include "assert/assert.h"
#include "util/memory.h"
#include "util/string.h"
#include <string.h>
battleability_t BATTLE_MOVES[BATTLE_MOVE_COUNT_MAX];
uint8_t BATTLE_MOVE_COUNT;
errorret_t battleMoveInit(void) {
memoryZero(BATTLE_MOVES, sizeof(BATTLE_MOVES));
BATTLE_MOVE_COUNT = BATTLE_MOVE_ID_NULL + 1;// Reserve NULL.
// Get moves JSON.
assetentry_t *entry = assetLock(
"battle/moves.jsonc", ASSET_LOADER_TYPE_JSON, NULL
);
errorret_t ret = assetRequireLoaded(entry);
if(errorIsNotOk(ret)) {
assetUnlockEntry(entry);
errorChain(ret);
}
yyjson_val *root = yyjson_doc_get_root(entry->data.json);
yyjson_val *moves = yyjson_obj_get(root, "moves");
yyjson_obj_iter iter = yyjson_obj_iter_with(moves);
yyjson_val *key;
while((key = yyjson_obj_iter_next(&iter))) {
if(BATTLE_MOVE_COUNT >= BATTLE_MOVE_COUNT_MAX) {
assetUnlockEntry(entry);
errorThrow(
"Battle move: too many moves defined (max %u)",
(uint32_t)BATTLE_MOVE_COUNT_MAX
);
}
battlemoveid_t id = BATTLE_MOVE_COUNT++;
battleability_t *move = &BATTLE_MOVES[id];
// Name
if(!yyjson_is_str(key)) {
assetUnlockEntry(entry);
errorThrow("Battle move: keys in 'moves' must be strings");
}
const char_t *name = yyjson_get_str(key);
stringCopy(move->name, name, BATTLE_MOVE_NAME_MAX);
if(strlen(name) >= BATTLE_MOVE_NAME_MAX) {
assetUnlockEntry(entry);
errorThrow(
"Battle move '%s': name must be less than %u characters",
name, (uint32_t)BATTLE_MOVE_NAME_MAX
);
}
// Must me object
yyjson_val *val = yyjson_obj_iter_get_val(key);
if(!yyjson_is_obj(val)) {
assetUnlockEntry(entry);
errorThrow("Battle move '%s': value must be an object", name);
}
// Valid targets
yyjson_val *enemies = yyjson_obj_get(val, "enemies");
if(enemies != NULL && !yyjson_is_bool(enemies)) {
assetUnlockEntry(entry);
errorThrow("Battle move '%s': 'enemies' must be a boolean", name);
}
yyjson_val *allies = yyjson_obj_get(val, "allies");
if(allies != NULL && !yyjson_is_bool(allies)) {
assetUnlockEntry(entry);
errorThrow("Battle move '%s': 'allies' must be a boolean", name);
}
yyjson_val *multiple = yyjson_obj_get(val, "multiple");
if(multiple != NULL && !yyjson_is_bool(multiple)) {
assetUnlockEntry(entry);
errorThrow("Battle move '%s': 'multiple' must be a boolean", name);
}
yyjson_val *self = yyjson_obj_get(val, "self");
if(self != NULL && !yyjson_is_bool(self)) {
assetUnlockEntry(entry);
errorThrow("Battle move '%s': 'self' must be a boolean", name);
}
battletarget_t target = 0;
if(yyjson_get_bool(enemies)) target |= BATTLE_TARGET_ENEMIES;
if(yyjson_get_bool(allies)) target |= BATTLE_TARGET_ALLIES;
if(yyjson_get_bool(multiple)) target |= BATTLE_TARGET_MULTIPLE;
if(yyjson_get_bool(self)) target |= BATTLE_TARGET_SELF;
move->target = target;
if(move->target == 0) {
assetUnlockEntry(entry);
errorThrow("Battle move '%s': missing target type", name);
}
// Default target (optional)
yyjson_val *defaultVal = yyjson_obj_get(val, "default");
if(defaultVal != NULL && !yyjson_is_str(defaultVal)) {
assetUnlockEntry(entry);
errorThrow("Battle move '%s': 'default' must be a string", name);
}
const char_t *defaultTarget = yyjson_get_str(defaultVal);
if(defaultTarget == NULL) {
move->targetDefault = 0;
} else if(stringCompareInsensitive(defaultTarget, "enemy") == 0) {
move->targetDefault = BATTLE_TARGET_ENEMIES;
} else if(stringCompareInsensitive(defaultTarget, "ally") == 0) {
move->targetDefault = BATTLE_TARGET_ALLIES;
} else if(stringCompareInsensitive(defaultTarget, "self") == 0) {
move->targetDefault = BATTLE_TARGET_SELF;
} else {
assetUnlockEntry(entry);
errorThrow("Battle move %s has invalid default target.", name);
}
}
assetUnlockEntry(entry);
errorOk();
}
battlemoveid_t battleMoveGetIdByName(const char_t *name) {
assertNotNull(name, "name must not be NULL");
for(battlemoveid_t id = BATTLE_MOVE_ID_NULL + 1; id < BATTLE_MOVE_COUNT; id++) {
if(stringEquals(BATTLE_MOVES[id].name, name)) return id;
}
return BATTLE_MOVE_ID_NULL;
}
-42
View File
@@ -1,42 +0,0 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "asset/asset.h"
#include "battletarget.h"
typedef uint8_t battlemoveid_t;
#define BATTLE_MOVE_NAME_MAX 16
#define BATTLE_MOVE_COUNT_MAX 250
#define BATTLE_MOVE_ID_NULL ((battlemoveid_t)0)
extern uint8_t BATTLE_MOVE_COUNT;
typedef struct {
char_t name[BATTLE_MOVE_NAME_MAX];
battletarget_t target;
battletarget_t targetDefault;
} battleability_t;
extern battleability_t BATTLE_MOVES[BATTLE_MOVE_COUNT_MAX];
/**
* Initializes the battle move subsystem, loading assets/battle/moves.jsonc.
*
* @return Any error that occurs.
*/
errorret_t battleMoveInit(void);
/**
* Finds a move's id by name (exact match).
*
* @param name The move name to search for.
* @return The matching move's id, or BATTLE_MOVE_ID_NULL if not found.
*/
battlemoveid_t battleMoveGetIdByName(const char_t *name);
@@ -1,18 +0,0 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "rpg/battle/move/battlemove.h"
#include "rpg/battle/fighter/battlefighterpos.h"
typedef struct battlefighter_s battlefighter_t;
typedef struct {
battlemoveid_t move;
battlefighterpos_t targets[BATTLE_FIGHTER_POS_COUNT];
battlefighter_t *user;
} battlemoveaction_t;
-16
View File
@@ -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 "dusk.h"
typedef uint8_t battletarget_t;
#define BATTLE_TARGET_ENEMIES (1 << 0)
#define BATTLE_TARGET_ALLIES (1 << 1)
#define BATTLE_TARGET_MULTIPLE (1 << 2)
#define BATTLE_TARGET_SELF (1 << 3)
-188
View File
@@ -1,188 +0,0 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "party.h"
#include "assert/assert.h"
#include "util/memory.h"
#include "util/string.h"
#include "save/save.h"
#include "asset/asset.h"
#include "asset/loader/assetloader.h"
errorret_t partyInit(party_t *party) {
assertNotNull(party, "Party cannot be NULL");
memoryZero(party, sizeof(party_t));
for(uint8_t i = 0; i < PARTY_ACTIVE_SIZE_MAX; i++) {
party->order[i] = PARTY_ORDER_EMPTY;
}
assetentry_t *entry = assetLock("party.jsonc", ASSET_LOADER_TYPE_JSON, NULL);
errorret_t result = assetRequireLoaded(entry);
if(errorIsNotOk(result)) {
assetUnlockEntry(entry);
errorChain(result);
}
yyjson_val *root = yyjson_doc_get_root(entry->data.json);
yyjson_val *members = yyjson_obj_get(root, "members");
if(!yyjson_is_obj(members)) {
assetUnlockEntry(entry);
errorThrow("party.jsonc: missing/invalid 'members' object");
}
const size_t memberCount = yyjson_obj_size(members);
if(memberCount > PARTY_MEMBER_COUNT_MAX) {
assetUnlockEntry(entry);
errorThrow(
"party.jsonc: defines more than PARTY_MEMBER_COUNT_MAX (%u) members",
PARTY_MEMBER_COUNT_MAX
);
}
uint8_t idx = 0;
yyjson_val *key;
yyjson_val *memberObj;
yyjson_obj_iter iter = yyjson_obj_iter_with(members);
while((key = yyjson_obj_iter_next(&iter))) {
memberObj = yyjson_obj_iter_get_val(key);
if(yyjson_get_len(key) >= PARTY_KEY_LENGTH_MAX) {
assetUnlockEntry(entry);
errorThrow(
"party.jsonc: member key '%s' exceeds PARTY_KEY_LENGTH_MAX (%u)",
yyjson_get_str(key), PARTY_KEY_LENGTH_MAX
);
}
stringCopy(party->keys[idx], yyjson_get_str(key), PARTY_KEY_LENGTH_MAX - 1);
battlefighter_t *member = &party->members[idx];
member->id = idx;
errorret_t parseResult = battleFighterParse(member, memberObj);
if(errorIsNotOk(parseResult)) {
assetUnlockEntry(entry);
errorChain(parseResult);
}
idx++;
}
assetUnlockEntry(entry);
// TEST: only the first defined member starts active, in the first party
// position - replace once there's a real starting-party/character-
// creation flow. Deliberately separate from the roster seeding above:
// order (not a member's presence in the roster) is what determines who's
// currently in the party.
if(memberCount > 0) party->order[0] = 0;
errorOk();
}
uint8_t partyGetMemberIndexByKey(const char_t *key) {
assertNotNull(key, "Key cannot be NULL");
const party_t *party = &SAVE.slot.party;
for(uint8_t i = 0; i < PARTY_MEMBER_COUNT_MAX; i++) {
if(stringEquals(party->keys[i], key)) return i;
}
return PARTY_MEMBER_NOT_FOUND;
}
const char_t *partyGetMemberKey(const uint8_t memberIndex) {
assertTrue(memberIndex < PARTY_MEMBER_COUNT_MAX, "Invalid party member index");
return SAVE.slot.party.keys[memberIndex];
}
bool_t partyIsMemberActive(const uint8_t memberIndex) {
assertTrue(memberIndex < PARTY_MEMBER_COUNT_MAX, "Invalid party member index");
const party_t *party = &SAVE.slot.party;
for(uint8_t i = 0; i < PARTY_ACTIVE_SIZE_MAX; i++) {
if(party->order[i] == memberIndex) return true;
}
return false;
}
void partyAddMember(const uint8_t memberIndex) {
assertTrue(memberIndex < PARTY_MEMBER_COUNT_MAX, "Invalid party member index");
party_t *party = &SAVE.slot.party;
assertTrue(
party->members[memberIndex].status != BATTLE_FIGHTER_STATUS_NULL,
"Member does not exist in the roster"
);
if(partyIsMemberActive(memberIndex)) return;
for(uint8_t i = 0; i < PARTY_ACTIVE_SIZE_MAX; i++) {
if(party->order[i] != PARTY_ORDER_EMPTY) continue;
party->order[i] = memberIndex;
return;
}
}
battlefighter_t *partyGetOrderMember(const uint8_t slot) {
assertTrue(slot < PARTY_ACTIVE_SIZE_MAX, "Invalid 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];
}
void partySetOrder(const uint8_t slot, const uint8_t memberIndex) {
assertTrue(slot < PARTY_ACTIVE_SIZE_MAX, "Invalid party order slot");
assertTrue(
memberIndex == PARTY_ORDER_EMPTY || memberIndex < PARTY_MEMBER_COUNT_MAX,
"Invalid party member index"
);
SAVE.slot.party.order[slot] = memberIndex;
}
void partyRemoveMember(const uint8_t memberIndex) {
assertTrue(memberIndex < PARTY_MEMBER_COUNT_MAX, "Invalid party member index");
party_t *party = &SAVE.slot.party;
uint8_t removedSlot = PARTY_ORDER_EMPTY;
for(uint8_t i = 0; i < PARTY_ACTIVE_SIZE_MAX; i++) {
if(party->order[i] != memberIndex) continue;
removedSlot = i;
break;
}
if(removedSlot == PARTY_ORDER_EMPTY) return;
for(uint8_t i = removedSlot; i < PARTY_ACTIVE_SIZE_MAX - 1; i++) {
party->order[i] = party->order[i + 1];
}
party->order[PARTY_ACTIVE_SIZE_MAX - 1] = PARTY_ORDER_EMPTY;
}
void partyHealMember(const uint8_t memberIndex) {
assertTrue(memberIndex < PARTY_MEMBER_COUNT_MAX, "Invalid party member index");
battlefighter_t *member = &SAVE.slot.party.members[memberIndex];
if(member->status == BATTLE_FIGHTER_STATUS_NULL) return;
member->status = BATTLE_FIGHTER_STATUS_NORMAL;
member->stats.health = member->stats.healthMax;
member->stats.mp = member->stats.mpMax;
}
void partyHealAll(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) continue;
partyHealMember(i);
}
}
-126
View File
@@ -1,126 +0,0 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "rpg/battle/fighter/battlefighter.h"
#include "yyjson.h"
#define PARTY_MEMBER_COUNT_MAX 10
#define PARTY_ACTIVE_SIZE_MAX 4
#define PARTY_KEY_LENGTH_MAX 32
#define PARTY_ORDER_EMPTY 0xFF
#define PARTY_MEMBER_NOT_FOUND 0xFF
typedef struct {
battlefighter_t members[PARTY_MEMBER_COUNT_MAX];
char_t keys[PARTY_MEMBER_COUNT_MAX][PARTY_KEY_LENGTH_MAX];
uint8_t order[PARTY_ACTIVE_SIZE_MAX];
} party_t;
/**
* Initializes party with an empty order, then seeds every roster slot
* directly from party.jsonc's "members" object (each key/value pair fills
* the next members[]/keys[] slot in the object's iteration order, key
* copied into keys[] and value parsed via battleFighterParse) - unlike
* partyAddMember, this never touches order itself except for one
* placeholder default: if party.jsonc defines at least one member,
* order[0] is set to 0 (the first member starts active in the first party
* position). Replace this default once there's a real starting-party/
* character-creation flow.
*
* @param party The party to initialize.
* @return Error if party.jsonc fails to load/parse, defines more members
* than PARTY_MEMBER_COUNT_MAX has room for, or a key exceeds
* PARTY_KEY_LENGTH_MAX.
*/
errorret_t partyInit(party_t *party);
/**
* Looks up a roster member's index by its party.jsonc key (see
* party_t.keys).
*
* @param key The member's key to search for.
* @return The matching roster index, or PARTY_MEMBER_NOT_FOUND if no
* member has that key.
*/
uint8_t partyGetMemberIndexByKey(const char_t *key);
/**
* Gets a roster member's party.jsonc key by index (see party_t.keys).
*
* @param memberIndex The roster member index to query.
* @return The member's key - "" if memberIndex is past however many
* members party.jsonc actually defines.
*/
const char_t *partyGetMemberKey(const uint8_t memberIndex);
/**
* Checks whether memberIndex currently occupies a slot in the current save
* slot's party order (i.e. is actively in the party right now).
*
* @param memberIndex The roster member index to check.
* @return True if memberIndex appears anywhere in order.
*/
bool_t partyIsMemberActive(const uint8_t memberIndex);
/**
* Adds an existing roster member (see partyInit - every roster slot
* always exists once initialized) to the current save slot's active party
* order, in the first free order slot. No-op if memberIndex is already
* active, or if there is no free order slot.
*
* @param memberIndex The roster member index to activate.
*/
void partyAddMember(const uint8_t memberIndex);
/**
* 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
* empty.
*/
battlefighter_t *partyGetOrderMember(const uint8_t 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
* PARTY_ORDER_EMPTY to clear the slot.
*/
void partySetOrder(const uint8_t slot, const uint8_t memberIndex);
/**
* Removes memberIndex from the current save slot's active party order -
* the roster member itself is untouched (it still exists, per partyInit;
* it's simply no longer active) - shifting every later order entry down
* one slot to close the gap, so order stays packed with no holes between
* active members. No-op if memberIndex isn't currently active.
*
* @param memberIndex The roster member index to deactivate.
*/
void partyRemoveMember(const uint8_t memberIndex);
/**
* Fully restores a roster member's health/mp to their max and clears a
* dead status back to normal - unlike battleFighterHeal, this can revive
* a dead member (there's no combat context here to keep them down). No-op
* if the slot is empty.
*
* @param memberIndex The roster member index to heal.
*/
void partyHealMember(const uint8_t memberIndex);
/**
* Calls partyHealMember for every occupied slot in the current save
* slot's party roster.
*/
void partyHealAll(void);
-19
View File
@@ -1,19 +0,0 @@
# Copyright (c) 2026 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
# Sources
target_sources(${DUSK_LIBRARY_TARGET_NAME}
PUBLIC
battlestate.c
battlestateopening.c
battlestatepreround.c
battlestateselection.c
battlestateexecuting.c
battlestatepostround.c
battlestatelost.c
battlestatewon.c
battlestatefled.c
battlestateending.c
)
-66
View File
@@ -1,66 +0,0 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "battlestate.h"
battlestatefunctions_t BATTLE_STATE_FUNCTIONS[BATTLE_STATE_COUNT] = {
[BATTLE_STATE_NULL] = { 0 },
[BATTLE_STATE_OPENING] = {
.init = battleStateOpeningInit,
.update = battleStateOpeningUpdate,
.dispose = battleStateOpeningDispose
},
[BATTLE_STATE_PRE_ROUND] = {
.init = battleStatePreRoundInit,
.update = battleStatePreRoundUpdate,
.dispose = battleStatePreRoundDispose
},
[BATTLE_STATE_SELECTION] = {
.init = battleStateSelectionInit,
.update = battleStateSelectionUpdate,
.dispose = battleStateSelectionDispose
},
[BATTLE_STATE_EXECUTING] = {
.init = battleStateExecutingInit,
.update = battleStateExecutingUpdate,
.dispose = battleStateExecutingDispose
},
[BATTLE_STATE_POST_ROUND] = {
.init = battleStatePostRoundInit,
.update = battleStatePostRoundUpdate,
.dispose = battleStatePostRoundDispose
},
[BATTLE_STATE_LOST] = {
.init = battleStateLostInit,
.update = battleStateLostUpdate,
.dispose = battleStateLostDispose
},
[BATTLE_STATE_WON] = {
.init = battleStateWonInit,
.update = battleStateWonUpdate,
.dispose = battleStateWonDispose
},
[BATTLE_STATE_FLED] = {
.init = battleStateFledInit,
.update = battleStateFledUpdate,
.dispose = battleStateFledDispose
},
[BATTLE_STATE_ENDING] = {
.init = battleStateEndingInit,
.update = battleStateEndingUpdate,
.dispose = battleStateEndingDispose
}
};
-64
View File
@@ -1,64 +0,0 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "battlestateopening.h"
#include "battlestatepreround.h"
#include "battlestateselection.h"
#include "battlestateexecuting.h"
#include "battlestatepostround.h"
#include "battlestatelost.h"
#include "battlestatewon.h"
#include "battlestatefled.h"
#include "battlestateending.h"
typedef enum {
// No active battle.
BATTLE_STATE_NULL,
// Battle hasn't actually started yet, equiv to trainer intro in Pokemon.
BATTLE_STATE_OPENING,
// Pre round, anything that happens before AI or Player can act.
BATTLE_STATE_PRE_ROUND,
// Player is deciding what to do, waiting for their input
BATTLE_STATE_SELECTION,
// Currently executing the moves.
BATTLE_STATE_EXECUTING,
// Post round, anything that happens after AI or Player has acted, loops back
// after this point
BATTLE_STATE_POST_ROUND,
// Battle has ended with a player loss
BATTLE_STATE_LOST,
// Battle has ended with a player win
BATTLE_STATE_WON,
// Battle has ended with a player fleeing
BATTLE_STATE_FLED,
// Battle state is done, this is fade out or whatever.
BATTLE_STATE_ENDING,
BATTLE_STATE_COUNT
} battlestate_t;
typedef union {
battlestateopening_t opening;
battlestatepreround_t preRound;
battlestateselection_t selection;
battlestateexecuting_t executing;
battlestatepostround_t postRound;
battlestatelost_t lost;
battlestatewon_t won;
battlestatefled_t fled;
battlestateending_t ending;
} battlestatedata_t;
typedef struct {
void (*init)();
void (*update)();
void (*dispose)();
} battlestatefunctions_t;
extern battlestatefunctions_t BATTLE_STATE_FUNCTIONS[BATTLE_STATE_COUNT];
@@ -1,28 +0,0 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "battlestateending.h"
#include "rpg/battle/battle.h"
#include "scene/scene.h"
void battleStateEndingInit(void) {
// Tear down the battle and hand control back to the overworld. The
// overworld scene keeps no state of its own in scenedata_t (player/map
// state lives in the separate global entity/map systems, untouched by
// switching to/from SCENE_TYPE_BATTLE), so there's nothing else to
// restore here.
battleDispose();
sceneSet(SCENE_TYPE_OVERWORLD);
}
void battleStateEndingUpdate(void) {
}
void battleStateEndingDispose(void) {
}
@@ -1,29 +0,0 @@
/**
* 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 {
} battlestateending_t;
/**
* Called when the battle enters BATTLE_STATE_ENDING. Disposes the battle
* (see battleDispose) and switches back to SCENE_TYPE_OVERWORLD.
*/
void battleStateEndingInit(void);
/**
* Updates BATTLE_STATE_ENDING for one frame.
*/
void battleStateEndingUpdate(void);
/**
* Called when the battle leaves BATTLE_STATE_ENDING.
*/
void battleStateEndingDispose(void);
@@ -1,116 +0,0 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "battlestateexecuting.h"
#include "rpg/battle/battle.h"
#include "rpg/cutscene/item/cutsceneitem.h"
#include "rpg/cutscene/cutscenesystem.h"
#include "rpg/cutscene/cutscene.h"
#include "asset/assetfile.h"
#include "ui/overlay/uifatalerror.h"
#include "assert/assert.h"
#include "util/string.h"
void battleStateExecutingResolveFighterIndex(
battlefighterpos_t *fighterIndex,
const uint8_t userIndex,
const battlemoveaction_t *action
) {
if(*fighterIndex == BATTLE_FIGHTER_POS_TARGET) {
*fighterIndex = action->targets[0];
} else if(*fighterIndex == BATTLE_FIGHTER_POS_USER) {
*fighterIndex = userIndex;
}
}
void battleStateExecutingInit(void) {
cutsceneitem_t items[BATTLE_STATE_EXECUTING_ITEMS_MAX];
uint8_t itemsCount = 0;
// For each action (just queued during selection). actionsPending is
// indexed by fighter position, not sequentially, so scan every position
// and stop early once every pending action has been processed.
uint8_t processed = 0;
for(
uint8_t i = 0;
i < BATTLE_FIGHTER_POS_COUNT && processed < BATTLE.actionsPendingCount;
i++
) {
// Get action.
battlemoveaction_t *action = &BATTLE.actionsPending[i];
if(action->move == BATTLE_MOVE_ID_NULL) continue;
processed++;
assertTrue(action->move < BATTLE_MOVE_COUNT, "Invalid move id");
// Get ability.
battleability_t *ability = &BATTLE_MOVES[action->move];
assertStrLenMin(ability->name, 1, "Invalid move name");
// Determine cutscene path
char_t path[ASSET_FILE_NAME_MAX];
stringFormat(
path, ASSET_FILE_NAME_MAX - 1,
"cutscenes/battle/moves/%s.jsonc", ability->name
);
// Load and parse the move's cutscene straight into the tail of items.
const uint8_t moveItemsStart = itemsCount;
cutscene_t scene;
errorret_t result = cutsceneLoadParse(
path, &scene, &items[itemsCount],
BATTLE_STATE_EXECUTING_ITEMS_MAX - itemsCount
);
if(errorIsNotOk(result)) {
errorCatch(errorPrint(result));
uiFatalErrorOpen(NULL);
continue;
}
itemsCount += scene.itemCount;
// Resolve BATTLE_FIGHTER_POS_TARGET/USER sentinels against this
// action, now that its user/target fighters are known.
for(uint8_t j = moveItemsStart; j < itemsCount; j++) {
cutsceneitem_t *moveItem = &items[j];
if(moveItem->type == CUTSCENE_ITEM_TYPE_BATTLE_FIGHTER_DAMAGE) {
battleStateExecutingResolveFighterIndex(
&moveItem->battleFighterDamage.fighterIndex, i, action
);
} else if(moveItem->type == CUTSCENE_ITEM_TYPE_BATTLE_FIGHTER_HEAL) {
battleStateExecutingResolveFighterIndex(
&moveItem->battleFighterHeal.fighterIndex, i, action
);
}
}
// Insert end of attack cutscene item.
items[itemsCount++] = (cutsceneitem_t){
.type = CUTSCENE_ITEM_TYPE_BATTLE_POST_MOVE
};
// This action has now been resolved - clear it so it isn't
// re-executed (and doesn't block re-selection) next round.
action->move = BATTLE_MOVE_ID_NULL;
}
BATTLE.actionsPendingCount = 0;
// After all moves completed, transition to pre-round for next round.
items[itemsCount++] = (cutsceneitem_t){
.type = CUTSCENE_ITEM_TYPE_BATTLE_SET_STATE,
.battleSetState = { .state = BATTLE_STATE_PRE_ROUND }
};
cutsceneSystemInsertItemsNext(items, itemsCount);
}
void battleStateExecutingUpdate(void) {
}
void battleStateExecutingDispose(void) {
}
@@ -1,50 +0,0 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "dusk.h"
#include "rpg/battle/fighter/battlefighterpos.h"
#include "rpg/battle/move/battlemoveaction.h"
typedef struct {
} battlestateexecuting_t;
#define BATTLE_STATE_EXECUTING_ITEMS_MAX 64
/**
* Called when the battle enters BATTLE_STATE_EXECUTING.
*/
void battleStateExecutingInit(void);
/**
* Resolves a BATTLE_FIGHTER_POS_TARGET/BATTLE_FIGHTER_POS_USER sentinel
* (as parsed onto a BATTLE_FIGHTER_DAMAGE/BATTLE_FIGHTER_HEAL item inside
* a move's own cutscene) against the action currently being resolved
* into cutscene items. Leaves fighterIndex untouched if it's already a
* concrete BATTLE.fighters index.
*
* @param fighterIndex The field to resolve in place.
* @param userIndex Index into BATTLE.fighters of the fighter performing
* the action.
* @param action The action being resolved.
*/
void battleStateExecutingResolveFighterIndex(
battlefighterpos_t *fighterIndex,
const uint8_t userIndex,
const battlemoveaction_t *action
);
/**
* Updates BATTLE_STATE_EXECUTING for one frame.
*/
void battleStateExecutingUpdate(void);
/**
* Called when the battle leaves BATTLE_STATE_EXECUTING.
*/
void battleStateExecutingDispose(void);
@@ -1,32 +0,0 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "battlestatefled.h"
#include "rpg/cutscene/item/cutsceneitem.h"
#include "rpg/cutscene/cutscenesystem.h"
void battleStateFledInit(void) {
const cutsceneitem_t items[] = {
{
.type = CUTSCENE_ITEM_TYPE_TEXT,
.text = { .text = "Got away safely!" }
},
{
.type = CUTSCENE_ITEM_TYPE_BATTLE_SET_STATE,
.battleSetState = { .state = BATTLE_STATE_ENDING }
}
};
cutsceneSystemInsertItemsNext(items, sizeof(items) / sizeof(cutsceneitem_t));
}
void battleStateFledUpdate(void) {
}
void battleStateFledDispose(void) {
}
@@ -1,30 +0,0 @@
/**
* 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 {
} battlestatefled_t;
/**
* Called when the battle enters BATTLE_STATE_FLED. Queues a textbox
* announcing the escape, then transitions to BATTLE_STATE_ENDING once
* dismissed.
*/
void battleStateFledInit(void);
/**
* Updates BATTLE_STATE_FLED for one frame.
*/
void battleStateFledUpdate(void);
/**
* Called when the battle leaves BATTLE_STATE_FLED.
*/
void battleStateFledDispose(void);
@@ -1,32 +0,0 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "battlestatelost.h"
#include "rpg/cutscene/item/cutsceneitem.h"
#include "rpg/cutscene/cutscenesystem.h"
void battleStateLostInit(void) {
const cutsceneitem_t items[] = {
{
.type = CUTSCENE_ITEM_TYPE_TEXT,
.text = { .text = "You were defeated..." }
},
{
.type = CUTSCENE_ITEM_TYPE_BATTLE_SET_STATE,
.battleSetState = { .state = BATTLE_STATE_ENDING }
}
};
cutsceneSystemInsertItemsNext(items, sizeof(items) / sizeof(cutsceneitem_t));
}
void battleStateLostUpdate(void) {
}
void battleStateLostDispose(void) {
}
@@ -1,30 +0,0 @@
/**
* 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 {
} battlestatelost_t;
/**
* Called when the battle enters BATTLE_STATE_LOST. Queues a textbox
* announcing the loss, then transitions to BATTLE_STATE_ENDING once
* dismissed.
*/
void battleStateLostInit(void);
/**
* Updates BATTLE_STATE_LOST for one frame.
*/
void battleStateLostUpdate(void);
/**
* Called when the battle leaves BATTLE_STATE_LOST.
*/
void battleStateLostDispose(void);
@@ -1,28 +0,0 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "battlestateopening.h"
#include "rpg/cutscene/item/cutsceneitem.h"
#include "rpg/cutscene/cutscenesystem.h"
void battleStateOpeningInit(void) {
const cutsceneitem_t items[] = {
{
.type = CUTSCENE_ITEM_TYPE_BATTLE_SET_STATE,
.battleSetState = { .state = BATTLE_STATE_PRE_ROUND }
}
};
cutsceneSystemInsertItemsNext(items, sizeof(items) / sizeof(cutsceneitem_t));
}
void battleStateOpeningUpdate(void) {
}
void battleStateOpeningDispose(void) {
}
@@ -1,28 +0,0 @@
/**
* 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 {
} battlestateopening_t;
/**
* Called when the battle enters BATTLE_STATE_OPENING.
*/
void battleStateOpeningInit(void);
/**
* Updates BATTLE_STATE_OPENING for one frame.
*/
void battleStateOpeningUpdate(void);
/**
* Called when the battle leaves BATTLE_STATE_OPENING.
*/
void battleStateOpeningDispose(void);
@@ -1,20 +0,0 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "battlestatepostround.h"
void battleStatePostRoundInit(void) {
}
void battleStatePostRoundUpdate(void) {
}
void battleStatePostRoundDispose(void) {
}
@@ -1,28 +0,0 @@
/**
* 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 {
} battlestatepostround_t;
/**
* Called when the battle enters BATTLE_STATE_POST_ROUND.
*/
void battleStatePostRoundInit(void);
/**
* Updates BATTLE_STATE_POST_ROUND for one frame.
*/
void battleStatePostRoundUpdate(void);
/**
* Called when the battle leaves BATTLE_STATE_POST_ROUND.
*/
void battleStatePostRoundDispose(void);
@@ -1,41 +0,0 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "battlestatepreround.h"
#include "rpg/battle/battle.h"
#include "rpg/cutscene/item/cutsceneitem.h"
#include "rpg/cutscene/cutscenesystem.h"
void battleStatePreRoundInit(void) {
// TODO: Determine selection order and who gets to act.
BATTLE.fighterOrderCount = 0;
for(uint8_t i = 0; i < BATTLE_FIGHTER_POS_COUNT; i++) {
if(BATTLE.fighters[i] == NULL) continue;
if(!battleFighterIsAlive(BATTLE.fighters[i])) continue;
BATTLE.fighterOrder[BATTLE.fighterOrderCount++] = i;
}
// Queue up the set state and wait for selection to stop cutscene ending.
cutsceneitem_t items[] = {
{
.type = CUTSCENE_ITEM_TYPE_BATTLE_SET_STATE,
.battleSetState = { .state = BATTLE_STATE_SELECTION }
},
{
.type = CUTSCENE_ITEM_TYPE_BATTLE_WAIT_SELECTION
}
};
cutsceneSystemInsertItemsNext(items, sizeof(items) / sizeof(cutsceneitem_t));
}
void battleStatePreRoundUpdate(void) {
}
void battleStatePreRoundDispose(void) {
}
@@ -1,28 +0,0 @@
/**
* 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 {
} battlestatepreround_t;
/**
* Called when the battle enters BATTLE_STATE_PRE_ROUND.
*/
void battleStatePreRoundInit(void);
/**
* Updates BATTLE_STATE_PRE_ROUND for one frame.
*/
void battleStatePreRoundUpdate(void);
/**
* Called when the battle leaves BATTLE_STATE_PRE_ROUND.
*/
void battleStatePreRoundDispose(void);
@@ -1,146 +0,0 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "battlestateselection.h"
#include "rpg/battle/battle.h"
#include "assert/assert.h"
void battleStateSelectionInit(void) {
BATTLE.stateData.selection.selectionIndex = 0;
}
bool_t battleStateSelectionFighterHasDecided(const uint8_t fighterIndex) {
assertTrue(fighterIndex < BATTLE_FIGHTER_POS_COUNT, "Fighter OOB");
return BATTLE.actionsPending[fighterIndex].move != BATTLE_MOVE_ID_NULL;
}
bool_t battleStateSelectionFighterNeedsDecision(const uint8_t fighterIndex) {
assertTrue(fighterIndex < BATTLE_FIGHTER_POS_COUNT, "Fighter OOB");
battlefighter_t *fighter = BATTLE.fighters[fighterIndex];
if(fighter == NULL) return false;
if(!battleFighterIsAlive(fighter)) return false;
return !battleStateSelectionFighterHasDecided(fighterIndex);
}
bool_t battleStateSelectionIsComplete(void) {
return BATTLE.stateData.selection.selectionIndex >= BATTLE.fighterOrderCount;
}
void battleStateSelectionAiDecide(const uint8_t fighterIndex) {
battlefighter_t *fighter = BATTLE.fighters[fighterIndex];
const battlefighterteam_t enemyTeam =
fighter->team == BATTLE_FIGHTER_TEAM_ALLY ?
BATTLE_FIGHTER_TEAM_ENEMY : BATTLE_FIGHTER_TEAM_ALLY;
// Simple placeholder AI: attack the first living fighter on the
// opposing team. No move variety or target scoring yet.
for(uint8_t i = 0; i < BATTLE_FIGHTER_POS_COUNT; i++) {
battlefighter_t *candidate = BATTLE.fighters[i];
if(candidate == NULL) continue;
if(candidate->team != enemyTeam) continue;
if(!battleFighterIsAlive(candidate)) continue;
battleStateSelectionQueueAttack(fighterIndex, i);
return;
}
}
void battleStateSelectionUpdate(void) {
battlestateselection_t *state = &BATTLE.stateData.selection;
// Are we still waiting for a selection?
while(state->selectionIndex < BATTLE.fighterOrderCount) {
const uint8_t fighterIndex = BATTLE.fighterOrder[state->selectionIndex];
// Is this fighter still owed a decision?
if(!battleStateSelectionFighterNeedsDecision(fighterIndex)) {
state->selectionIndex++;
continue;
}
// Players will act on their own.
battlefighter_t *fighter = BATTLE.fighters[fighterIndex];
if(fighter->controller != BATTLE_FIGHTER_CONTROLLER_AI) return;
battleStateSelectionAiDecide(fighterIndex);
state->selectionIndex++;
}
}
void battleStateSelectionDispose(void) {
}
void battleStateSelectionQueueAttack(
const uint8_t fighterIndex,
const uint8_t targetIndex
) {
assertTrue(fighterIndex < BATTLE_FIGHTER_POS_COUNT, "Fighter OOB");
assertTrue(targetIndex < BATTLE_FIGHTER_POS_COUNT, "Target OOB");
assertNotNull(BATTLE.fighters[fighterIndex], "Fighter cannot be NULL");
assertNotNull(BATTLE.fighters[targetIndex], "Target cannot be NULL");
const battlemoveid_t move = battleMoveGetIdByName("slash");
assertTrue(move != BATTLE_MOVE_ID_NULL, "Missing 'slash' battle move");
battlemoveaction_t *action = &BATTLE.actionsPending[fighterIndex];
if(action->move == BATTLE_MOVE_ID_NULL) BATTLE.actionsPendingCount++;
action->move = move;
action->targets[0] = targetIndex;
action->user = BATTLE.fighters[fighterIndex];
}
battlefighter_t *battleStateSelectionGetCurrentFighter(void) {
if(BATTLE.state != BATTLE_STATE_SELECTION) return NULL;
const uint8_t index = BATTLE.stateData.selection.selectionIndex;
if(index >= BATTLE.fighterOrderCount) return NULL;
return BATTLE.fighters[BATTLE.fighterOrder[index]];
}
void battleStateSelectionPlayerAttack(const uint8_t targetIndex) {
battlefighter_t *fighter = battleStateSelectionGetCurrentFighter();
if(fighter == NULL) return;
const uint8_t selectionIndex = BATTLE.stateData.selection.selectionIndex;
const uint8_t fighterIndex = BATTLE.fighterOrder[selectionIndex];
battleStateSelectionQueueAttack(fighterIndex, targetIndex);
BATTLE.stateData.selection.selectionIndex++;
}
void battleStateSelectionGoBack(void) {
battlestateselection_t *state = &BATTLE.stateData.selection;
uint8_t index = state->selectionIndex;
while(index > 0) {
index--;
const uint8_t fighterIndex = BATTLE.fighterOrder[index];
battlefighter_t *fighter = BATTLE.fighters[fighterIndex];
if(fighter == NULL) continue;
if(fighter->controller != BATTLE_FIGHTER_CONTROLLER_PLAYER) continue;
if(!battleStateSelectionFighterHasDecided(fighterIndex)) continue;
battlemoveaction_t *action = &BATTLE.actionsPending[fighterIndex];
action->move = BATTLE_MOVE_ID_NULL;
BATTLE.actionsPendingCount--;
state->selectionIndex = index;
return;
}
}
void battleStateSelectionPlayerFlee(void) {
battlefighter_t *fighter = battleStateSelectionGetCurrentFighter();
if(fighter == NULL) return;
BATTLE.result = BATTLE_RESULT_FLED;
battleSetState(BATTLE_STATE_FLED);
}
@@ -1,120 +0,0 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "rpg/battle/fighter/battlefighter.h"
typedef struct {
// Cursor into BATTLE.fighters (by position index) for the fighter
// currently deciding a move this round.
uint8_t selectionIndex;
} battlestateselection_t;
/**
* Called when the battle enters BATTLE_STATE_SELECTION.
*/
void battleStateSelectionInit(void);
/**
* Updates BATTLE_STATE_SELECTION for one frame: auto-decides (see
* battleStateSelectionAiDecide) for every AI-controlled fighter the
* cursor passes, stopping once it reaches a player-controlled fighter
* awaiting input (see battleStateSelectionGetCurrentFighter). Once every
* position has decided, BATTLE_WAIT_SELECTION (see
* cutsceneBattleWaitSelectionUpdate) queues the move to
* BATTLE_STATE_EXECUTING.
*/
void battleStateSelectionUpdate(void);
/**
* Called when the battle leaves BATTLE_STATE_SELECTION.
*/
void battleStateSelectionDispose(void);
/**
* Checks whether the fighter at fighterIndex has already queued a move
* this round.
*
* @param fighterIndex Index into BATTLE.fighters to check.
* @return True if an action is already pending for this fighter.
*/
bool_t battleStateSelectionFighterHasDecided(const uint8_t fighterIndex);
/**
* Checks whether the fighter at fighterIndex is a live, undecided
* candidate that BATTLE_STATE_SELECTION should still be deciding a move
* for.
*
* @param fighterIndex Index into BATTLE.fighters to check.
* @return True if the fighter is alive and has no move queued yet.
*/
bool_t battleStateSelectionFighterNeedsDecision(const uint8_t fighterIndex);
/**
* Decides and queues a move for an AI-controlled fighter: currently
* always a basic attack against the first living fighter on the
* opposing team (see battleStateSelectionQueueAttack). No-ops if there's
* no living target (the battle should already be over by then via
* BATTLE_POST_MOVE).
*
* @param fighterIndex Index into BATTLE.fighters of the deciding fighter.
*/
void battleStateSelectionAiDecide(const uint8_t fighterIndex);
/**
* Checks whether every fighter in BATTLE.fighterOrder has decided a move
* this round.
*
* @return True once the selection cursor has passed every fighter.
*/
bool_t battleStateSelectionIsComplete(void);
/**
* Queues a basic attack (the "slash" move) from fighterIndex against
* targetIndex.
*
* @param fighterIndex Index into BATTLE.fighters of the deciding fighter.
* @param targetIndex Index into BATTLE.fighters of the target.
*/
void battleStateSelectionQueueAttack(
const uint8_t fighterIndex,
const uint8_t targetIndex
);
/**
* Returns the fighter currently awaiting a decision in
* BATTLE_STATE_SELECTION.
*
* @return Pointer to the fighter awaiting a decision, or NULL if the
* battle isn't in BATTLE_STATE_SELECTION or every position has
* already decided.
*/
battlefighter_t *battleStateSelectionGetCurrentFighter(void);
/**
* Submits the currently-selecting fighter's attack against a target, if
* the battle is in BATTLE_STATE_SELECTION and awaiting a decision. Queues
* the move and advances the selection cursor.
*
* @param targetIndex Index into BATTLE.fighters of the target.
*/
void battleStateSelectionPlayerAttack(const uint8_t targetIndex);
/**
* Ends the battle immediately with BATTLE_STATE_FLED, if the battle is in
* BATTLE_STATE_SELECTION and awaiting a decision.
*/
void battleStateSelectionPlayerFlee(void);
/**
* Rewinds the selection cursor to the nearest earlier player-controlled
* fighter that has already decided a move this round, clearing its
* pending action so it can be re-decided. AI-decided fighters along the
* way are left alone (skipped over, not rewound onto). No-ops if there's
* no such fighter (e.g. already at the first decision of the round).
*/
void battleStateSelectionGoBack(void);
@@ -1,32 +0,0 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "battlestatewon.h"
#include "rpg/cutscene/item/cutsceneitem.h"
#include "rpg/cutscene/cutscenesystem.h"
void battleStateWonInit(void) {
const cutsceneitem_t items[] = {
{
.type = CUTSCENE_ITEM_TYPE_TEXT,
.text = { .text = "You won the battle!" }
},
{
.type = CUTSCENE_ITEM_TYPE_BATTLE_SET_STATE,
.battleSetState = { .state = BATTLE_STATE_ENDING }
}
};
cutsceneSystemInsertItemsNext(items, sizeof(items) / sizeof(cutsceneitem_t));
}
void battleStateWonUpdate(void) {
}
void battleStateWonDispose(void) {
}
@@ -1,30 +0,0 @@
/**
* 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 {
} battlestatewon_t;
/**
* Called when the battle enters BATTLE_STATE_WON. Queues a textbox
* announcing the win, then transitions to BATTLE_STATE_ENDING once
* dismissed.
*/
void battleStateWonInit(void);
/**
* Updates BATTLE_STATE_WON for one frame.
*/
void battleStateWonUpdate(void);
/**
* Called when the battle leaves BATTLE_STATE_WON.
*/
void battleStateWonDispose(void);
-15
View File
@@ -1,15 +0,0 @@
# Copyright (c) 2025 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
# Sources
target_sources(${DUSK_LIBRARY_TARGET_NAME}
PUBLIC
cutscene.c
cutsceneref.c
cutscenesystem.c
)
# Subdirs
add_subdirectory(item)
-178
View File
@@ -1,178 +0,0 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "cutscene.h"
#include "item/json/cutscenejsonpauseflags.h"
#include "util/memory.h"
#include "assert/assert.h"
#include "asset/asset.h"
#include "asset/loader/assetloader.h"
errorret_t cutsceneParseItem(
yyjson_val *itemObj,
cutsceneitem_t *item,
const uint8_t index
) {
assertNotNull(itemObj, "Item object cannot be NULL");
assertNotNull(item, "Item cannot be NULL");
if(!yyjson_is_obj(itemObj)) {
errorThrow("Cutscene item %u is not an object", (uint32_t)index);
}
const char_t *typeName = yyjson_get_str(yyjson_obj_get(itemObj, "type"));
if(!cutsceneItemLookupType(typeName, &item->type)) {
errorThrow(
"Cutscene item %u: missing/unsupported item type %s",
(uint32_t)index, typeName
);
}
cutsceneitemloadcallback_t *load = CUTSCENE_ITEM_CALLBACKS[item->type].load;
if(load == NULL) {
errorThrow(
"Cutscene item %u: unhandled item type %u",
(uint32_t)index, (uint32_t)item->type
);
}
errorret_t result = load(itemObj, item);
if(errorIsNotOk(result)) errorChain(result);
errorOk();
}
size_t cutsceneCountItems(yyjson_doc *doc) {
assertNotNull(doc, "Doc cannot be NULL");
yyjson_val *root = yyjson_doc_get_root(doc);
yyjson_val *itemsArr = yyjson_obj_get(root, "items");
if(!yyjson_is_arr(itemsArr)) return 0;
return yyjson_arr_size(itemsArr);
}
errorret_t cutsceneParseDoc(
yyjson_doc *doc,
cutscene_t *scene,
cutsceneitem_t *items,
size_t itemsMax
) {
assertNotNull(doc, "Doc cannot be NULL");
assertNotNull(scene, "Scene cannot be NULL");
assertNotNull(items, "Items cannot be NULL");
assertTrue(itemsMax > 0, "Items max cannot be 0");
yyjson_val *root = yyjson_doc_get_root(doc);
yyjson_val *itemsArr = yyjson_obj_get(root, "items");
if(!yyjson_is_arr(itemsArr)) {
errorThrow("Cutscene JSON is missing an 'items' array");
}
size_t itemCount = yyjson_arr_size(itemsArr);
if(itemCount > itemsMax) {
errorThrow("Cutscene has more items than its target buffer allows");
}
cutscenepause_t pause = CUTSCENE_PAUSE_DEFAULT;
yyjson_val *pauseArr = yyjson_obj_get(root, "pause");
if(yyjson_is_arr(pauseArr)) {
if(!cutsceneJsonParsePauseFlags(pauseArr, &pause)) {
errorThrow("Cutscene JSON has an invalid 'pause' flag");
}
}
memoryZero(items, itemCount * sizeof(cutsceneitem_t));
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 = cutsceneParseItem(itemVal, &items[index], index);
if(errorIsNotOk(itemResult)) errorChain(itemResult);
index++;
}
scene->itemCount = (uint8_t)itemCount;
scene->itemsMax = itemsMax;
scene->pause = pause;
errorOk();
}
void cutsceneAppendAt(
cutscene_t *scene,
const uint8_t atIndex,
const cutsceneitem_t *items,
const uint8_t count
) {
assertNotNull(scene, "Scene cannot be NULL");
assertNotNull(items, "Items cannot be NULL");
assertTrue(count > 0, "Count cannot be 0");
assertTrue(atIndex <= scene->itemCount, "atIndex out of bounds");
assertTrue(
(size_t)scene->itemCount + count <= scene->itemsMax,
"Cutscene item append exceeds itemsMax"
);
const size_t tailCount = (size_t)scene->itemCount - atIndex;
if(tailCount > 0) {
memoryMove(
&scene->items[atIndex + count],
&scene->items[atIndex],
tailCount * sizeof(cutsceneitem_t)
);
}
memoryCopy(&scene->items[atIndex], items, count * sizeof(cutsceneitem_t));
scene->itemCount += count;
}
void cutsceneAppend(
cutscene_t *scene,
const cutsceneitem_t *items,
const uint8_t count
) {
cutsceneAppendAt(scene, scene->itemCount, items, count);
}
void cutsceneAppendNext(
cutscene_t *scene,
const uint8_t currentIndex,
const cutsceneitem_t *items,
const uint8_t count
) {
cutsceneAppendAt(scene, (uint8_t)(currentIndex + 1), items, count);
}
errorret_t cutsceneLoadParse(
const char_t *path,
cutscene_t *scene,
cutsceneitem_t *items,
const size_t itemsMax
) {
assertNotNull(path, "Path cannot be NULL");
assertNotNull(scene, "Scene cannot be NULL");
assertNotNull(items, "Items cannot be NULL");
// Lock the asset, require it loaded.
assetentry_t *entry = assetLock(path, ASSET_LOADER_TYPE_JSON, NULL);
errorret_t result = assetRequireLoaded(entry);
if(errorIsNotOk(result)) {
assetUnlockEntry(entry);
errorChain(result);
}
// Parse the loaded JSON
errorret_t parseResult = cutsceneParseDoc(
entry->data.json, scene, items, itemsMax
);
// Free up the asset entry.
assetUnlockEntry(entry);
errorChain(parseResult);
errorOk();
}
-154
View File
@@ -1,154 +0,0 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "rpg/cutscene/item/cutsceneitem.h"
#include "rpg/cutscene/cutscenepause.h"
typedef struct cutscene_s {
cutsceneitem_t *items;
uint8_t itemCount;
// Capacity of items - see cutsceneAppend/cutsceneAppendAt/
// cutsceneAppendNext, which assert against this rather than taking a
// capacity parameter of their own. Set once, either by cutsceneParseDoc
// (to whatever itemsMax it was given) or by whoever declares a
// C-authored cutscene_t directly (to items' true array capacity, which
// may be larger than itemCount to leave room for a later append/insert).
size_t itemsMax;
cutscenepause_t pause;
} cutscene_t;
/**
* Parses one cutscene item object into item. Every field/enum name is
* validated as real (untrusted, authored) file content - failures are
* real errors, not asserts. Dispatches to the matching type's Load
* callback (see CUTSCENE_ITEM_CALLBACKS in item/cutsceneitem.h) - the
* per-type parsing logic itself lives there, colocated with that type's
* runtime behavior.
*
* @param itemObj The item's JSON object.
* @param item Destination item, already zeroed by the caller.
* @param index Index of this item within the cutscene, for error messages.
* @return Error code indicating success or failure of the parse.
*/
errorret_t cutsceneParseItem(
yyjson_val *itemObj,
cutsceneitem_t *item,
const uint8_t index
);
/**
* Counts how many entries are in doc's top-level "items" array, without
* parsing any of them - e.g. so a caller that wants to malloc its own
* items array instead of using a fixed one could size it first (we don't
* do that ourselves, but the option stays open).
*
* @param doc Already-parsed JSON document.
* @return Number of entries in "items", or 0 if it's missing/not an array.
*/
size_t cutsceneCountItems(yyjson_doc *doc);
/**
* Parses doc's "items" (and optional "pause") into items, and updates
* scene's itemCount/itemsMax/pause - scene->items is left untouched, since
* the caller already points it at items. Purely a parser: doesn't touch
* the asset system, doesn't lock/load anything, and doesn't take
* ownership of doc - the caller is responsible for both loading doc
* beforehand and for its lifetime afterward (though as of cutscene items
* owning their own string fields by value, nothing parsed here actually
* needs doc to survive past this call returning).
*
* @param doc Already-parsed JSON document to read from.
* @param scene Destination scene - itemCount/itemsMax/pause are
* overwritten.
* @param items Destination item array, capacity itemsMax.
* @param itemsMax Capacity of items.
* @return Error code indicating success or failure of the parse.
*/
errorret_t cutsceneParseDoc(
yyjson_doc *doc,
cutscene_t *scene,
cutsceneitem_t *items,
size_t itemsMax
);
/**
* Inserts items into scene->items starting at atIndex, growing
* scene->itemCount. Every existing item from atIndex onward shifts right
* by count to make room. Asserts if this would exceed scene->itemsMax.
*
* @param scene Cutscene to insert into.
* @param atIndex Index the first inserted item should end up at - must be
* <= scene->itemCount.
* @param items Items to insert, copied in order.
* @param count Number of entries in items.
*/
void cutsceneAppendAt(
cutscene_t *scene,
const uint8_t atIndex,
const cutsceneitem_t *items,
const uint8_t count
);
/**
* Same as cutsceneAppendAt, but always inserts at the end of
* scene->items.
*
* @param scene Cutscene to append to.
* @param items Items to append, copied in order.
* @param count Number of entries in items.
*/
void cutsceneAppend(
cutscene_t *scene,
const cutsceneitem_t *items,
const uint8_t count
);
/**
* Same as cutsceneAppendAt, but inserts right after currentIndex (i.e. at
* currentIndex + 1) instead of at a literal index - e.g. pass
* CUTSCENE_SYSTEM.currentItem to make these items run immediately after
* the currently-executing one. currentIndex may be 0xFF (nothing has run
* yet), which wraps to insert at index 0, matching that sentinel's usual
* meaning elsewhere in the cutscene system.
*
* @param scene Cutscene to insert into.
* @param currentIndex Index to insert after.
* @param items Items to insert, copied in order.
* @param count Number of entries in items.
*/
void cutsceneAppendNext(
cutscene_t *scene,
const uint8_t currentIndex,
const cutsceneitem_t *items,
const uint8_t count
);
/**
* Loads a cutscene JSON asset by path and parses it into scene/items (see
* cutsceneParseDoc) - the common "lock the asset, require it loaded,
* parse its 'items' array, unlock it again" sequence shared by every
* place that resolves a cutscene by file path (cutsceneSystemLoad,
* cutsceneCutsceneResolve, cutsceneInsertResolveAndSplice,
* battleStateExecutingInit, cutsceneSystemGoTo's reload). Purely propagates the
* error on failure (like cutsceneParseDoc) - this is core cutscene logic,
* not UI, so it doesn't reach for uiFatalErrorOpen itself; each caller
* decides how to surface the failure (typically errorCatch(errorPrint())
* + uiFatalErrorOpen(NULL), same as any other asset load failure).
*
* @param path Asset path of the cutscene JSON file to load.
* @param scene Destination scene - itemCount/itemsMax/pause overwritten.
* @param items Destination item array, capacity itemsMax.
* @param itemsMax Capacity of items.
* @return Error code indicating success or failure of the load/parse.
*/
errorret_t cutsceneLoadParse(
const char_t *path,
cutscene_t *scene,
cutsceneitem_t *items,
const size_t itemsMax
);
-26
View File
@@ -1,26 +0,0 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "dusk.h"
typedef uint8_t cutscenepause_t;
#define CUTSCENE_PAUSE_NONE ((cutscenepause_t)0)
#define CUTSCENE_PAUSE_NPC ((cutscenepause_t)(1 << 0))
#define CUTSCENE_PAUSE_PLAYER ((cutscenepause_t)(1 << 1))
#define CUTSCENE_PAUSE_WORLD ((cutscenepause_t)(1 << 2))
#define CUTSCENE_PAUSE_BATTLE ((cutscenepause_t)(1 << 3))
#define CUTSCENE_PAUSE_DEFAULT ((cutscenepause_t)( \
CUTSCENE_PAUSE_NPC | CUTSCENE_PAUSE_PLAYER \
))
#define CUTSCENE_PAUSE_ALL ((cutscenepause_t)( \
CUTSCENE_PAUSE_NPC | CUTSCENE_PAUSE_PLAYER | CUTSCENE_PAUSE_WORLD | \
CUTSCENE_PAUSE_BATTLE \
))
-24
View File
@@ -1,24 +0,0 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "cutsceneref.h"
#include "assert/assert.h"
void cutsceneRefReset(
cutsceneref_t *refs,
entity_t *interact,
entity_t *interacted
) {
assertNotNull(refs, "Refs cannot be null");
refs->entityInteract = interact;
refs->entityInteracted = interacted;
refs->entityLastCreated = NULL;
refs->entityLastRef = NULL;
refs->areaLastCreated = CUTSCENE_REF_AREA_LAST_CREATED;
refs->textMiniLastCreated = CUTSCENE_REF_TEXT_MINI_LAST_CREATED;
}
-36
View File
@@ -1,36 +0,0 @@
/**
* 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 entity_s entity_t;
#define CUTSCENE_REF_AREA_LAST_CREATED ((uint8_t)0xFF)
#define CUTSCENE_REF_TEXT_MINI_LAST_CREATED ((uint8_t)0xFA)
typedef struct {
entity_t *entityInteract;
entity_t *entityInteracted;
entity_t *entityLastCreated;
entity_t *entityLastRef;
uint8_t areaLastCreated;
uint8_t textMiniLastCreated;
} cutsceneref_t;
/**
* Resets refs to an empty state.
*
* @param refs Refs to reset.
* @param interact The entity that initiated the interaction, or NULL.
* @param interacted The entity being interacted with, or NULL.
*/
void cutsceneRefReset(
cutsceneref_t *refs,
entity_t *interact,
entity_t *interacted
);
-358
View File
@@ -1,358 +0,0 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "cutscenesystem.h"
#include "rpg/entity/entity.h"
#include "util/memory.h"
#include "util/string.h"
#include "assert/assert.h"
#include "ui/overlay/uifatalerror.h"
#include "save/slot/saveslot.h"
cutscenesystem_t CUTSCENE_SYSTEM;
void cutsceneSystemInit() {
memoryZero(&CUTSCENE_SYSTEM, sizeof(cutscenesystem_t));
CUTSCENE_SYSTEM.loadedScene.items = CUTSCENE_SYSTEM.loadedItems;
CUTSCENE_SYSTEM.loadedScene.itemsMax = CUTSCENE_LOADED_ITEMS_MAX;
}
void cutsceneSystemUpdate() {
if(CUTSCENE_SYSTEM.scene == NULL) return;
const cutsceneitem_t *item = cutsceneSystemGetCurrentItem();
if(cutsceneItemUpdate(item, &CUTSCENE_SYSTEM.data)) cutsceneSystemNext();
}
void cutsceneSystemDispose() {
CUTSCENE_SYSTEM.scene = NULL;
CUTSCENE_SYSTEM.currentItem = CUTSCENE_CURRENT_ITEM_NONE;
CUTSCENE_SYSTEM.pause = CUTSCENE_PAUSE_NONE;
cutsceneRefReset(&CUTSCENE_SYSTEM.refs, NULL, NULL);
CUTSCENE_SYSTEM.textCache[0] = '\0';
CUTSCENE_SYSTEM.onComplete = NULL;
CUTSCENE_SYSTEM.loadedFile[0] = '\0';
}
void cutsceneSystemPrepare(
cutscene_t *cutscene,
entity_t *interact,
entity_t *interacted
) {
assertNotNull(cutscene, "Cutscene cannot be NULL");
CUTSCENE_SYSTEM.scene = cutscene;
CUTSCENE_SYSTEM.pause = cutscene->pause;
cutsceneRefReset(&CUTSCENE_SYSTEM.refs, interact, interacted);
CUTSCENE_SYSTEM.textCache[0] = '\0';
CUTSCENE_SYSTEM.onComplete = NULL;
// cutsceneNext will cause overflow to index 0 (intentional).
CUTSCENE_SYSTEM.currentItem = CUTSCENE_CURRENT_ITEM_NONE;
// Clear loaded file if cutscene not running from file.
if(cutscene != &CUTSCENE_SYSTEM.loadedScene) {
CUTSCENE_SYSTEM.loadedFile[0] = '\0';
}
}
void cutsceneSystemStartCutscene(cutscene_t *cutscene) {
cutsceneSystemStartCutsceneWith(cutscene, NULL, NULL);
}
void cutsceneSystemStartCutsceneWith(
cutscene_t *cutscene,
entity_t *interact,
entity_t *interacted
) {
assertNotNull(cutscene, "Cutscene cannot be NULL");
assertTrue(
cutscene->itemCount <= cutscene->itemsMax,
"Cutscene itemCount exceeds itemsMax"
);
// Prep cutscene, save it to the save slot, and advance, aka overflow to 0.
cutsceneSystemPrepare(cutscene, interact, interacted);
saveSlotSetCurrentCutscene(CUTSCENE_SYSTEM.loadedFile);
cutsceneSystemNext();
}
void cutsceneSystemStartCutsceneAndGoToMarker(
cutscene_t *cutscene,
const char_t *marker
) {
assertNotNull(marker, "Marker cannot be NULL");
// Restarts the cutscene
cutsceneSystemPrepare(cutscene, NULL, NULL);
cutsceneSystemGoTo(marker);
}
void cutsceneSystemInsertItemsNext(
const cutsceneitem_t *items,
const size_t itemCount
) {
assertNotNull(items, "Items cannot be NULL");
assertNotNull(
CUTSCENE_SYSTEM.scene,
"cutsceneSystemInsertItemsNext called with no cutscene running"
);
cutsceneAppendNext(
CUTSCENE_SYSTEM.scene, CUTSCENE_SYSTEM.currentItem, items, itemCount
);
}
void cutsceneSystemInsertItems(
const cutsceneitem_t *items,
const size_t itemCount
) {
cutsceneSystemInsertItemsNext(items, itemCount);
cutsceneSystemNext();
}
void cutsceneSystemInsertCutscene(const cutscene_t *cutscene) {
assertNotNull(cutscene, "Cutscene cannot be NULL");
cutsceneSystemInsertItems(cutscene->items, cutscene->itemCount);
}
void cutsceneSystemClearAfter(const uint8_t index) {
assertNotNull(
CUTSCENE_SYSTEM.scene,
"cutsceneSystemClearAfter called with no cutscene running"
);
assertTrue(
index < CUTSCENE_SYSTEM.scene->itemCount,
"cutsceneSystemClearAfter index out of range"
);
CUTSCENE_SYSTEM.scene->itemCount = index + 1;
}
void cutsceneSystemLoad(const char_t *file) {
assertNotNull(file, "File cannot be NULL");
// Take a copy of file, as it may be a part of the cutscene itself.
char_t fileCopy[ASSET_FILE_NAME_MAX];
stringCopy(fileCopy, file, ASSET_FILE_NAME_MAX - 1);
// Load the cutscene asset, parse it, and start it.
errorret_t result = cutsceneLoadParse(
fileCopy, &CUTSCENE_SYSTEM.loadedScene, CUTSCENE_SYSTEM.loadedItems,
CUTSCENE_LOADED_ITEMS_MAX
);
if(errorIsNotOk(result)) {
errorCatch(errorPrint(result));
uiFatalErrorOpen(NULL);
return;
}
// Store the loaded file so we can restart if needed.
stringCopy(CUTSCENE_SYSTEM.loadedFile, fileCopy, ASSET_FILE_NAME_MAX - 1);
cutsceneSystemStartCutscene(&CUTSCENE_SYSTEM.loadedScene);
}
void cutsceneRestart(void) {
assertNotNull(
CUTSCENE_SYSTEM.scene, "cutsceneRestart called with no cutscene running"
);
assertTrue(
CUTSCENE_SYSTEM.scene == &CUTSCENE_SYSTEM.loadedScene,
"cutsceneRestart called with a cutscene not loaded from file"
);
assertTrue(
CUTSCENE_SYSTEM.loadedFile[0] != '\0',
"cutsceneRestart called with no loaded file"
);
// Copy the refs and callbacks
cutscenecallback_t onComplete = CUTSCENE_SYSTEM.onComplete;
cutsceneref_t refs = CUTSCENE_SYSTEM.refs;
// Reload the file.
char_t file[ASSET_FILE_NAME_MAX];
stringCopy(file, CUTSCENE_SYSTEM.loadedFile, ASSET_FILE_NAME_MAX - 1);
cutsceneSystemLoad(file);
// Restore the refs and callbacks.
CUTSCENE_SYSTEM.onComplete = onComplete;
CUTSCENE_SYSTEM.refs = refs;
}
void cutsceneSystemSetOnComplete(cutscenecallback_t onComplete) {
assertNotNull(
CUTSCENE_SYSTEM.scene,
"cutsceneSystemSetOnComplete called with no cutscene running"
);
CUTSCENE_SYSTEM.onComplete = onComplete;
}
entity_t * cutsceneSystemGetEntity(const uint8_t entityIndex) {
entity_t *entity;
if(entityIndex == CUTSCENE_ENTITY_INTERACT) {
assertNotNull(
CUTSCENE_SYSTEM.refs.entityInteract,
"CUTSCENE_ENTITY_INTERACT used but no interact entity is set"
);
entity = CUTSCENE_SYSTEM.refs.entityInteract;
} else if(entityIndex == CUTSCENE_ENTITY_INTERACTED) {
assertNotNull(
CUTSCENE_SYSTEM.refs.entityInteracted,
"CUTSCENE_ENTITY_INTERACTED used but no interacted entity is set"
);
entity = CUTSCENE_SYSTEM.refs.entityInteracted;
} else if(entityIndex == CUTSCENE_ENTITY_LAST_CREATED) {
assertNotNull(
CUTSCENE_SYSTEM.refs.entityLastCreated,
"CUTSCENE_ENTITY_LAST_CREATED used but no entity has been created"
);
entity = CUTSCENE_SYSTEM.refs.entityLastCreated;
} else if(entityIndex == CUTSCENE_ENTITY_LAST_REF) {
assertNotNull(
CUTSCENE_SYSTEM.refs.entityLastRef,
"CUTSCENE_ENTITY_LAST_REF used but no entity has been referenced"
);
entity = CUTSCENE_SYSTEM.refs.entityLastRef;
} else {
assertTrue(
entityIndex < ENTITY_COUNT,
"Entity index is out of range"
);
entity = &ENTITIES[entityIndex];
}
CUTSCENE_SYSTEM.refs.entityLastRef = entity;
return entity;
}
uint8_t cutsceneSystemGetAreaId(const uint8_t areaId) {
if(areaId == CUTSCENE_REF_AREA_LAST_CREATED) {
assertTrue(
CUTSCENE_SYSTEM.refs.areaLastCreated != CUTSCENE_REF_AREA_LAST_CREATED,
"CUTSCENE_REF_AREA_LAST_CREATED used but no map area has been created"
);
return CUTSCENE_SYSTEM.refs.areaLastCreated;
}
return areaId;
}
uint8_t cutsceneSystemGetTextMiniId(const uint8_t index) {
if(index == CUTSCENE_REF_TEXT_MINI_LAST_CREATED) {
assertTrue(
CUTSCENE_SYSTEM.refs.textMiniLastCreated !=
CUTSCENE_REF_TEXT_MINI_LAST_CREATED,
"CUTSCENE_REF_TEXT_MINI_LAST_CREATED used but no mini textbox has been "
"shown"
);
return CUTSCENE_SYSTEM.refs.textMiniLastCreated;
}
return index;
}
const char_t * cutsceneSystemGetTextCache(void) {
return CUTSCENE_SYSTEM.textCache;
}
void cutsceneSystemSetTextCache(const char_t *text) {
assertNotNull(text, "Text cannot be NULL");
stringCopy(
CUTSCENE_SYSTEM.textCache, text, CUTSCENE_TEXT_CACHE_MAX - 1
);
}
void cutsceneSystemNext() {
if(CUTSCENE_SYSTEM.scene == NULL) return;
// Pop the just-finished item off the front.
if(CUTSCENE_SYSTEM.currentItem == CUTSCENE_CURRENT_ITEM_NONE) {
CUTSCENE_SYSTEM.currentItem = 0;
} else {
cutscene_t *scene = CUTSCENE_SYSTEM.scene;
const size_t tailCount = (size_t)scene->itemCount - 1;
if(tailCount > 0) {
memoryMove(
&scene->items[0], &scene->items[1], tailCount * sizeof(cutsceneitem_t)
);
}
scene->itemCount--;
}
// End of the cutscene?
if(CUTSCENE_SYSTEM.scene->itemCount == 0) {
cutscenecallback_t onComplete = CUTSCENE_SYSTEM.onComplete;
CUTSCENE_SYSTEM.scene = NULL;
CUTSCENE_SYSTEM.pause = CUTSCENE_PAUSE_NONE;
if(onComplete != NULL) onComplete(NULL);
return;
}
// Start next (now current) item
const cutsceneitem_t *item = cutsceneSystemGetCurrentItem();
memset(&CUTSCENE_SYSTEM.data, 0, sizeof(CUTSCENE_SYSTEM.data));
cutsceneItemStart(item, &CUTSCENE_SYSTEM.data);
}
void cutsceneSystemGoTo(const char_t *name) {
assertNotNull(name, "Name cannot be NULL");
assertNotNull(
CUTSCENE_SYSTEM.scene, "cutsceneSystemGoTo called with no cutscene running"
);
assertTrue(
CUTSCENE_SYSTEM.scene == &CUTSCENE_SYSTEM.loadedScene,
"cutsceneSystemGoTo requires the running cutscene file reference (1)"
);
assertTrue(
CUTSCENE_SYSTEM.loadedFile[0] != '\0',
"cutsceneSystemGoTo requires the running cutscene file reference (2)"
);
cutscene_t freshScene = { .items = CUTSCENE_SYSTEM.gotoScratchItems };
errorret_t result = cutsceneLoadParse(
CUTSCENE_SYSTEM.loadedFile, &freshScene, CUTSCENE_SYSTEM.gotoScratchItems,
CUTSCENE_LOADED_ITEMS_MAX
);
if(errorIsNotOk(result)) {
errorCatch(errorPrint(result));
uiFatalErrorOpen(NULL);
return;
}
// Search for the marker with the given name...
for(uint8_t i = 0; i < freshScene.itemCount; i++) {
const cutsceneitem_t *item = &freshScene.items[i];
if(
item->type != CUTSCENE_ITEM_TYPE_MARKER ||
!stringEquals(item->marker.name, name)
) continue;
// Found, so splice the cutscene at that point and start it, the remaining
// items being the rest of the cutscene after the marker.
const uint8_t remaining = freshScene.itemCount - i;
memoryCopy(
CUTSCENE_SYSTEM.loadedItems, &freshScene.items[i],
remaining * sizeof(cutsceneitem_t)
);
CUTSCENE_SYSTEM.loadedScene.itemCount = remaining;
CUTSCENE_SYSTEM.currentItem = 0;
memoryZero(&CUTSCENE_SYSTEM.data, sizeof(CUTSCENE_SYSTEM.data));
cutsceneItemStart(
&CUTSCENE_SYSTEM.loadedItems[0], &CUTSCENE_SYSTEM.data
);
return;
}
assertTrue(false, "cutsceneSystemGoTo: no marker found with that name");
}
const cutsceneitem_t * cutsceneSystemGetCurrentItem() {
if(CUTSCENE_SYSTEM.scene == NULL) return NULL;
return &CUTSCENE_SYSTEM.scene->items[0];
}
-241
View File
@@ -1,241 +0,0 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "cutscene.h"
#include "cutsceneref.h"
#define CUTSCENE_ENTITY_INTERACT ((uint8_t)0xFE)
#define CUTSCENE_ENTITY_INTERACTED ((uint8_t)0xFD)
#define CUTSCENE_ENTITY_LAST_CREATED ((uint8_t)0xFC)
#define CUTSCENE_ENTITY_LAST_REF ((uint8_t)0xFB)
#define CUTSCENE_CURRENT_ITEM_NONE ((uint8_t)0xFF)
#define CUTSCENE_TEXT_CACHE_MAX 64
#define CUTSCENE_LOADED_ITEMS_MAX 128
#define CUTSCENE_INSERT_ITEMS_MAX 16
typedef struct {
cutscene_t *scene;
uint8_t currentItem;
cutscenepause_t pause;
cutsceneref_t refs;
// Free-form text cache for the running cutscene - see
// cutsceneSystemGetTextCache/cutsceneSystemSetTextCache.
char_t textCache[CUTSCENE_TEXT_CACHE_MAX];
// Runtime data for the current item.
cutsceneitemdata_t data;
// See cutsceneSystemSetOnComplete.
cutscenecallback_t onComplete;
// Cache and storage used for the dynamically loaded cutscenes.
cutsceneitem_t loadedItems[CUTSCENE_LOADED_ITEMS_MAX];
cutscene_t loadedScene;
char_t loadedFile[ASSET_FILE_NAME_MAX];
// Cutscene items scratch, mostly used for CUTSCENE_INSERT items.
cutsceneitem_t gotoScratchItems[CUTSCENE_LOADED_ITEMS_MAX];
} cutscenesystem_t;
extern cutscenesystem_t CUTSCENE_SYSTEM;
/**
* Initialize the cutscene system.
*/
void cutsceneSystemInit();
/**
* Disposes of the cutscene system, stopping any active cutscene.
*/
void cutsceneSystemDispose();
/**
* Resets CUTSCENE_SYSTEM to run cutscene from its first item, binding
* interact/interacted entities. Does not itself advance to the first item.
*
* @param cutscene Pointer to the cutscene to prepare.
* @param interact The entity that initiated the interaction (player), or
* NULL.
* @param interacted The entity being interacted with (NPC), or NULL.
*/
void cutsceneSystemPrepare(
cutscene_t *cutscene,
entity_t *interact,
entity_t *interacted
);
/**
* Start a cutscene with no bound entities.
*
* @param cutscene Pointer to the cutscene to start.
*/
void cutsceneSystemStartCutscene(cutscene_t *cutscene);
/**
* Start a cutscene with the two entities that triggered it.
*
* @param cutscene Pointer to the cutscene to start.
* @param interact The entity that initiated the interaction (player).
* @param interacted The entity that was interacted with (NPC).
*/
void cutsceneSystemStartCutsceneWith(
cutscene_t *cutscene,
entity_t *interact,
entity_t *interacted
);
/**
* Starts a cutscene with no bound entities, jumping straight to the
* marker with the given name instead of running from the first item.
* Asserts if no marker with that name exists.
*
* @param cutscene Pointer to the cutscene to start.
* @param marker Marker name to jump to.
*/
void cutsceneSystemStartCutsceneAndGoToMarker(
cutscene_t *cutscene,
const char_t *marker
);
/**
* Splices items into the running cutscene so that items[0] becomes the
* very next item, without otherwise disturbing the currently-running
* item's progress.
*
* @param items Items to splice in.
* @param itemCount Number of items in items.
*/
void cutsceneSystemInsertItemsNext(
const cutsceneitem_t *items,
const size_t itemCount
);
/**
* Splices items into the running cutscene right after the current item
* (see cutsceneSystemInsertItemsNext), then immediately advances into the
* first spliced item.
*
* @param items Items to splice in.
* @param itemCount Number of items in items.
*/
void cutsceneSystemInsertItems(
const cutsceneitem_t *items,
const size_t itemCount
);
/**
* Splices cutscene's items into the running cutscene.
*
* @param cutscene The cutscene whose items to splice in.
*/
void cutsceneSystemInsertCutscene(const cutscene_t *cutscene);
/**
* Discards every item queued after index (e.g. index 0 keeps only the
* currently-running item and drops everything spliced in behind it),
* without disturbing index's own progress - e.g. so a callback that
* decides the rest of a batch-spliced sequence is now moot (a battle
* ending mid-round, with other fighters' still-queued move cutscenes and
* the round's trailing state transition left behind) can drop it before
* splicing in its own follow-up items, instead of leaving it to run
* afterward against torn-down state.
*
* @param index Index to keep - everything after it is discarded. Must be
* < the running cutscene's current item count.
*/
void cutsceneSystemClearAfter(const uint8_t index);
/**
* Loads and immediately starts a cutscene asset by file name.
*
* @param file Cutscene file name.
*/
void cutsceneSystemLoad(const char_t *file);
/**
* Restarts the currently running cutscene. Will perform a load if the cutscene
* was initially from a file.
*/
void cutsceneRestart(void);
/**
* Sets a native callback to fire once when the currently running cutscene
* finishes.
*
* @param onComplete Callback to fire on completion.
*/
void cutsceneSystemSetOnComplete(cutscenecallback_t onComplete);
/**
* Resolves a raw entity index (or sentinel) to an entity pointer.
*
* @param entityIndex Raw entity index or sentinel value.
* @returns Pointer to the resolved entity.
*/
entity_t * cutsceneSystemGetEntity(const uint8_t entityIndex);
/**
* Resolves a raw map area ID (or CUTSCENE_REF_AREA_LAST_CREATED sentinel) to
* a concrete map area ID.
*
* @param areaId Raw map area ID or sentinel value.
* @returns The resolved map area ID.
*/
uint8_t cutsceneSystemGetAreaId(const uint8_t areaId);
/**
* Resolves a raw mini textbox slot index (or CUTSCENE_REF_TEXT_MINI_LAST_CREATED
* sentinel) to a concrete UI_TEXTBOX_MINI_LIST slot index.
*
* @param index Raw slot index or sentinel value.
* @returns The resolved slot index.
*/
uint8_t cutsceneSystemGetTextMiniId(const uint8_t index);
/**
* Returns the running cutscene's cached text - see
* cutsceneSystemSetTextCache. Empty ("") if nothing has been cached yet.
*
* @returns The cached text.
*/
const char_t * cutsceneSystemGetTextCache(void);
/**
* Overwrites the running cutscene's cached text.
*
* @param text The text to cache; copied internally.
*/
void cutsceneSystemSetTextCache(const char_t *text);
/**
* Advance to the next item in the cutscene.
*/
void cutsceneSystemNext();
/**
* Jumps to a cutscene marker directly. If the cutscene is a loaded cutscene,
* this will result in it being reloaded (due to unshift nature of cutscenes).
*
* @param name Marker name to search for.
*/
void cutsceneSystemGoTo(const char_t *name);
/**
* Update the cutscene system for one frame.
*/
void cutsceneSystemUpdate();
/**
* Get the current cutscene item.
*
* @return Pointer to the current cutscene item.
*/
const cutsceneitem_t * cutsceneSystemGetCurrentItem();
-24
View File
@@ -1,24 +0,0 @@
# Copyright (c) 2025 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
target_sources(${DUSK_LIBRARY_TARGET_NAME}
PUBLIC
cutsceneitem.c
cutsceneitembase.c
cutscenecallback.c
cutsceneprint.c
)
add_subdirectory(control)
add_subdirectory(entity)
add_subdirectory(item)
add_subdirectory(maparea)
add_subdirectory(ui)
add_subdirectory(battle)
add_subdirectory(save)
add_subdirectory(audio)
add_subdirectory(json)
add_subdirectory(story)
add_subdirectory(party)
@@ -1,17 +0,0 @@
# Copyright (c) 2026 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
target_sources(${DUSK_LIBRARY_TARGET_NAME}
PUBLIC
cutsceneaudioplay.c
cutsceneaudiostop.c
cutsceneaudiopause.c
cutsceneaudioresume.c
cutsceneaudiofade.c
cutsceneaudiofadewait.c
cutsceneaudiosetpan.c
cutsceneaudiosetloop.c
cutsceneaudioset.c
)
@@ -1,59 +0,0 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "rpg/cutscene/item/cutsceneitem.h"
#include "audio/mixer/audiomixer.h"
#include "rpg/cutscene/item/json/cutscenejsonaudiochannel.h"
#include "rpg/cutscene/item/json/cutscenejsoneasing.h"
#include "rpg/cutscene/item/json/cutscenejsonfield.h"
void cutsceneAudioFadeStart(
const cutsceneitem_t *item,
cutsceneitemdata_t *data
) {
audioMixerFadeTo(
item->audioFade.channel,
item->audioFade.from,
item->audioFade.to,
item->audioFade.duration,
item->audioFade.easing
);
}
bool_t cutsceneAudioFadeUpdate(
const cutsceneitem_t *item,
cutsceneitemdata_t *data
) {
return true;
}
errorret_t cutsceneAudioFadeLoad(
yyjson_val *itemObj,
cutsceneitem_t *item
) {
audiomixerchannel_t channelValue;
if(!cutsceneJsonLookupAudioChannel(
yyjson_get_str(yyjson_obj_get(itemObj, "channel")), &channelValue
)) {
errorThrow("Cutscene item (AUDIO_FADE): invalid 'channel'");
}
item->audioFade.channel = channelValue;
item->audioFade.from = cutsceneJsonGetFloat(itemObj, "from", 0.0f);
item->audioFade.to = cutsceneJsonGetFloat(itemObj, "to", 0.0f);
item->audioFade.duration = cutsceneJsonGetFloat(itemObj, "duration", 0.0f);
const char_t *easingName =
yyjson_get_str(yyjson_obj_get(itemObj, "easing"));
easingtype_t easingValue = EASING_LINEAR;
if(easingName != NULL &&
!cutsceneJsonLookupEasing(easingName, &easingValue)) {
errorThrow("Cutscene item (AUDIO_FADE): invalid 'easing'");
}
item->audioFade.easing = easingValue;
errorOk();
}
@@ -1,56 +0,0 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "audio/mixer/audiomixerchannel.h"
#include "animation/easing.h"
#include "rpg/cutscene/item/cutsceneitembase.h"
typedef struct {
audiomixerchannel_t channel;
float_t from;
float_t to;
float_t duration;
easingtype_t easing;
} cutsceneaudiofade_t;
/**
* 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).
*
* @param item The cutscene item.
* @param data Runtime data storage.
*/
void cutsceneAudioFadeStart(
const cutsceneitem_t *item,
cutsceneitemdata_t *data
);
/**
* Updates an audio fade step (always completes immediately - the fade
* itself keeps running independently of cutscene progression).
*
* @param item The cutscene item.
* @param data Runtime data storage.
* @returns true always.
*/
bool_t cutsceneAudioFadeUpdate(
const cutsceneitem_t *item,
cutsceneitemdata_t *data
);
/**
* Parses an AUDIO_FADE cutscene item's JSON fields into item.
*
* @param itemObj The item's JSON object.
* @param item Destination item, already zeroed by the caller.
* @return Error code indicating success or failure of the parse.
*/
errorret_t cutsceneAudioFadeLoad(
yyjson_val *itemObj,
cutsceneitem_t *item
);
@@ -1,24 +0,0 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "rpg/cutscene/item/cutsceneitem.h"
#include "audio/mixer/audiomixer.h"
#include "rpg/cutscene/item/json/cutscenejsonaudiochannel.h"
bool_t cutsceneAudioFadeWaitUpdate(
const cutsceneitem_t *item,
cutsceneitemdata_t *data
) {
return !audioMixerIsFading(item->audioFadeWaitChannel);
}
errorret_t cutsceneAudioFadeWaitLoad(
yyjson_val *itemObj,
cutsceneitem_t *item
) {
return cutsceneJsonLoadAudioChannelOnly(itemObj, &item->audioFadeWaitChannel);
}
@@ -1,36 +0,0 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "audio/mixer/audiomixerchannel.h"
#include "rpg/cutscene/item/cutsceneitembase.h"
/**
* Updates an audio fade-wait step, completing once the watched channel's
* fade (started by a CUTSCENE_AUDIO_FADE elsewhere) finishes. Has no Start
* callback -- there's nothing to do until the fade is actually done.
*
* @param item The cutscene item.
* @param data Runtime data storage.
* @returns true once the channel is no longer fading.
*/
bool_t cutsceneAudioFadeWaitUpdate(
const cutsceneitem_t *item,
cutsceneitemdata_t *data
);
/**
* Parses an AUDIO_FADE_WAIT cutscene item's JSON fields into item.
*
* @param itemObj The item's JSON object.
* @param item Destination item, already zeroed by the caller.
* @return Error code indicating success or failure of the parse.
*/
errorret_t cutsceneAudioFadeWaitLoad(
yyjson_val *itemObj,
cutsceneitem_t *item
);
@@ -1,31 +0,0 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "rpg/cutscene/item/cutsceneitem.h"
#include "audio/mixer/audiomixer.h"
#include "rpg/cutscene/item/json/cutscenejsonaudiochannel.h"
void cutsceneAudioPauseStart(
const cutsceneitem_t *item,
cutsceneitemdata_t *data
) {
audioMixerPause(item->audioPauseChannel);
}
bool_t cutsceneAudioPauseUpdate(
const cutsceneitem_t *item,
cutsceneitemdata_t *data
) {
return true;
}
errorret_t cutsceneAudioPauseLoad(
yyjson_val *itemObj,
cutsceneitem_t *item
) {
return cutsceneJsonLoadAudioChannelOnly(itemObj, &item->audioPauseChannel);
}
@@ -1,45 +0,0 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "audio/mixer/audiomixerchannel.h"
#include "rpg/cutscene/item/cutsceneitembase.h"
/**
* Starts an audio pause step (pauses the channel immediately).
*
* @param item The cutscene item.
* @param data Runtime data storage.
*/
void cutsceneAudioPauseStart(
const cutsceneitem_t *item,
cutsceneitemdata_t *data
);
/**
* Updates an audio pause step (always completes immediately).
*
* @param item The cutscene item.
* @param data Runtime data storage.
* @returns true always.
*/
bool_t cutsceneAudioPauseUpdate(
const cutsceneitem_t *item,
cutsceneitemdata_t *data
);
/**
* Parses an AUDIO_PAUSE cutscene item's JSON fields into item.
*
* @param itemObj The item's JSON object.
* @param item Destination item, already zeroed by the caller.
* @return Error code indicating success or failure of the parse.
*/
errorret_t cutsceneAudioPauseLoad(
yyjson_val *itemObj,
cutsceneitem_t *item
);
@@ -1,62 +0,0 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "rpg/cutscene/item/cutsceneitem.h"
#include "rpg/cutscene/item/json/cutscenejsonaudiochannel.h"
#include "rpg/cutscene/item/json/cutscenejsonfield.h"
void cutsceneAudioPlayStart(
const cutsceneitem_t *item,
cutsceneitemdata_t *data
) {
audioMixerQueuePlay(
item->audioPlay.file,
item->audioPlay.channel,
item->audioPlay.volume,
item->audioPlay.pan,
item->audioPlay.looping,
item->audioPlay.loopCount,
item->audioPlay.loopStart,
item->audioPlay.loopTo
);
}
bool_t cutsceneAudioPlayUpdate(
const cutsceneitem_t *item,
cutsceneitemdata_t *data
) {
return true;
}
errorret_t cutsceneAudioPlayLoad(
yyjson_val *itemObj,
cutsceneitem_t *item
) {
if(!cutsceneJsonCopyString(
itemObj, "file", NULL, item->audioPlay.file, AUDIO_PATH_MAX
)) {
errorThrow("Cutscene item (AUDIO_PLAY): missing/too-long 'file'");
}
audiomixerchannel_t channelValue;
if(!cutsceneJsonLookupAudioChannel(
yyjson_get_str(yyjson_obj_get(itemObj, "channel")), &channelValue
)) {
errorThrow("Cutscene item (AUDIO_PLAY): invalid 'channel'");
}
item->audioPlay.channel = channelValue;
item->audioPlay.volume = cutsceneJsonGetFloat(itemObj, "volume", 1.0f);
item->audioPlay.pan = cutsceneJsonGetFloat(itemObj, "pan", 0.0f);
item->audioPlay.looping = cutsceneJsonGetBool(itemObj, "looping", false);
item->audioPlay.loopCount =
(uint8_t)cutsceneJsonGetInt(itemObj, "loopCount", 0);
item->audioPlay.loopStart =
cutsceneJsonGetFloat(itemObj, "loopStart", -1.0f);
item->audioPlay.loopTo = cutsceneJsonGetFloat(itemObj, "loopTo", 0.0f);
errorOk();
}
@@ -1,58 +0,0 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "audio/mixer/audiomixer.h"
#include "rpg/cutscene/item/cutsceneitembase.h"
typedef struct {
char_t file[AUDIO_PATH_MAX];
audiomixerchannel_t channel;
float_t volume;
float_t pan;
bool_t looping;
uint8_t loopCount;
float_t loopStart;
float_t loopTo;
} cutsceneaudioplay_t;
/**
* Starts an audio play step (queues the sound via audioMixerQueuePlay() -
* see its own comment on when it actually starts).
*
* @param item The cutscene item.
* @param data Runtime data storage.
*/
void cutsceneAudioPlayStart(
const cutsceneitem_t *item,
cutsceneitemdata_t *data
);
/**
* Updates an audio play step (always completes immediately - the sound
* keeps loading/playing independently of cutscene progression).
*
* @param item The cutscene item.
* @param data Runtime data storage.
* @returns true always.
*/
bool_t cutsceneAudioPlayUpdate(
const cutsceneitem_t *item,
cutsceneitemdata_t *data
);
/**
* Parses an AUDIO_PLAY cutscene item's JSON fields into item.
*
* @param itemObj The item's JSON object.
* @param item Destination item, already zeroed by the caller.
* @return Error code indicating success or failure of the parse.
*/
errorret_t cutsceneAudioPlayLoad(
yyjson_val *itemObj,
cutsceneitem_t *item
);
@@ -1,31 +0,0 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "rpg/cutscene/item/cutsceneitem.h"
#include "audio/mixer/audiomixer.h"
#include "rpg/cutscene/item/json/cutscenejsonaudiochannel.h"
void cutsceneAudioResumeStart(
const cutsceneitem_t *item,
cutsceneitemdata_t *data
) {
audioMixerResume(item->audioResumeChannel);
}
bool_t cutsceneAudioResumeUpdate(
const cutsceneitem_t *item,
cutsceneitemdata_t *data
) {
return true;
}
errorret_t cutsceneAudioResumeLoad(
yyjson_val *itemObj,
cutsceneitem_t *item
) {
return cutsceneJsonLoadAudioChannelOnly(itemObj, &item->audioResumeChannel);
}
@@ -1,45 +0,0 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "audio/mixer/audiomixerchannel.h"
#include "rpg/cutscene/item/cutsceneitembase.h"
/**
* Starts an audio resume step (resumes the channel immediately).
*
* @param item The cutscene item.
* @param data Runtime data storage.
*/
void cutsceneAudioResumeStart(
const cutsceneitem_t *item,
cutsceneitemdata_t *data
);
/**
* Updates an audio resume step (always completes immediately).
*
* @param item The cutscene item.
* @param data Runtime data storage.
* @returns true always.
*/
bool_t cutsceneAudioResumeUpdate(
const cutsceneitem_t *item,
cutsceneitemdata_t *data
);
/**
* Parses an AUDIO_RESUME cutscene item's JSON fields into item.
*
* @param itemObj The item's JSON object.
* @param item Destination item, already zeroed by the caller.
* @return Error code indicating success or failure of the parse.
*/
errorret_t cutsceneAudioResumeLoad(
yyjson_val *itemObj,
cutsceneitem_t *item
);
@@ -1,54 +0,0 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "rpg/cutscene/item/cutsceneitem.h"
#include "audio/mixer/audiomixer.h"
#include "rpg/cutscene/item/json/cutscenejsonaudiochannel.h"
#include "rpg/cutscene/item/json/cutscenejsonfield.h"
void cutsceneAudioSetStart(
const cutsceneitem_t *item,
cutsceneitemdata_t *data
) {
audioMixerSetPan(item->audioSet.channel, item->audioSet.pan);
audioMixerSetLoop(
item->audioSet.channel,
item->audioSet.looping,
item->audioSet.loopCount,
item->audioSet.loopStart,
item->audioSet.loopTo
);
}
bool_t cutsceneAudioSetUpdate(
const cutsceneitem_t *item,
cutsceneitemdata_t *data
) {
return true;
}
errorret_t cutsceneAudioSetLoad(
yyjson_val *itemObj,
cutsceneitem_t *item
) {
audiomixerchannel_t channelValue;
if(!cutsceneJsonLookupAudioChannel(
yyjson_get_str(yyjson_obj_get(itemObj, "channel")), &channelValue
)) {
errorThrow("Cutscene item (AUDIO_SET): invalid 'channel'");
}
item->audioSet.channel = channelValue;
item->audioSet.pan = cutsceneJsonGetFloat(itemObj, "pan", 0.0f);
item->audioSet.looping = cutsceneJsonGetBool(itemObj, "looping", true);
item->audioSet.loopCount =
(uint8_t)cutsceneJsonGetInt(itemObj, "loopCount", 0);
item->audioSet.loopStart =
cutsceneJsonGetFloat(itemObj, "loopStart", -1.0f);
item->audioSet.loopTo = cutsceneJsonGetFloat(itemObj, "loopTo", 0.0f);
errorOk();
}
@@ -1,57 +0,0 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "audio/mixer/audiomixerchannel.h"
#include "rpg/cutscene/item/cutsceneitembase.h"
typedef struct {
audiomixerchannel_t channel;
float_t pan;
bool_t looping;
uint8_t loopCount;
float_t loopStart;
float_t loopTo;
} cutsceneaudioset_t;
/**
* Starts an audio set step - applies pan and looping behaviour together in
* one item (via audioMixerSetPan()/audioMixerSetLoop()), for when you want
* to change both at once rather than using CUTSCENE_AUDIO_SET_PAN/
* CUTSCENE_AUDIO_SET_LOOP separately.
*
* @param item The cutscene item.
* @param data Runtime data storage.
*/
void cutsceneAudioSetStart(
const cutsceneitem_t *item,
cutsceneitemdata_t *data
);
/**
* Updates an audio set step (always completes immediately).
*
* @param item The cutscene item.
* @param data Runtime data storage.
* @returns true always.
*/
bool_t cutsceneAudioSetUpdate(
const cutsceneitem_t *item,
cutsceneitemdata_t *data
);
/**
* Parses an AUDIO_SET cutscene item's JSON fields into item.
*
* @param itemObj The item's JSON object.
* @param item Destination item, already zeroed by the caller.
* @return Error code indicating success or failure of the parse.
*/
errorret_t cutsceneAudioSetLoad(
yyjson_val *itemObj,
cutsceneitem_t *item
);
@@ -1,52 +0,0 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "rpg/cutscene/item/cutsceneitem.h"
#include "audio/mixer/audiomixer.h"
#include "rpg/cutscene/item/json/cutscenejsonaudiochannel.h"
#include "rpg/cutscene/item/json/cutscenejsonfield.h"
void cutsceneAudioSetLoopStart(
const cutsceneitem_t *item,
cutsceneitemdata_t *data
) {
audioMixerSetLoop(
item->audioSetLoop.channel,
item->audioSetLoop.looping,
item->audioSetLoop.loopCount,
item->audioSetLoop.loopStart,
item->audioSetLoop.loopTo
);
}
bool_t cutsceneAudioSetLoopUpdate(
const cutsceneitem_t *item,
cutsceneitemdata_t *data
) {
return true;
}
errorret_t cutsceneAudioSetLoopLoad(
yyjson_val *itemObj,
cutsceneitem_t *item
) {
audiomixerchannel_t channelValue;
if(!cutsceneJsonLookupAudioChannel(
yyjson_get_str(yyjson_obj_get(itemObj, "channel")), &channelValue
)) {
errorThrow("Cutscene item (AUDIO_SET_LOOP): invalid 'channel'");
}
item->audioSetLoop.channel = channelValue;
item->audioSetLoop.looping = cutsceneJsonGetBool(itemObj, "looping", true);
item->audioSetLoop.loopCount =
(uint8_t)cutsceneJsonGetInt(itemObj, "loopCount", 0);
item->audioSetLoop.loopStart =
cutsceneJsonGetFloat(itemObj, "loopStart", -1.0f);
item->audioSetLoop.loopTo = cutsceneJsonGetFloat(itemObj, "loopTo", 0.0f);
errorOk();
}
@@ -1,54 +0,0 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "audio/mixer/audiomixerchannel.h"
#include "rpg/cutscene/item/cutsceneitembase.h"
typedef struct {
audiomixerchannel_t channel;
bool_t looping;
uint8_t loopCount;
float_t loopStart;
float_t loopTo;
} cutsceneaudiosetloop_t;
/**
* Starts an audio set-loop step (applies the new looping behaviour
* immediately, via audioMixerSetLoop()).
*
* @param item The cutscene item.
* @param data Runtime data storage.
*/
void cutsceneAudioSetLoopStart(
const cutsceneitem_t *item,
cutsceneitemdata_t *data
);
/**
* Updates an audio set-loop step (always completes immediately).
*
* @param item The cutscene item.
* @param data Runtime data storage.
* @returns true always.
*/
bool_t cutsceneAudioSetLoopUpdate(
const cutsceneitem_t *item,
cutsceneitemdata_t *data
);
/**
* Parses an AUDIO_SET_LOOP cutscene item's JSON fields into item.
*
* @param itemObj The item's JSON object.
* @param item Destination item, already zeroed by the caller.
* @return Error code indicating success or failure of the parse.
*/
errorret_t cutsceneAudioSetLoopLoad(
yyjson_val *itemObj,
cutsceneitem_t *item
);
@@ -1,41 +0,0 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "rpg/cutscene/item/cutsceneitem.h"
#include "audio/mixer/audiomixer.h"
#include "rpg/cutscene/item/json/cutscenejsonaudiochannel.h"
#include "rpg/cutscene/item/json/cutscenejsonfield.h"
void cutsceneAudioSetPanStart(
const cutsceneitem_t *item,
cutsceneitemdata_t *data
) {
audioMixerSetPan(item->audioSetPan.channel, item->audioSetPan.pan);
}
bool_t cutsceneAudioSetPanUpdate(
const cutsceneitem_t *item,
cutsceneitemdata_t *data
) {
return true;
}
errorret_t cutsceneAudioSetPanLoad(
yyjson_val *itemObj,
cutsceneitem_t *item
) {
audiomixerchannel_t channelValue;
if(!cutsceneJsonLookupAudioChannel(
yyjson_get_str(yyjson_obj_get(itemObj, "channel")), &channelValue
)) {
errorThrow("Cutscene item (AUDIO_SET_PAN): invalid 'channel'");
}
item->audioSetPan.channel = channelValue;
item->audioSetPan.pan = cutsceneJsonGetFloat(itemObj, "pan", 0.0f);
errorOk();
}
@@ -1,51 +0,0 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "audio/mixer/audiomixerchannel.h"
#include "rpg/cutscene/item/cutsceneitembase.h"
typedef struct {
audiomixerchannel_t channel;
float_t pan;
} cutsceneaudiosetpan_t;
/**
* Starts an audio set-pan step (applies the new pan immediately, via
* audioMixerSetPan()).
*
* @param item The cutscene item.
* @param data Runtime data storage.
*/
void cutsceneAudioSetPanStart(
const cutsceneitem_t *item,
cutsceneitemdata_t *data
);
/**
* Updates an audio set-pan step (always completes immediately).
*
* @param item The cutscene item.
* @param data Runtime data storage.
* @returns true always.
*/
bool_t cutsceneAudioSetPanUpdate(
const cutsceneitem_t *item,
cutsceneitemdata_t *data
);
/**
* Parses an AUDIO_SET_PAN cutscene item's JSON fields into item.
*
* @param itemObj The item's JSON object.
* @param item Destination item, already zeroed by the caller.
* @return Error code indicating success or failure of the parse.
*/
errorret_t cutsceneAudioSetPanLoad(
yyjson_val *itemObj,
cutsceneitem_t *item
);
@@ -1,31 +0,0 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "rpg/cutscene/item/cutsceneitem.h"
#include "audio/mixer/audiomixer.h"
#include "rpg/cutscene/item/json/cutscenejsonaudiochannel.h"
void cutsceneAudioStopStart(
const cutsceneitem_t *item,
cutsceneitemdata_t *data
) {
audioMixerStop(item->audioStopChannel);
}
bool_t cutsceneAudioStopUpdate(
const cutsceneitem_t *item,
cutsceneitemdata_t *data
) {
return true;
}
errorret_t cutsceneAudioStopLoad(
yyjson_val *itemObj,
cutsceneitem_t *item
) {
return cutsceneJsonLoadAudioChannelOnly(itemObj, &item->audioStopChannel);
}
@@ -1,45 +0,0 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "audio/mixer/audiomixerchannel.h"
#include "rpg/cutscene/item/cutsceneitembase.h"
/**
* Starts an audio stop step (stops the channel immediately).
*
* @param item The cutscene item.
* @param data Runtime data storage.
*/
void cutsceneAudioStopStart(
const cutsceneitem_t *item,
cutsceneitemdata_t *data
);
/**
* Updates an audio stop step (always completes immediately).
*
* @param item The cutscene item.
* @param data Runtime data storage.
* @returns true always.
*/
bool_t cutsceneAudioStopUpdate(
const cutsceneitem_t *item,
cutsceneitemdata_t *data
);
/**
* Parses an AUDIO_STOP cutscene item's JSON fields into item.
*
* @param itemObj The item's JSON object.
* @param item Destination item, already zeroed by the caller.
* @return Error code indicating success or failure of the parse.
*/
errorret_t cutsceneAudioStopLoad(
yyjson_val *itemObj,
cutsceneitem_t *item
);
@@ -1,14 +0,0 @@
# Copyright (c) 2026 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
target_sources(${DUSK_LIBRARY_TARGET_NAME}
PUBLIC
cutscenebattlestart.c
cutscenebattlesetstate.c
cutscenebattlewaitselection.c
cutscenebattlepostmove.c
cutscenebattlefighterdamage.c
cutscenebattlefighterheal.c
)
@@ -1,68 +0,0 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "rpg/cutscene/item/cutsceneitem.h"
#include "rpg/battle/battle.h"
#include "rpg/cutscene/item/json/cutscenejsonfield.h"
#include "assert/assert.h"
#include "util/string.h"
#define CUTSCENE_BATTLE_FIGHTER_REF_MAX 16
void cutsceneBattleFighterDamageStart(
const cutsceneitem_t *item,
cutsceneitemdata_t *data
) {
const cutscenebattlefighterdamage_t *damage = &item->battleFighterDamage;
assertTrue(
damage->fighterIndex < BATTLE_FIGHTER_POS_COUNT,
"fighterIndex sentinel was never resolved"
);
battlefighter_t *fighter = BATTLE.fighters[damage->fighterIndex];
assertNotNull(fighter, "Fighter cannot be NULL");
battleFighterDamage(fighter, damage->amount);
}
bool_t cutsceneBattleFighterDamageUpdate(
const cutsceneitem_t *item,
cutsceneitemdata_t *data
) {
return true;
}
errorret_t cutsceneBattleFighterDamageLoad(
yyjson_val *itemObj,
cutsceneitem_t *item
) {
char_t fighterRef[CUTSCENE_BATTLE_FIGHTER_REF_MAX];
if(!cutsceneJsonCopyString(
itemObj, "fighter", NULL, fighterRef, CUTSCENE_BATTLE_FIGHTER_REF_MAX
)) {
errorThrow("Cutscene item (BATTLE_FIGHTER_DAMAGE): missing 'fighter'");
}
if(stringEquals(fighterRef, "target")) {
item->battleFighterDamage.fighterIndex = BATTLE_FIGHTER_POS_TARGET;
} else if(stringEquals(fighterRef, "user")) {
item->battleFighterDamage.fighterIndex = BATTLE_FIGHTER_POS_USER;
} else {
errorThrow(
"Cutscene item (BATTLE_FIGHTER_DAMAGE): 'fighter' must be "
"'target' or 'user'"
);
}
const int32_t amount = cutsceneJsonGetInt(itemObj, "amount", -1);
if(amount < 0 || amount > UINT16_MAX) {
errorThrow(
"Cutscene item (BATTLE_FIGHTER_DAMAGE): invalid/missing 'amount'"
);
}
item->battleFighterDamage.amount = (uint16_t)amount;
errorOk();
}
@@ -1,55 +0,0 @@
/**
* 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"
#include "rpg/battle/fighter/battlefighterpos.h"
typedef struct {
// Index into BATTLE.fighters of the fighter to damage, or one of
// BATTLE_FIGHTER_POS_TARGET/BATTLE_FIGHTER_POS_USER, resolved against
// the currently-executing action by battleStateExecutingInit before
// this item ever runs.
battlefighterpos_t fighterIndex;
uint16_t amount;
} cutscenebattlefighterdamage_t;
/**
* Starts a BATTLE_FIGHTER_DAMAGE item, applying the configured damage to
* BATTLE.fighters[fighterIndex] immediately.
*
* @param item The cutscene item.
* @param data Runtime data storage.
*/
void cutsceneBattleFighterDamageStart(
const cutsceneitem_t *item,
cutsceneitemdata_t *data
);
/**
* Updates a BATTLE_FIGHTER_DAMAGE item (always completes immediately).
*
* @param item The cutscene item.
* @param data Runtime data storage.
* @returns true always.
*/
bool_t cutsceneBattleFighterDamageUpdate(
const cutsceneitem_t *item,
cutsceneitemdata_t *data
);
/**
* Parses a BATTLE_FIGHTER_DAMAGE cutscene item's JSON fields into item.
*
* @param itemObj The item's JSON object.
* @param item Destination item, already zeroed by the caller.
* @return Error code indicating success or failure of the parse.
*/
errorret_t cutsceneBattleFighterDamageLoad(
yyjson_val *itemObj,
cutsceneitem_t *item
);
@@ -1,68 +0,0 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "rpg/cutscene/item/cutsceneitem.h"
#include "rpg/battle/battle.h"
#include "rpg/cutscene/item/json/cutscenejsonfield.h"
#include "assert/assert.h"
#include "util/string.h"
#define CUTSCENE_BATTLE_FIGHTER_REF_MAX 16
void cutsceneBattleFighterHealStart(
const cutsceneitem_t *item,
cutsceneitemdata_t *data
) {
const cutscenebattlefighterheal_t *heal = &item->battleFighterHeal;
assertTrue(
heal->fighterIndex < BATTLE_FIGHTER_POS_COUNT,
"fighterIndex sentinel was never resolved"
);
battlefighter_t *fighter = BATTLE.fighters[heal->fighterIndex];
assertNotNull(fighter, "Fighter cannot be NULL");
battleFighterHeal(fighter, heal->amount);
}
bool_t cutsceneBattleFighterHealUpdate(
const cutsceneitem_t *item,
cutsceneitemdata_t *data
) {
return true;
}
errorret_t cutsceneBattleFighterHealLoad(
yyjson_val *itemObj,
cutsceneitem_t *item
) {
char_t fighterRef[CUTSCENE_BATTLE_FIGHTER_REF_MAX];
if(!cutsceneJsonCopyString(
itemObj, "fighter", NULL, fighterRef, CUTSCENE_BATTLE_FIGHTER_REF_MAX
)) {
errorThrow("Cutscene item (BATTLE_FIGHTER_HEAL): missing 'fighter'");
}
if(stringEquals(fighterRef, "target")) {
item->battleFighterHeal.fighterIndex = BATTLE_FIGHTER_POS_TARGET;
} else if(stringEquals(fighterRef, "user")) {
item->battleFighterHeal.fighterIndex = BATTLE_FIGHTER_POS_USER;
} else {
errorThrow(
"Cutscene item (BATTLE_FIGHTER_HEAL): 'fighter' must be "
"'target' or 'user'"
);
}
const int32_t amount = cutsceneJsonGetInt(itemObj, "amount", -1);
if(amount < 0 || amount > UINT16_MAX) {
errorThrow(
"Cutscene item (BATTLE_FIGHTER_HEAL): invalid/missing 'amount'"
);
}
item->battleFighterHeal.amount = (uint16_t)amount;
errorOk();
}
@@ -1,55 +0,0 @@
/**
* 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"
#include "rpg/battle/fighter/battlefighterpos.h"
typedef struct {
// Index into BATTLE.fighters of the fighter to heal, or one of
// BATTLE_FIGHTER_POS_TARGET/BATTLE_FIGHTER_POS_USER, resolved against
// the currently-executing action by battleStateExecutingInit before
// this item ever runs.
battlefighterpos_t fighterIndex;
uint16_t amount;
} cutscenebattlefighterheal_t;
/**
* Starts a BATTLE_FIGHTER_HEAL item, applying the configured heal to
* BATTLE.fighters[fighterIndex] immediately.
*
* @param item The cutscene item.
* @param data Runtime data storage.
*/
void cutsceneBattleFighterHealStart(
const cutsceneitem_t *item,
cutsceneitemdata_t *data
);
/**
* Updates a BATTLE_FIGHTER_HEAL item (always completes immediately).
*
* @param item The cutscene item.
* @param data Runtime data storage.
* @returns true always.
*/
bool_t cutsceneBattleFighterHealUpdate(
const cutsceneitem_t *item,
cutsceneitemdata_t *data
);
/**
* Parses a BATTLE_FIGHTER_HEAL cutscene item's JSON fields into item.
*
* @param itemObj The item's JSON object.
* @param item Destination item, already zeroed by the caller.
* @return Error code indicating success or failure of the parse.
*/
errorret_t cutsceneBattleFighterHealLoad(
yyjson_val *itemObj,
cutsceneitem_t *item
);
@@ -1,60 +0,0 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "rpg/cutscene/item/cutsceneitem.h"
#include "rpg/battle/battle.h"
#include "rpg/cutscene/cutscenesystem.h"
#include "console/console.h"
void cutsceneBattlePostMoveStart(
const cutsceneitem_t *item,
cutsceneitemdata_t *data
) {
consolePrint("BATTLE_POST_MOVE\n");
// Once a result has already been decided (e.g. the player fled), there
// is nothing left to check.
if(BATTLE.result != BATTLE_RESULT_NONE) return;
bool_t allyAlive = false;
bool_t enemyAlive = false;
for(uint8_t i = 0; i < BATTLE_FIGHTER_POS_COUNT; i++) {
battlefighter_t *fighter = BATTLE.fighters[i];
if(fighter == NULL) continue;
if(!battleFighterIsAlive(fighter)) continue;
if(fighter->team == BATTLE_FIGHTER_TEAM_ALLY) allyAlive = true;
else enemyAlive = true;
}
if(allyAlive && enemyAlive) return;
BATTLE.result = allyAlive ? BATTLE_RESULT_WIN : BATTLE_RESULT_LOSS;
// Drop the rest of this round's already-spliced items (other fighters'
// still-pending move cutscenes, the trailing BATTLE_SET_STATE(PRE_ROUND) -
// see battleStateExecutingInit) - the battle is over, so none of that
// should run against the WON/LOST/ENDING transition about to replace it.
cutsceneSystemClearAfter(CUTSCENE_SYSTEM.currentItem);
const cutsceneitem_t items[] = {
{
.type = CUTSCENE_ITEM_TYPE_BATTLE_SET_STATE,
.battleSetState = {
.state = allyAlive ? BATTLE_STATE_WON : BATTLE_STATE_LOST
}
}
};
cutsceneSystemInsertItemsNext(items, sizeof(items) / sizeof(cutsceneitem_t));
}
bool_t cutsceneBattlePostMoveUpdate(
const cutsceneitem_t *item,
cutsceneitemdata_t *data
) {
return true;
}
@@ -1,37 +0,0 @@
/**
* 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"
/**
* Starts a BATTLE_POST_MOVE item. Runs after each queued move's cutscene
* finishes: checks whether every ally or every enemy fighter has been
* knocked out and, if so, sets BATTLE.result and splices in a
* BATTLE_SET_STATE to BATTLE_STATE_WON/LOST. No-ops the health check if
* BATTLE.result is already set (e.g. the player fled). Not
* JSON-authorable -- constructed dynamically by battleStateExecutingInit.
*
* @param item The cutscene item.
* @param data Runtime data storage.
*/
void cutsceneBattlePostMoveStart(
const cutsceneitem_t *item,
cutsceneitemdata_t *data
);
/**
* Updates a BATTLE_POST_MOVE item (always completes immediately).
*
* @param item The cutscene item.
* @param data Runtime data storage.
* @returns true always.
*/
bool_t cutsceneBattlePostMoveUpdate(
const cutsceneitem_t *item,
cutsceneitemdata_t *data
);
@@ -1,41 +0,0 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "rpg/cutscene/item/cutsceneitem.h"
#include "rpg/battle/battle.h"
#include "rpg/cutscene/item/json/cutscenejsonbattlestate.h"
#include "assert/assert.h"
void cutsceneBattleSetStateStart(
const cutsceneitem_t *item,
cutsceneitemdata_t *data
) {
assertNotNull(item, "item cannot be NULL");
battleSetState(item->battleSetState.state);
}
bool_t cutsceneBattleSetStateUpdate(
const cutsceneitem_t *item,
cutsceneitemdata_t *data
) {
return true;
}
errorret_t cutsceneBattleSetStateLoad(
yyjson_val *itemObj,
cutsceneitem_t *item
) {
battlestate_t state;
if(!cutsceneJsonLookupBattleState(
yyjson_get_str(yyjson_obj_get(itemObj, "state")), &state
)) {
errorThrow("Cutscene item (BATTLE_SET_STATE): invalid 'state'");
}
item->battleSetState.state = state;
errorOk();
}
@@ -1,50 +0,0 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "rpg/battle/state/battlestate.h"
#include "rpg/cutscene/item/cutsceneitembase.h"
typedef struct {
battlestate_t state;
} cutscenebattlesetstate_t;
/**
* Starts a BATTLE_SET_STATE item, transitioning the battle to the
* configured state immediately.
*
* @param item The cutscene item.
* @param data Runtime data storage.
*/
void cutsceneBattleSetStateStart(
const cutsceneitem_t *item,
cutsceneitemdata_t *data
);
/**
* Updates a BATTLE_SET_STATE item (always completes immediately).
*
* @param item The cutscene item.
* @param data Runtime data storage.
* @returns true always.
*/
bool_t cutsceneBattleSetStateUpdate(
const cutsceneitem_t *item,
cutsceneitemdata_t *data
);
/**
* Parses a BATTLE_SET_STATE cutscene item's JSON fields into item.
*
* @param itemObj The item's JSON object.
* @param item Destination item, already zeroed by the caller.
* @return Error code indicating success or failure of the parse.
*/
errorret_t cutsceneBattleSetStateLoad(
yyjson_val *itemObj,
cutsceneitem_t *item
);
@@ -1,95 +0,0 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "rpg/cutscene/item/cutsceneitem.h"
#include "rpg/battle/battle.h"
#include "rpg/battle/party.h"
#include "assert/assert.h"
#include "util/memory.h"
battlefighter_t CUTSCENE_BATTLE_START_ENEMY_POOL[
CUTSCENE_BATTLE_START_ENEMY_COUNT_MAX
];
void cutsceneBattleStartStart(
const cutsceneitem_t *item,
cutsceneitemdata_t *data
) {
assertNotNull(item, "item cannot be NULL");
const cutscenebattlestart_t *config = &item->battleStart;
assertTrue(
config->enemyCount <= CUTSCENE_BATTLE_START_ENEMY_COUNT_MAX,
"enemyCount out of bounds"
);
battlefighter_t *fighters[BATTLE_FIGHTER_POS_COUNT] = { 0 };
memoryZero(
CUTSCENE_BATTLE_START_ENEMY_POOL,
sizeof(CUTSCENE_BATTLE_START_ENEMY_POOL)
);
for(uint8_t i = 0; i < config->enemyCount; i++) {
battlefighter_t *enemy = &CUTSCENE_BATTLE_START_ENEMY_POOL[i];
*enemy = config->enemies[i].fighter;
fighters[i] = enemy;
}
for(uint8_t i = 0; i < PARTY_ACTIVE_SIZE_MAX; i++) {
battlefighter_t *member = partyGetOrderMember(i);
if(member == NULL) continue;
fighters[BATTLE_FIGHTER_POS_4 + i] = member;
}
battleStart(fighters);
}
bool_t cutsceneBattleStartUpdate(
const cutsceneitem_t *item,
cutsceneitemdata_t *data
) {
return true;
}
errorret_t cutsceneBattleStartLoad(
yyjson_val *itemObj,
cutsceneitem_t *item
) {
yyjson_val *enemies = yyjson_obj_get(itemObj, "enemies");
size_t enemyCount = yyjson_arr_size(enemies);
if(
!yyjson_is_arr(enemies) || enemyCount == 0 ||
enemyCount > CUTSCENE_BATTLE_START_ENEMY_COUNT_MAX
) {
errorThrow(
"Cutscene item (BATTLE_START): 'enemies' must have 1-%u entries",
(uint32_t)CUTSCENE_BATTLE_START_ENEMY_COUNT_MAX
);
}
item->battleStart.enemyCount = (uint8_t)enemyCount;
yyjson_arr_iter iter = yyjson_arr_iter_with(enemies);
yyjson_val *enemyVal;
size_t e = 0;
while((enemyVal = yyjson_arr_iter_next(&iter)) != NULL) {
cutscenebattlestartenemy_t *enemy = &item->battleStart.enemies[e];
errorret_t parseResult = battleFighterParse(&enemy->fighter, enemyVal);
if(errorIsNotOk(parseResult)) errorChain(parseResult);
// Enemy JSON never specifies team/controller (battleFighterParse just
// defaulted them to ALLY/PLAYER) - BATTLE_START enemies are always
// ENEMY/AI.
enemy->fighter.team = BATTLE_FIGHTER_TEAM_ENEMY;
enemy->fighter.controller = BATTLE_FIGHTER_CONTROLLER_AI;
e++;
}
errorOk();
}
@@ -1,64 +0,0 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "rpg/battle/fighter/battlefighter.h"
#include "rpg/cutscene/item/cutsceneitembase.h"
// Enemies always occupy the left-side positions (BATTLE_FIGHTER_POS_0-3).
#define CUTSCENE_BATTLE_START_ENEMY_COUNT_MAX 4
typedef struct {
// Fully parsed at Load time via battleFighterParse (team/controller
// forced to ENEMY/AI right after, since enemy JSON only ever supplies
// stats/abilities) - Start splices this directly into
// CUTSCENE_BATTLE_START_ENEMY_POOL, no further init needed.
battlefighter_t fighter;
} cutscenebattlestartenemy_t;
typedef struct {
cutscenebattlestartenemy_t enemies[CUTSCENE_BATTLE_START_ENEMY_COUNT_MAX];
uint8_t enemyCount;
} cutscenebattlestart_t;
/**
* Starts a BATTLE_START item: spawns the configured enemies, fills the
* remaining positions with the active party (via partyGetOrderMember), and
* calls battleStart. Always completes immediately - the battle scene takes
* over from here.
*
* @param item The cutscene item.
* @param data Runtime data storage.
*/
void cutsceneBattleStartStart(
const cutsceneitem_t *item,
cutsceneitemdata_t *data
);
/**
* Updates a BATTLE_START item (always completes immediately).
*
* @param item The cutscene item.
* @param data Runtime data storage.
* @returns true always.
*/
bool_t cutsceneBattleStartUpdate(
const cutsceneitem_t *item,
cutsceneitemdata_t *data
);
/**
* Parses a BATTLE_START cutscene item's JSON fields into item.
*
* @param itemObj The item's JSON object.
* @param item Destination item, already zeroed by the caller.
* @return Error code indicating success or failure of the parse.
*/
errorret_t cutsceneBattleStartLoad(
yyjson_val *itemObj,
cutsceneitem_t *item
);
@@ -1,29 +0,0 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "rpg/cutscene/item/cutsceneitem.h"
#include "rpg/cutscene/cutscenesystem.h"
#include "rpg/battle/battle.h"
#include "rpg/battle/state/battlestateselection.h"
bool_t cutsceneBattleWaitSelectionUpdate(
const cutsceneitem_t *item,
cutsceneitemdata_t *data
) {
if(BATTLE.state != BATTLE_STATE_SELECTION) return true;
if(!battleStateSelectionIsComplete()) return false;
// Every fighter has decided - queue the move to BATTLE_STATE_EXECUTING.
const cutsceneitem_t items[] = {
{
.type = CUTSCENE_ITEM_TYPE_BATTLE_SET_STATE,
.battleSetState = { .state = BATTLE_STATE_EXECUTING }
}
};
cutsceneSystemInsertItemsNext(items, sizeof(items) / sizeof(cutsceneitem_t));
return true;
}
@@ -1,27 +0,0 @@
/**
* 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 BATTLE_WAIT_SELECTION step, completing once every fighter has
* decided a move this round (letting the queued BATTLE_SET_STATE step
* that follows move the battle on to BATTLE_STATE_EXECUTING) or once the
* selecting fighter has fled (moving on to BATTLE_STATE_FLED). Has no
* Start callback -- there's nothing to do until selection actually
* finishes.
*
* @param item The cutscene item.
* @param data Runtime data storage.
* @returns true once selection has completed or the battle has left
* BATTLE_STATE_SELECTION.
*/
bool_t cutsceneBattleWaitSelectionUpdate(
const cutsceneitem_t *item,
cutsceneitemdata_t *data
);
@@ -1,16 +0,0 @@
# Copyright (c) 2026 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
target_sources(${DUSK_LIBRARY_TARGET_NAME}
PUBLIC
cutscenewait.c
cutscenesetpause.c
cutsceneconcurrent.c
cutscenemarker.c
cutscenerestart.c
cutscenequitgame.c
cutscenescene.c
cutsceneidle.c
)
@@ -1,46 +0,0 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "rpg/cutscene/item/cutsceneitem.h"
#include "assert/assert.h"
void cutsceneConcurrentStart(
const cutsceneitem_t *item,
cutsceneitemdata_t *data
) {
assertTrue(
item->concurrent.count <= CUTSCENE_CONCURRENT_MAX,
"Too many items in CUTSCENE_CONCURRENT"
);
for(uint8_t i = 0; i < item->concurrent.count; i++) {
assertTrue(
item->concurrent.items[i].type != CUTSCENE_ITEM_TYPE_CONCURRENT,
"Concurrent items cannot be nested"
);
cutsceneItemStart(
&item->concurrent.items[i],
(cutsceneitemdata_t *)&data->concurrent.childData[i]
);
}
}
bool_t cutsceneConcurrentUpdate(
const cutsceneitem_t *item,
cutsceneitemdata_t *data
) {
for(uint8_t i = 0; i < item->concurrent.count; i++) {
if(data->concurrent.doneMask & (1u << i)) continue;
if(cutsceneItemUpdate(
&item->concurrent.items[i],
(cutsceneitemdata_t *)&data->concurrent.childData[i]
)) {
data->concurrent.doneMask |= (uint8_t)(1u << i);
}
}
uint8_t allDone = (uint8_t)((1u << item->concurrent.count) - 1u);
return data->concurrent.doneMask == allDone;
}
@@ -1,60 +0,0 @@
/**
* 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"
#include "cutscenewait.h"
#include "rpg/cutscene/item/entity/cutsceneentitywalkto.h"
/** Maximum number of items that may run inside a CUTSCENE_CONCURRENT. */
#define CUTSCENE_CONCURRENT_MAX 8
/**
* Static (const) data for a concurrent cutscene item.
*/
typedef struct {
const cutsceneitem_t *items;
uint8_t count;
} cutsceneconcurrent_t;
/**
* Runtime data for one non-concurrent child item.
* Concurrent items cannot be nested.
*/
typedef union {
cutscenewaitdata_t wait;
cutsceneentitywalktodata_t entityWalkTo;
} cutsceneconcurrentchilddata_t;
/** Runtime data for a running concurrent item. */
typedef struct {
cutsceneconcurrentchilddata_t childData[CUTSCENE_CONCURRENT_MAX];
uint8_t doneMask;
} cutsceneconcurrentdata_t;
/**
* Starts a concurrent item (starts all child items simultaneously).
*
* @param item The cutscene item.
* @param data Runtime data storage.
*/
void cutsceneConcurrentStart(
const cutsceneitem_t *item,
cutsceneitemdata_t *data
);
/**
* Updates a concurrent item (ticks all unfinished children).
*
* @param item The cutscene item.
* @param data Runtime data storage.
* @returns true once every child has completed.
*/
bool_t cutsceneConcurrentUpdate(
const cutsceneitem_t *item,
cutsceneitemdata_t *data
);
Loaded 100 of 464 files, more files were not shown because too many files have changed in this diff. Show more