158 lines
4.8 KiB
C
158 lines
4.8 KiB
C
/**
|
|
* 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 "assert/assert.h"
|
|
|
|
cutscenesystem_t CUTSCENE_SYSTEM;
|
|
|
|
void cutsceneSystemInit() {
|
|
memoryZero(&CUTSCENE_SYSTEM, sizeof(cutscenesystem_t));
|
|
}
|
|
|
|
void cutsceneSystemStartCutscene(const cutscene_t *cutscene) {
|
|
cutsceneSystemStartCutsceneWith(cutscene, NULL, NULL);
|
|
}
|
|
|
|
void cutsceneSystemStartCutsceneWith(
|
|
const cutscene_t *cutscene,
|
|
entity_t *interact,
|
|
entity_t *interacted
|
|
) {
|
|
assertTrue(
|
|
cutscene->dataSize < CUTSCENE_SYSTEM_SIZE_MAX,
|
|
"Cutscene data size exceeds CUTSCENE_SYSTEM_SIZE_MAX"
|
|
);
|
|
|
|
CUTSCENE_SYSTEM.scene = cutscene;
|
|
CUTSCENE_SYSTEM.pause = cutscene->pause;
|
|
CUTSCENE_SYSTEM.entityInteract = interact;
|
|
CUTSCENE_SYSTEM.entityInteracted = interacted;
|
|
CUTSCENE_SYSTEM.entityLastCreated = NULL;
|
|
CUTSCENE_SYSTEM.entityLastRef = NULL;
|
|
CUTSCENE_SYSTEM.areaLastCreated = CUTSCENE_AREA_LAST_CREATED;
|
|
CUTSCENE_SYSTEM.textMiniLastCreated = CUTSCENE_TEXT_MINI_LAST_CREATED;
|
|
CUTSCENE_SYSTEM.currentItem = 0xFF;// Set to 0xFF so Next wraps to 0.
|
|
cutsceneSystemNext();
|
|
}
|
|
|
|
void cutsceneSystemUpdate() {
|
|
if(CUTSCENE_SYSTEM.scene == NULL) return;
|
|
|
|
const cutsceneitem_t *item = cutsceneSystemGetCurrentItem();
|
|
if(cutsceneItemUpdate(item, &CUTSCENE_SYSTEM.data)) cutsceneSystemNext();
|
|
}
|
|
|
|
void cutsceneSystemNext() {
|
|
if(CUTSCENE_SYSTEM.scene == NULL) return;
|
|
|
|
CUTSCENE_SYSTEM.currentItem++;
|
|
|
|
// End of the cutscene?
|
|
if(
|
|
CUTSCENE_SYSTEM.currentItem >= CUTSCENE_SYSTEM.scene->itemCount
|
|
) {
|
|
CUTSCENE_SYSTEM.scene = NULL;
|
|
CUTSCENE_SYSTEM.currentItem = 0xFF;
|
|
CUTSCENE_SYSTEM.pause = CUTSCENE_PAUSE_NONE;
|
|
CUTSCENE_SYSTEM.entityInteract = NULL;
|
|
CUTSCENE_SYSTEM.entityInteracted = NULL;
|
|
CUTSCENE_SYSTEM.entityLastCreated = NULL;
|
|
CUTSCENE_SYSTEM.entityLastRef = NULL;
|
|
CUTSCENE_SYSTEM.areaLastCreated = CUTSCENE_AREA_LAST_CREATED;
|
|
CUTSCENE_SYSTEM.textMiniLastCreated = CUTSCENE_TEXT_MINI_LAST_CREATED;
|
|
return;
|
|
}
|
|
|
|
// Start item.
|
|
const cutsceneitem_t *item = cutsceneSystemGetCurrentItem();
|
|
memset(&CUTSCENE_SYSTEM.data, 0, sizeof(CUTSCENE_SYSTEM.data));
|
|
cutsceneItemStart(item, &CUTSCENE_SYSTEM.data);
|
|
}
|
|
|
|
const cutsceneitem_t * cutsceneSystemGetCurrentItem() {
|
|
if(CUTSCENE_SYSTEM.scene == NULL) return NULL;
|
|
|
|
return &CUTSCENE_SYSTEM.scene->items[CUTSCENE_SYSTEM.currentItem];
|
|
}
|
|
|
|
entity_t * cutsceneSystemGetEntity(const uint8_t entityIndex) {
|
|
entity_t *entity;
|
|
|
|
if(entityIndex == CUTSCENE_ENTITY_INTERACT) {
|
|
assertNotNull(
|
|
CUTSCENE_SYSTEM.entityInteract,
|
|
"CUTSCENE_ENTITY_INTERACT used but no interact entity is set"
|
|
);
|
|
entity = CUTSCENE_SYSTEM.entityInteract;
|
|
} else if(entityIndex == CUTSCENE_ENTITY_INTERACTED) {
|
|
assertNotNull(
|
|
CUTSCENE_SYSTEM.entityInteracted,
|
|
"CUTSCENE_ENTITY_INTERACTED used but no interacted entity is set"
|
|
);
|
|
entity = CUTSCENE_SYSTEM.entityInteracted;
|
|
} else if(entityIndex == CUTSCENE_ENTITY_LAST_CREATED) {
|
|
assertNotNull(
|
|
CUTSCENE_SYSTEM.entityLastCreated,
|
|
"CUTSCENE_ENTITY_LAST_CREATED used but no entity has been created"
|
|
);
|
|
entity = CUTSCENE_SYSTEM.entityLastCreated;
|
|
} else if(entityIndex == CUTSCENE_ENTITY_LAST_REF) {
|
|
assertNotNull(
|
|
CUTSCENE_SYSTEM.entityLastRef,
|
|
"CUTSCENE_ENTITY_LAST_REF used but no entity has been referenced"
|
|
);
|
|
entity = CUTSCENE_SYSTEM.entityLastRef;
|
|
} else {
|
|
assertTrue(
|
|
entityIndex < ENTITY_COUNT,
|
|
"Entity index is out of range"
|
|
);
|
|
entity = &ENTITIES[entityIndex];
|
|
}
|
|
|
|
CUTSCENE_SYSTEM.entityLastRef = entity;
|
|
return entity;
|
|
}
|
|
|
|
uint8_t cutsceneSystemGetAreaId(const uint8_t areaId) {
|
|
if(areaId == CUTSCENE_AREA_LAST_CREATED) {
|
|
assertTrue(
|
|
CUTSCENE_SYSTEM.areaLastCreated != CUTSCENE_AREA_LAST_CREATED,
|
|
"CUTSCENE_AREA_LAST_CREATED used but no map area has been created"
|
|
);
|
|
return CUTSCENE_SYSTEM.areaLastCreated;
|
|
}
|
|
return areaId;
|
|
}
|
|
|
|
uint8_t cutsceneSystemGetTextMiniId(const uint8_t index) {
|
|
if(index == CUTSCENE_TEXT_MINI_LAST_CREATED) {
|
|
assertTrue(
|
|
CUTSCENE_SYSTEM.textMiniLastCreated != CUTSCENE_TEXT_MINI_LAST_CREATED,
|
|
"CUTSCENE_TEXT_MINI_LAST_CREATED used but no mini textbox has been "
|
|
"shown"
|
|
);
|
|
return CUTSCENE_SYSTEM.textMiniLastCreated;
|
|
}
|
|
return index;
|
|
}
|
|
|
|
void cutsceneSystemDispose() {
|
|
CUTSCENE_SYSTEM.scene = NULL;
|
|
CUTSCENE_SYSTEM.currentItem = 0xFF;
|
|
CUTSCENE_SYSTEM.pause = CUTSCENE_PAUSE_NONE;
|
|
CUTSCENE_SYSTEM.entityInteract = NULL;
|
|
CUTSCENE_SYSTEM.entityInteracted = NULL;
|
|
CUTSCENE_SYSTEM.entityLastCreated = NULL;
|
|
CUTSCENE_SYSTEM.entityLastRef = NULL;
|
|
CUTSCENE_SYSTEM.areaLastCreated = CUTSCENE_AREA_LAST_CREATED;
|
|
CUTSCENE_SYSTEM.textMiniLastCreated = CUTSCENE_TEXT_MINI_LAST_CREATED;
|
|
}
|