Camera API, improved cutscene API
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user