Add user data to callbacks
This commit is contained in:
@@ -13,14 +13,19 @@ typedef struct cutscene_s {
|
|||||||
const cutsceneitem_t *items;
|
const cutsceneitem_t *items;
|
||||||
uint8_t itemCount;
|
uint8_t itemCount;
|
||||||
cutscenepause_t pause;
|
cutscenepause_t pause;
|
||||||
|
|
||||||
|
// Size in bytes of this cutscene's custom user data, carved out of
|
||||||
|
// CUTSCENE_SYSTEM.data while the cutscene is running.
|
||||||
|
size_t dataSize;
|
||||||
} cutscene_t;
|
} cutscene_t;
|
||||||
|
|
||||||
#define CUTSCENE(NAME, PAUSE_TYPE, ...) \
|
#define CUTSCENE(NAME, SIZE, PAUSE_TYPE, ...) \
|
||||||
static const cutsceneitem_t CUTSCENE_##NAME##_ITEMS[] = { __VA_ARGS__ }; \
|
static const cutsceneitem_t CUTSCENE_##NAME##_ITEMS[] = { __VA_ARGS__ }; \
|
||||||
static const cutscene_t CUTSCENE_##NAME = { \
|
static const cutscene_t CUTSCENE_##NAME = { \
|
||||||
.items = CUTSCENE_##NAME##_ITEMS, \
|
.items = CUTSCENE_##NAME##_ITEMS, \
|
||||||
.itemCount = sizeof(CUTSCENE_##NAME##_ITEMS) / sizeof(cutsceneitem_t), \
|
.itemCount = sizeof(CUTSCENE_##NAME##_ITEMS) / sizeof(cutsceneitem_t), \
|
||||||
.pause = CUTSCENE_PAUSE_##PAUSE_TYPE \
|
.pause = CUTSCENE_PAUSE_##PAUSE_TYPE, \
|
||||||
|
.dataSize = SIZE \
|
||||||
};
|
};
|
||||||
|
|
||||||
#define CUTSCENE_REFERENCE(CUTSCENE) \
|
#define CUTSCENE_REFERENCE(CUTSCENE) \
|
||||||
|
|||||||
@@ -25,6 +25,11 @@ void cutsceneSystemStartCutsceneWith(
|
|||||||
entity_t *interact,
|
entity_t *interact,
|
||||||
entity_t *interacted
|
entity_t *interacted
|
||||||
) {
|
) {
|
||||||
|
assertTrue(
|
||||||
|
cutscene->dataSize < CUTSCENE_SYSTEM_SIZE_MAX,
|
||||||
|
"Cutscene data size exceeds CUTSCENE_SYSTEM_SIZE_MAX"
|
||||||
|
);
|
||||||
|
|
||||||
CUTSCENE_SYSTEM.scene = cutscene;
|
CUTSCENE_SYSTEM.scene = cutscene;
|
||||||
CUTSCENE_SYSTEM.pause = cutscene->pause;
|
CUTSCENE_SYSTEM.pause = cutscene->pause;
|
||||||
CUTSCENE_SYSTEM.entityInteract = interact;
|
CUTSCENE_SYSTEM.entityInteract = interact;
|
||||||
|
|||||||
@@ -15,6 +15,10 @@ typedef struct entity_s entity_t;
|
|||||||
#define CUTSCENE_ENTITY_LAST_CREATED ((uint8_t)0xFC)
|
#define CUTSCENE_ENTITY_LAST_CREATED ((uint8_t)0xFC)
|
||||||
#define CUTSCENE_ENTITY_LAST_REF ((uint8_t)0xFB)
|
#define CUTSCENE_ENTITY_LAST_REF ((uint8_t)0xFB)
|
||||||
|
|
||||||
|
// Maximum number of bytes a running cutscene may request via
|
||||||
|
// cutscene_t.dataSize.
|
||||||
|
#define CUTSCENE_SYSTEM_SIZE_MAX 8192
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
const cutscene_t *scene;
|
const cutscene_t *scene;
|
||||||
uint8_t currentItem;
|
uint8_t currentItem;
|
||||||
@@ -26,6 +30,10 @@ typedef struct {
|
|||||||
|
|
||||||
// Data (used by the current item).
|
// Data (used by the current item).
|
||||||
cutsceneitemdata_t data;
|
cutsceneitemdata_t data;
|
||||||
|
|
||||||
|
// Custom user data for the running cutscene, sized per-scene by
|
||||||
|
// cutscene_t.dataSize.
|
||||||
|
uint8_t userData[CUTSCENE_SYSTEM_SIZE_MAX];
|
||||||
} cutscenesystem_t;
|
} cutscenesystem_t;
|
||||||
|
|
||||||
extern cutscenesystem_t CUTSCENE_SYSTEM;
|
extern cutscenesystem_t CUTSCENE_SYSTEM;
|
||||||
|
|||||||
@@ -6,12 +6,13 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "cutsceneitem.h"
|
#include "cutsceneitem.h"
|
||||||
|
#include "rpg/cutscene/cutscenesystem.h"
|
||||||
|
|
||||||
void cutsceneCallbackStart(
|
void cutsceneCallbackStart(
|
||||||
const cutsceneitem_t *item,
|
const cutsceneitem_t *item,
|
||||||
cutsceneitemdata_t *data
|
cutsceneitemdata_t *data
|
||||||
) {
|
) {
|
||||||
if(item->callback != NULL) item->callback();
|
if(item->callback != NULL) item->callback(CUTSCENE_SYSTEM.userData);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool_t cutsceneCallbackUpdate(
|
bool_t cutsceneCallbackUpdate(
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
typedef struct cutsceneitem_s cutsceneitem_t;
|
typedef struct cutsceneitem_s cutsceneitem_t;
|
||||||
typedef union cutsceneitemdata_u cutsceneitemdata_t;
|
typedef union cutsceneitemdata_u cutsceneitemdata_t;
|
||||||
|
|
||||||
typedef void (*cutscenecallback_t)(void);
|
typedef void (*cutscenecallback_t)(void *userData);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts a callback item (invokes the callback immediately).
|
* Starts a callback item (invokes the callback immediately).
|
||||||
|
|||||||
@@ -9,11 +9,11 @@
|
|||||||
#include "rpg/cutscene/cutscene.h"
|
#include "rpg/cutscene/cutscene.h"
|
||||||
#include "rpg/cutscene/cutscenesystem.h"
|
#include "rpg/cutscene/cutscenesystem.h"
|
||||||
|
|
||||||
CUTSCENE(TEST_ONE, DEFAULT,
|
CUTSCENE(TEST_ONE, 0, DEFAULT,
|
||||||
CUTSCENE_TEXT("Test One."),
|
CUTSCENE_TEXT("Test One."),
|
||||||
);
|
);
|
||||||
|
|
||||||
CUTSCENE(TEST_TWO, DEFAULT,
|
CUTSCENE(TEST_TWO, 0, DEFAULT,
|
||||||
CUTSCENE_TEXT("Test Two."),
|
CUTSCENE_TEXT("Test Two."),
|
||||||
CUTSCENE_ENTITY_ADD(ENTITY_TYPE_NPC, 4, 4, 0),
|
CUTSCENE_ENTITY_ADD(ENTITY_TYPE_NPC, 4, 4, 0),
|
||||||
CUTSCENE_ENTITY_WALK_TO(CUTSCENE_ENTITY_LAST_CREATED, 8, 2, 0),
|
CUTSCENE_ENTITY_WALK_TO(CUTSCENE_ENTITY_LAST_CREATED, 8, 2, 0),
|
||||||
|
|||||||
Reference in New Issue
Block a user