Cutscene defs

This commit is contained in:
2026-07-02 11:32:31 -05:00
parent 7b98e40ccf
commit fdc4e056f9
9 changed files with 34 additions and 80 deletions
-1
View File
@@ -7,7 +7,6 @@
target_sources(${DUSK_LIBRARY_TARGET_NAME} target_sources(${DUSK_LIBRARY_TARGET_NAME}
PUBLIC PUBLIC
cutscenesystem.c cutscenesystem.c
cutscenemode.c
) )
# Subdirs # Subdirs
+22 -2
View File
@@ -7,10 +7,30 @@
#pragma once #pragma once
#include "rpg/cutscene/item/cutsceneitem.h" #include "rpg/cutscene/item/cutsceneitem.h"
#include "cutscenepause.h" #include "rpg/cutscene/cutscenepause.h"
typedef struct cutscene_s { typedef struct cutscene_s {
const cutsceneitem_t *items; const cutsceneitem_t *items;
uint8_t itemCount; uint8_t itemCount;
cutscenepause_t pause; cutscenepause_t pause;
} cutscene_t; } cutscene_t;
#define CUTSCENE(NAME, PAUSE_TYPE, ...) \
static const cutsceneitem_t CUTSCENE_##NAME##_ITEMS[] = { __VA_ARGS__ }; \
static const cutscene_t CUTSCENE_##NAME = { \
.items = CUTSCENE_##NAME##_ITEMS, \
.itemCount = sizeof(CUTSCENE_##NAME##_ITEMS) / sizeof(cutsceneitem_t), \
.pause = CUTSCENE_PAUSE_##PAUSE_TYPE \
};
#define CUTSCENE_REFERENCE(CUTSCENE) \
&CUTSCENE_##CUTSCENE
#define CUTSCENE_TEXT(TEXT) \
{ .type = CUTSCENE_ITEM_TYPE_TEXT, .text = { .text = TEXT } }
#define CUTSCENE_WAIT(WAIT) \
{ .type = CUTSCENE_ITEM_TYPE_WAIT, .wait = WAIT }
#define CUTSCENE_CUTSCENE(CUTSCENE) \
{ .type = CUTSCENE_ITEM_TYPE_CUTSCENE, .cutscene = CUTSCENE_REFERENCE(CUTSCENE) }
-19
View File
@@ -1,19 +0,0 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "rpg/cutscene/cutscenesystem.h"
bool_t cutsceneModeIsInputAllowed() {
switch(CUTSCENE_SYSTEM.mode) {
case CUTSCENE_MODE_FULL_FREEZE:
case CUTSCENE_MODE_INPUT_FREEZE:
return false;
default:
return true;
}
}
-26
View File
@@ -1,26 +0,0 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "dusk.h"
typedef enum {
CUTSCENE_MODE_NONE,
CUTSCENE_MODE_FULL_FREEZE,
CUTSCENE_MODE_INPUT_FREEZE,
CUTSCENE_MODE_GAMEPLAY
} cutscenemode_t;
// Default mode for all cutscenes.
#define CUTSCENE_MODE_INITIAL CUTSCENE_MODE_INPUT_FREEZE
/**
* Check if input is allowed in the current cutscene mode.
*
* @return true if input is allowed, false otherwise.
*/
bool_t cutsceneModeIsInputAllowed();
-3
View File
@@ -16,7 +16,6 @@ void cutsceneSystemInit() {
void cutsceneSystemStartCutscene(const cutscene_t *cutscene) { void cutsceneSystemStartCutscene(const cutscene_t *cutscene) {
CUTSCENE_SYSTEM.scene = cutscene; CUTSCENE_SYSTEM.scene = cutscene;
CUTSCENE_SYSTEM.mode = CUTSCENE_MODE_INITIAL;
CUTSCENE_SYSTEM.currentItem = 0xFF;// Set to 0xFF so start wraps. CUTSCENE_SYSTEM.currentItem = 0xFF;// Set to 0xFF so start wraps.
cutsceneSystemNext(); cutsceneSystemNext();
} }
@@ -39,7 +38,6 @@ void cutsceneSystemNext() {
) { ) {
CUTSCENE_SYSTEM.scene = NULL; CUTSCENE_SYSTEM.scene = NULL;
CUTSCENE_SYSTEM.currentItem = 0xFF; CUTSCENE_SYSTEM.currentItem = 0xFF;
CUTSCENE_SYSTEM.mode = CUTSCENE_MODE_NONE;
return; return;
} }
@@ -58,5 +56,4 @@ const cutsceneitem_t * cutsceneSystemGetCurrentItem() {
void cutsceneSystemDispose() { void cutsceneSystemDispose() {
CUTSCENE_SYSTEM.scene = NULL; CUTSCENE_SYSTEM.scene = NULL;
CUTSCENE_SYSTEM.currentItem = 0xFF; CUTSCENE_SYSTEM.currentItem = 0xFF;
CUTSCENE_SYSTEM.mode = CUTSCENE_MODE_NONE;
} }
-2
View File
@@ -7,7 +7,6 @@
#pragma once #pragma once
#include "cutscene.h" #include "cutscene.h"
#include "cutscenemode.h"
typedef struct { typedef struct {
const cutscene_t *scene; const cutscene_t *scene;
@@ -15,7 +14,6 @@ typedef struct {
// Data (used by the current item). // Data (used by the current item).
cutsceneitemdata_t data; cutsceneitemdata_t data;
cutscenemode_t mode;
} cutscenesystem_t; } cutscenesystem_t;
extern cutscenesystem_t CUTSCENE_SYSTEM; extern cutscenesystem_t CUTSCENE_SYSTEM;
+10 -21
View File
@@ -6,26 +6,15 @@
*/ */
#pragma once #pragma once
#include "rpg/cutscene/cutscenesystem.h" #include "rpg/cutscene/cutscene.h"
static const cutsceneitem_t TEST_CUTSCENE_ONE_ITEMS[] = { CUTSCENE(TEST_ONE, DEFAULT,
{ .type = CUTSCENE_ITEM_TYPE_TEXT, .text = { .text = "This is a test cutscene." } }, CUTSCENE_TEXT("This is a test cutscene."),
{ .type = CUTSCENE_ITEM_TYPE_WAIT, .wait = 0.5f }, CUTSCENE_WAIT(0.5f),
{ .type = CUTSCENE_ITEM_TYPE_TEXT, .text = { .text = "It has multiple lines of text.\nAnd waits in between." } }, CUTSCENE_TEXT("It has multiple lines of text.\nAnd waits in between.")
}; );
static const cutscene_t TEST_CUTSCENE_ONE = { CUTSCENE(TEST_TWO, DEFAULT,
.items = TEST_CUTSCENE_ONE_ITEMS, CUTSCENE_WAIT(0.1f),
.itemCount = sizeof(TEST_CUTSCENE_ONE_ITEMS) / sizeof(cutsceneitem_t) CUTSCENE_CUTSCENE(TEST_ONE),
}; );
static const cutsceneitem_t TEST_CUTSCENE_TWO_ITEMS[] = {
{ .type = CUTSCENE_ITEM_TYPE_WAIT, .wait = 0.1f },
{ .type = CUTSCENE_ITEM_TYPE_CUTSCENE, .cutscene = &TEST_CUTSCENE_ONE },
};
static const cutscene_t TEST_CUTSCENE = {
.items = TEST_CUTSCENE_TWO_ITEMS,
.pause = CUTSCENE_PAUSE_NPC,
.itemCount = sizeof(TEST_CUTSCENE_TWO_ITEMS) / sizeof(cutsceneitem_t)
};
+1 -5
View File
@@ -10,7 +10,6 @@
#include "util/memory.h" #include "util/memory.h"
#include "time/time.h" #include "time/time.h"
#include "util/math.h" #include "util/math.h"
#include "rpg/cutscene/cutscenemode.h"
#include "rpg/overworld/map.h" #include "rpg/overworld/map.h"
#include "rpg/overworld/chunk.h" #include "rpg/overworld/chunk.h"
#include "rpg/overworld/tile.h" #include "rpg/overworld/tile.h"
@@ -43,10 +42,7 @@ void entityUpdate(entity_t *entity) {
entityAnimUpdate(entity); entityAnimUpdate(entity);
// Movement code. // Movement code.
if( if(ENTITY_CALLBACKS[entity->type].movement != NULL) {
cutsceneModeIsInputAllowed() &&
ENTITY_CALLBACKS[entity->type].movement != NULL
) {
ENTITY_CALLBACKS[entity->type].movement(entity); ENTITY_CALLBACKS[entity->type].movement(entity);
} }
} }
+1 -1
View File
@@ -49,7 +49,7 @@ errorret_t rpgInit(void) {
npcSetMoveType(npc, NPC_MOVE_TYPE_PATH); npcSetMoveType(npc, NPC_MOVE_TYPE_PATH);
npc->position = (worldpos_t){ 8, 8, 1 }; npc->position = (worldpos_t){ 8, 8, 1 };
npc->interact.type = ENTITY_INTERACT_CUTSCENE; npc->interact.type = ENTITY_INTERACT_CUTSCENE;
npc->interact.data.cutscene = &TEST_CUTSCENE; npc->interact.data.cutscene = CUTSCENE_REFERENCE(TEST_TWO);
{ {
chunkpos_t cp; chunkpos_t cp;
worldPosToChunkPos(&npc->position, &cp); worldPosToChunkPos(&npc->position, &cp);