ending.lua 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. c.lifetime:set{state = c.sdk.lifetime_states:at(6)}
  34. c:set_phase(100)
  35. end
  36. elseif status == "failed" then
  37. c:set_variable("ember.ending.failed", true)
  38. end
  39. end
  40. function E.timer(c, s, e)
  41. if e.timer_name ~= "ember.ending.poll" then return true end
  42. E.client(c, s, e)
  43. local index = s:variable("ember.ending")
  44. if index and index <= 2 and not s:variable("ember.ending.failed") then
  45. local polls = (s:variable("ember.ending.polls") or 0) + 1
  46. c:set_variable("ember.ending.polls", polls)
  47. -- Also bound a refused delivery that never reached the native bridge.
  48. if polls >= 2600 then c:set_variable("ember.ending.failed", true)
  49. else c:start_timer("ember.ending.poll", 250) end
  50. end
  51. return true
  52. end
  53. -- Direct movies have no type-6 source: the native bridge handles local Escape,
  54. -- invokes the native stop routine, and waits for the decoder to stop.
  55. function E.skip(c, s, e) end
  56. -- A type-6 incident cannot complete a pre-rendered movie request.
  57. function E.started(c, s, e) end
  58. function E.terminated(c, s, e) end
  59. return E
  60. end