Cutscene defs
This commit is contained in:
@@ -7,7 +7,6 @@
|
||||
target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
||||
PUBLIC
|
||||
cutscenesystem.c
|
||||
cutscenemode.c
|
||||
)
|
||||
|
||||
# Subdirs
|
||||
|
||||
@@ -7,10 +7,30 @@
|
||||
|
||||
#pragma once
|
||||
#include "rpg/cutscene/item/cutsceneitem.h"
|
||||
#include "cutscenepause.h"
|
||||
#include "rpg/cutscene/cutscenepause.h"
|
||||
|
||||
typedef struct cutscene_s {
|
||||
const cutsceneitem_t *items;
|
||||
uint8_t itemCount;
|
||||
cutscenepause_t pause;
|
||||
} 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) }
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
@@ -16,7 +16,6 @@ void cutsceneSystemInit() {
|
||||
|
||||
void cutsceneSystemStartCutscene(const cutscene_t *cutscene) {
|
||||
CUTSCENE_SYSTEM.scene = cutscene;
|
||||
CUTSCENE_SYSTEM.mode = CUTSCENE_MODE_INITIAL;
|
||||
CUTSCENE_SYSTEM.currentItem = 0xFF;// Set to 0xFF so start wraps.
|
||||
cutsceneSystemNext();
|
||||
}
|
||||
@@ -39,7 +38,6 @@ void cutsceneSystemNext() {
|
||||
) {
|
||||
CUTSCENE_SYSTEM.scene = NULL;
|
||||
CUTSCENE_SYSTEM.currentItem = 0xFF;
|
||||
CUTSCENE_SYSTEM.mode = CUTSCENE_MODE_NONE;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -58,5 +56,4 @@ const cutsceneitem_t * cutsceneSystemGetCurrentItem() {
|
||||
void cutsceneSystemDispose() {
|
||||
CUTSCENE_SYSTEM.scene = NULL;
|
||||
CUTSCENE_SYSTEM.currentItem = 0xFF;
|
||||
CUTSCENE_SYSTEM.mode = CUTSCENE_MODE_NONE;
|
||||
}
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
#pragma once
|
||||
#include "cutscene.h"
|
||||
#include "cutscenemode.h"
|
||||
|
||||
typedef struct {
|
||||
const cutscene_t *scene;
|
||||
@@ -15,7 +14,6 @@ typedef struct {
|
||||
|
||||
// Data (used by the current item).
|
||||
cutsceneitemdata_t data;
|
||||
cutscenemode_t mode;
|
||||
} cutscenesystem_t;
|
||||
|
||||
extern cutscenesystem_t CUTSCENE_SYSTEM;
|
||||
|
||||
@@ -6,26 +6,15 @@
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "rpg/cutscene/cutscenesystem.h"
|
||||
#include "rpg/cutscene/cutscene.h"
|
||||
|
||||
static const cutsceneitem_t TEST_CUTSCENE_ONE_ITEMS[] = {
|
||||
{ .type = CUTSCENE_ITEM_TYPE_TEXT, .text = { .text = "This is a test cutscene." } },
|
||||
{ .type = CUTSCENE_ITEM_TYPE_WAIT, .wait = 0.5f },
|
||||
{ .type = CUTSCENE_ITEM_TYPE_TEXT, .text = { .text = "It has multiple lines of text.\nAnd waits in between." } },
|
||||
};
|
||||
CUTSCENE(TEST_ONE, DEFAULT,
|
||||
CUTSCENE_TEXT("This is a test cutscene."),
|
||||
CUTSCENE_WAIT(0.5f),
|
||||
CUTSCENE_TEXT("It has multiple lines of text.\nAnd waits in between.")
|
||||
);
|
||||
|
||||
static const cutscene_t TEST_CUTSCENE_ONE = {
|
||||
.items = TEST_CUTSCENE_ONE_ITEMS,
|
||||
.itemCount = sizeof(TEST_CUTSCENE_ONE_ITEMS) / sizeof(cutsceneitem_t)
|
||||
};
|
||||
|
||||
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)
|
||||
};
|
||||
CUTSCENE(TEST_TWO, DEFAULT,
|
||||
CUTSCENE_WAIT(0.1f),
|
||||
CUTSCENE_CUTSCENE(TEST_ONE),
|
||||
);
|
||||
@@ -10,7 +10,6 @@
|
||||
#include "util/memory.h"
|
||||
#include "time/time.h"
|
||||
#include "util/math.h"
|
||||
#include "rpg/cutscene/cutscenemode.h"
|
||||
#include "rpg/overworld/map.h"
|
||||
#include "rpg/overworld/chunk.h"
|
||||
#include "rpg/overworld/tile.h"
|
||||
@@ -43,10 +42,7 @@ void entityUpdate(entity_t *entity) {
|
||||
entityAnimUpdate(entity);
|
||||
|
||||
// Movement code.
|
||||
if(
|
||||
cutsceneModeIsInputAllowed() &&
|
||||
ENTITY_CALLBACKS[entity->type].movement != NULL
|
||||
) {
|
||||
if(ENTITY_CALLBACKS[entity->type].movement != NULL) {
|
||||
ENTITY_CALLBACKS[entity->type].movement(entity);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -49,7 +49,7 @@ errorret_t rpgInit(void) {
|
||||
npcSetMoveType(npc, NPC_MOVE_TYPE_PATH);
|
||||
npc->position = (worldpos_t){ 8, 8, 1 };
|
||||
npc->interact.type = ENTITY_INTERACT_CUTSCENE;
|
||||
npc->interact.data.cutscene = &TEST_CUTSCENE;
|
||||
npc->interact.data.cutscene = CUTSCENE_REFERENCE(TEST_TWO);
|
||||
{
|
||||
chunkpos_t cp;
|
||||
worldPosToChunkPos(&npc->position, &cp);
|
||||
|
||||
Reference in New Issue
Block a user