Camera API, improved cutscene API

This commit is contained in:
Jan Racek
2026-03-28 20:13:12 +01:00
parent 68cf8a7460
commit 561ee9dd64
6 changed files with 160 additions and 29 deletions

View File

@@ -10,18 +10,21 @@ namespace psxsplash {
void CutscenePlayer::init(Cutscene* cutscenes, int count, Camera* camera, AudioManager* audio,
UISystem* uiSystem) {
m_cutscenes = cutscenes;
m_count = count;
m_active = nullptr;
m_frame = 0;
m_nextAudio = 0;
m_camera = camera;
m_audio = audio;
m_uiSystem = uiSystem;
m_cutscenes = cutscenes;
m_count = count;
m_active = nullptr;
m_frame = 0;
m_nextAudio = 0;
m_loop = false;
m_camera = camera;
m_audio = audio;
m_uiSystem = uiSystem;
m_onCompleteRef = LUA_NOREF;
}
bool CutscenePlayer::play(const char* name) {
bool CutscenePlayer::play(const char* name, bool loop) {
if (!name || !m_cutscenes) return false;
m_loop = loop;
for (int i = 0; i < m_count; i++) {
if (m_cutscenes[i].name && streq(m_cutscenes[i].name, name)) {
@@ -106,7 +109,9 @@ bool CutscenePlayer::play(const char* name) {
}
void CutscenePlayer::stop() {
if (!m_active) return;
m_active = nullptr;
fireOnComplete();
}
void CutscenePlayer::tick() {
@@ -130,10 +135,34 @@ void CutscenePlayer::tick() {
m_frame++;
if (m_frame > m_active->totalFrames) {
m_active = nullptr; // Cutscene finished
if (m_loop) {
// Restart from the beginning
m_frame = 0;
m_nextAudio = 0;
} else {
m_active = nullptr; // Cutscene finished
fireOnComplete();
}
}
}
void CutscenePlayer::fireOnComplete() {
if (m_onCompleteRef == LUA_NOREF || !m_luaState) return;
psyqo::Lua L(m_luaState);
L.rawGetI(LUA_REGISTRYINDEX, m_onCompleteRef);
if (L.isFunction(-1)) {
if (L.pcall(0, 0) != LUA_OK) {
printf("Cutscene onComplete error: %s\n", L.optString(-1, "unknown"));
L.pop();
}
} else {
L.pop();
}
// Unreference the callback (one-shot)
luaL_unref(m_luaState, LUA_REGISTRYINDEX, m_onCompleteRef);
m_onCompleteRef = LUA_NOREF;
}
static int32_t applyCurve(int32_t t, InterpMode mode) {
switch (mode) {
default: