ending.lua 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. -- Ember bookends are pre-rendered movies. Keep Apex loaded while the native movie
  2. -- player owns presentation; never tear down the gameplay world to create type-6 actors.
  3. return function(m)
  4. local E = {}
  5. local music = require("mission_ember.music")(m)
  6. local function play(c, index)
  7. c:set_variable("ember.ending", index)
  8. c:clear_variable("ember.ending.playing")
  9. c:clear_variable("ember.ending.stopping")
  10. c:play_prerendered_movie{index = index}
  11. c:set_variable("ember.ending.polls", 0)
  12. c:start_timer("ember.ending.poll", 250)
  13. end
  14. function E.start(c, s)
  15. if s:variable("ember.ending") then return end
  16. music.update(c, s)
  17. play(c, 1)
  18. end
  19. function E.client(c, s, e)
  20. local index = s:variable("ember.ending")
  21. if not index or index > 2 then return end
  22. local status = c:prerendered_movie_status(index)
  23. if status == "playing" then
  24. if s:variable("ember.ending.playing") ~= index then c:set_variable("ember.ending.playing", index) end
  25. elseif status == "complete" then
  26. -- The native bridge requires real playback before it can report completion,
  27. -- including when a short/skip transition happens between script callbacks.
  28. if index == 1 then play(c, 2)
  29. else
  30. c:cancel_timer("ember.ending.poll")
  31. c:set_variable("ember.ending", 3)
  32. c:set_variable("ember.complete", true)
  33. -- The movie bridge observes this native lifetime receipt after both movies,
  34. -- allows the completion banner, then commits a guarded return to orbit.
  35. c.lifetime:set{state = c.sdk.lifetime_states:at(6)}
  36. c:set_phase(100)
  37. end
  38. elseif status == "failed" then
  39. c:set_variable("ember.ending.failed", true)
  40. end
  41. end
  42. function E.timer(c, s, e)
  43. if e.timer_name ~= "ember.ending.poll" then return true end
  44. E.client(c, s, e)
  45. local index = s:variable("ember.ending")
  46. if index and index <= 2 and not s:variable("ember.ending.failed") then
  47. local polls = (s:variable("ember.ending.polls") or 0) + 1
  48. c:set_variable("ember.ending.polls", polls)
  49. -- Also bound a refused delivery that never reached the native bridge.
  50. if polls >= 2600 then c:set_variable("ember.ending.failed", true)
  51. else c:start_timer("ember.ending.poll", 250) end
  52. end
  53. return true
  54. end
  55. -- Direct movies have no type-6 source: the native bridge handles local Escape,
  56. -- invokes the native stop routine, and waits for the decoder to stop.
  57. function E.skip(c, s, e) end
  58. -- A type-6 incident cannot complete a pre-rendered movie request.
  59. function E.started(c, s, e) end
  60. function E.terminated(c, s, e) end
  61. return E
  62. end