JACoders / OpenJK

Community effort to maintain and improve Jedi Academy (SP & MP) + Jedi Outcast (SP only) released by Raven Software
GNU General Public License v2.0
1.98k stars 607 forks source link

Cutscenes failing to play correctly #1150

Closed lawadr closed 9 months ago

lawadr commented 1 year ago

I'm experiencing an issue in Jedi Academy on the cutscene where Luke is addressing the students after the first level. The game does not crash but nothing happens. No animation, no camera movement, no speech. You have to skip the cutscene to progress. This happens in both vanilla Jedi Academy and with the latest OpenJK.

I've found a number of reports of the same issue online: https://www.gog.com/forum/star_wars_jedi_knight_jedi_academy/first_jedi_temple_cutscene_stuck https://www.gog.com/forum/star_wars_jedi_knight_jedi_academy/game_freezing https://steamcommunity.com/app/6020/discussions/0/3276942370878082914/ https://steamcommunity.com/app/6020/discussions/0/3201493200082464233/ https://steamcommunity.com/app/6020/discussions/0/1696048426810765937/ https://www.reddit.com/r/jediknight/comments/ek9mkq/jedi_academy_yavin_iv_cutscene_glitch/

Debugging this issue was a pain because debug builds of OpenJK played the cutscene just fine, but I got there in the end. It turns out that the issue occurs when the level loads too fast.

The game server spawns entities behind the scenes while the loading bar is moving. When the loading bar reaches the end, the client connects to the server and the player is placed in the world. If this occurs before all the entities are loaded then any script that references any of the missing entities will fail to load fully, leaving the chain of sequencer tasks broken.

When the server starts (at the beginning of the loading screen), the server time is set to 1000 milliseconds: https://github.com/JACoders/OpenJK/blob/90e8005b0cef3ce3405ad3f0011a204ca78e4c37/code/server/sv_init.cpp#L288

It then runs frames at 1000, 1100, 1200 and 1300 milliseconds to "warm up" the sever: https://github.com/JACoders/OpenJK/blob/90e8005b0cef3ce3405ad3f0011a204ca78e4c37/code/server/sv_init.cpp#L313

Meanwhile, the entity spawner's nextthink time is set to 1350 and its e_ThinkFunc is set to thinkF_NPC_Spawn_Go: https://github.com/JACoders/OpenJK/blob/90e8005b0cef3ce3405ad3f0011a204ca78e4c37/code/game/NPC_spawn.cpp#L2048-L2049

The first non-warmup frame occurs at 1400+(1/sv_fps) milliseconds, which with the default settings is at 1450. This triggers the think function, which finally bumps the nextthink time along by 100 milliseconds to 1550 and sets e_ThinkFunc to thinkF_NPC_Begin: https://github.com/JACoders/OpenJK/blob/90e8005b0cef3ce3405ad3f0011a204ca78e4c37/code/game/NPC_spawn.cpp#L1758-L1759

If this next time is reached before the client connects to the server (the loading bar reaches the end) then everything runs smoothly. The NPC_Begin function has been run on each entity and so they can all be looked up correctly by name, specifically here: https://github.com/JACoders/OpenJK/blob/90e8005b0cef3ce3405ad3f0011a204ca78e4c37/code/icarus/Sequencer.cpp#L692-L693

On my laptop, and in a release build, the client connects to the server at 1400 milliseconds. With RelWithDebugInfo I get around 1550 to 1600 on the first load of the cutscene, meaning it works, and then 1450 to 1500 on reloads (probably because some assets are still in memory?), meaning it fails.

I'm unsure what the best way to fix this bug is. The easiest way would probably be to increase the number of warm up frames or hardcode a delay to the client connection until after 1550 milliseconds. Alternatively, the Icarus code could be changed to postpone the lookup of entities until the task is processed, but I wouldn't know where to start with that.

Graham1225 commented 1 year ago

I am having the same issue with Jedi Outcast (via OpenJO) on a 2020 M1 Macbook Air with loading cutscenes at the start of new levels—which, in my case, are the start of Artus Mine and the cutscene following the first fight with Desaan. I am completely ignorant of coding, so I can't comment on your work, but you seem to experiencing the same problem: models load in and music starts, but the in-engine cutscene does not continue and thus soft-locking the game. The only command actions I can apparently do is open the console or quick-load. Has anyone figured out a workaround?

lawadr commented 1 year ago

I am having the same issue with Jedi Outcast (via OpenJO) on a 2020 M1 Macbook Air with loading cutscenes at the start of new levels—which, in my case, are the start of Artus Mine and the cutscene following the first fight with Desaan. I am completely ignorant of coding, so I can't comment on your work, but you seem to experiencing the same problem: models load in and music starts, but the in-engine cutscene does not continue and thus soft-locking the game. The only command actions I can apparently do is open the console or quick-load. Has anyone figured out a workaround?

I've just submitted a PR to fix this issue. With it, I finished Jedi Academy twice with no cutscene problems whatsoever. If you can build it, give it a shot and see if it fixes your issue.