Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support demo levels (try 2) #1378

Merged
merged 2 commits into from
May 31, 2024

Conversation

carlo-bramini
Copy link
Contributor

Checklist

  • I have read the coding conventions
  • I have added a changelog entry about what my pull request accomplishes, or it is an internal change

Description

This patch adds support for playing the demo levels of City of Vilcabamba.
It supersedes the patch at #722 and additional description can be found there and at #667.
It has been splitted in two commits:

  • the first commit improves the code for handling the assignment of level_type and it has been applied also for SEQ type. It does not change the behaviour but it allows to remove much similar copy-paste code, which is useful for implementing the second commit.
  • the second commit adds support for the demo level. I played it and I have not found particular problems in the game.

@carlo-bramini carlo-bramini force-pushed the add-support-demo-levels-2 branch 2 times, most recently from 66f7919 to 2a7ecb3 Compare May 26, 2024 12:25
@Richard-L
Copy link
Collaborator

Been hoping for this for a long time 🙏

Since there are several demos, I wonder which (or all?) are supported?

Many thanks for doing this.

@rr- rr- requested review from a team, rr-, eikehein and lahm86 and removed request for a team May 27, 2024 06:51
@rr-
Copy link
Collaborator

rr- commented May 27, 2024

Hey @carlo-bramini, I appreciate your efforts in refreshing the initial pull request. The proposed refactoring looks great, however, there are a few code style deviations we'd need to clear before giving it a go. I understand you've had challenges with the build process, so I don't want to burden you with these. Would you be okay with us making some stylistic adjustments directly in the PR, or, if it turns out we lack the access to push to your fork, creating a sibling PR with the changes?

@Richard-L @lahm86 @walkawayy to make this feature less esoteric, I think we could create a checkbox in the installer to download also the demo files from our server to make the demos accessible to a wider audience. But if there is more than a single demo floating around, this becomes problematic – kind of like with what version of UB to bundle. What are your thoughts on this subject?

@Richard-L
Copy link
Collaborator

Richard-L commented May 27, 2024

@rr- thanks for bringing this up. My hope is still that immediate and no-purchase no-nothing accessibility to playing the game (and that isn't confusing UB), will help attract a few more players' interest.

I'm in Paris atm without my main PC, but of the top of my head, for PC, there are these demos:

  • Vilcabamba Part 1
  • Vilcabamba Part 2
  • "Terracide" bundle, where a TR demo or Caves and the full Vilcabamba were included (this is the one I'd probably offer)

@lahm86
Copy link
Collaborator

lahm86 commented May 27, 2024

I think if it's a single download then adding it to the installer is a good call. If it becomes more complicated with various alternative downloads, then I'd be inclined to keep the support just for one type.

Would a "launch demo" button also be needed in the config tool, similar to "launch UB", or would that be going too far?

And - this is just another thought - if we were to provide the demo files, could we not just edit them to move the palette into the expected position, therefore reducing the amount of code changes needed in the first place? I appreciate that would affect the playability of independent demo downloads, but thought it would be worth mentioning. It would also mean we could open the files in trview and suchlike.

@rr-
Copy link
Collaborator

rr- commented May 27, 2024

Good call on editing the files especially since there is finite amount of them IMO.
Adding the button to launch the demo might be too much, same with creating a desktop shortcut.

@carlo-bramini
Copy link
Contributor Author

Hey @carlo-bramini, I appreciate your efforts in refreshing the initial pull request. The proposed refactoring looks great, however, there are a few code style deviations we'd need to clear before giving it a go. I understand you've had challenges with the build process, so I don't want to burden you with these. Would you be okay with us making some stylistic adjustments directly in the PR, or, if it turns out we lack the access to push to your fork, creating a sibling PR with the changes?

Ok, no problem!
You can just let me know which code style deviations need to be adjusted and I will squash them into the proper commit.

@@ -51,6 +58,60 @@ static bool GameFlow_LoadLevelSequence(
static bool GameFlow_LoadScriptLevels(struct json_object_s *obj);
static bool GameFlow_LoadFromFileImpl(const char *file_name);

static const STRING_TO_ENUM_TYPE map_GAMEFLOW_LEVEL_TYPE[] = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be named m_GameflowLevelTypeEnumMap or alike.

{ NULL, -1 },
};

static const STRING_TO_ENUM_TYPE map_GAMEFLOW_SEQ_TYPE[] = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be named m_GameflowSeqTypeEnumMap or alike.

};

static int32_t GameFlow_StringToEnumType(
const char *str, const STRING_TO_ENUM_TYPE *map)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can map the pointers as not changing by using const char *const str (I know we're inconsistent about const in our codebase, but it's a noble thing to try and adhere to it.)

@@ -219,6 +280,10 @@ static bool GameFlow_LoadLevelSequence(
GAMEFLOW_SEQUENCE *seq = g_GameFlow.levels[level_num].sequence;
int32_t i = 0;
while (jseq_elem) {
const char *tmp_s;
GAMEFLOW_DISPLAY_PICTURE_DATA *data;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep this particular variable inside the case expression. The compiler will error out, but we can suppress the error by adding curly braces around the case like so:

case foo: {
    int32_t local_var = 0;
    break;
}

static void Level_CompleteSetup(int32_t level_num);

static bool Level_LoadFromFile(const char *filename, int32_t level_num)
static bool Level_LoadFromFile(
const char *filename, int32_t level_num, bool is_demo)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is any way whatsoever to tell the file structure from the file contents rather than external gameflow metadata, I'd appreciate removing this parameter altogether.
If not, I recommend turning it into an enum LEVEL_FORMAT. In the future, it would be beneficial to support Saturn files, possibly PS1 files (I'm unsure about these platforms' data layouts though). But even beyond that, having this enum will help to distinguish between .PHD and .TR2 when we fuse relevant parts of the TR1X and TR2X codebase.

Level_LoadFromFile(g_GameFlow.levels[level_num].level_file, level_num);
bool is_demo =
(g_GameFlow.levels[level_num].level_type == GFL_TITLE_DEMO_PC)
| (g_GameFlow.levels[level_num].level_type == GFL_LEVEL_DEMO_PC);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than a binary op we can use ||. Also, we can mark the variables as const.

@@ -958,6 +958,8 @@ typedef enum GAMEFLOW_LEVEL_TYPE {
GFL_RESTART = 7,
GFL_SELECT = 8,
GFL_BONUS = 9,
GFL_TITLE_DEMO_PC = 10,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if there are more places that check for GFL_TITLE. In that case rather than sprinkling the codebase with additional || level_type == GFL_TITLE_DEMO_PC across, I'd lean towards resetting the level type in the gameflow loader back to GFL_TITLE for the given level. Same for regular levels.

@rr-
Copy link
Collaborator

rr- commented May 27, 2024

Oops I meant to comment rather than approving.

@carlo-bramini carlo-bramini force-pushed the add-support-demo-levels-2 branch 2 times, most recently from fe22246 to e57caf7 Compare May 28, 2024 13:55
@carlo-bramini carlo-bramini force-pushed the add-support-demo-levels-2 branch from e57caf7 to 0f1928a Compare May 28, 2024 14:06
@walkawayy walkawayy linked an issue May 28, 2024 that may be closed by this pull request
@walkawayy
Copy link
Collaborator

walkawayy commented May 28, 2024

I'm not sure if I did something wrong but my game crashes like this:

image

I put the demo config in my cfg folder, made a shortcut with -gold, and put in the title and level2 .phd's in my data folder. I used the demo level linked in the issue here: https://www.allgamestaff.it/download-tomb-raider/tr-1/

@rr-
Copy link
Collaborator

rr- commented May 29, 2024

The gameflow refers to the demo files with data_demo_pc/level2.phd and that's where the files should be put. Otherwise it'll try to load regular Vilcabamba as a demo level and chaos will ensue.

@carlo-bramini
Copy link
Contributor Author

I'm not sure if I did something wrong but my game crashes like this:

image

I put the demo config in my cfg folder, made a shortcut with -gold, and put in the title and level2 .phd's in my data folder. I used the demo level linked in the issue here: https://www.allgamestaff.it/download-tomb-raider/tr-1/

For running demo files, you must provide -demo_pc instead of -gold.
At the moment, it is needed to do it, otherwise the engine cannot distinguish between the different file format, if you are using this patch.

@walkawayy
Copy link
Collaborator

I'm not sure if I did something wrong but my game crashes like this:
image
I put the demo config in my cfg folder, made a shortcut with -gold, and put in the title and level2 .phd's in my data folder. I used the demo level linked in the issue here: https://www.allgamestaff.it/download-tomb-raider/tr-1/

For running demo files, you must provide -demo_pc instead of -gold. At the moment, it is needed to do it, otherwise the engine cannot distinguish between the different file format, if you are using this patch.

Oops I think was using -demo. I'll try again tonight. IMO we could probably drop the _pc part?

Copy link
Collaborator

@walkawayy walkawayy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

"key1": "Silver Key",
"puzzle1": "Gold Idol"
},
"demo": true,
Copy link
Collaborator

@walkawayy walkawayy May 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should set "unobtainable_pickups": x, and "unobtainable_kills": x, since TR1X analyzes the whole level for pickups and kills, but the demo ends early.

Copy link
Collaborator

@walkawayy walkawayy May 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here were the final stats I got. So I think "unobtainable_pickups": 5 and "unobtainable_kills": 9. We don't have an unobtainable_secrets gameflow option either since normally that doesn't come up. is this even worth worrying about @rr- ?

image

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made a quick PR #1380 to support this.

@rr- rr- merged commit 3f4b452 into LostArtefacts:develop May 31, 2024
1 check passed
@rr-
Copy link
Collaborator

rr- commented May 31, 2024

Thanks. We'll follow-up with subsequent PRs to try and remove the need for the new gameflow option.

@carlo-bramini
Copy link
Contributor Author

@rr- thanks for bringing this up. My hope is still that immediate and no-purchase no-nothing accessibility to playing the game (and that isn't confusing UB), will help attract a few more players' interest.

I'm in Paris atm without my main PC, but of the top of my head, for PC, there are these demos:

* Vilcabamba Part 1

* Vilcabamba Part 2

* "Terracide" bundle, where a TR demo or Caves and the full Vilcabamba were included (this is the one I'd probably offer)

I just made an interesting discover: I downloaded the Terracide demo bundle which includes also a different TR demo.
Inside, there is:

  • Caves level
  • Vilcabamba level
  • Gym level
  • Several videos non included in the other demos.

Unlike the two demo levels that you can download separately, these ones have the sections like the full game.
In other words, they don't need to use "level_demo_pc" and "title_demo_pc", you must use "normal" and "title" instead.
This is something unexpected.. this patch is required if you want to run the demos each one including a single level, while the demo into the Terracide bundle does not.
I made another json file with only the gym, the first levels and the title and I played it: no problems.

My question after I did this last experiment: since this last demo package includes also some videos and things may start to be a bit confusing, how about adding something like prefix_path on top of the json file?

This may allow to organize data files in this way:

\
 TR1_PC_RETAIL
   data
   fmv
 TR1_PC_DEMO1
   data
 TR1_PC_DEMO2
   data
 TR1_PC_DEMO3
   data
   fmv
 TR1_SATURN
   data
 TR1_PS1
   data
.....

If this prefix is not written in the json file or it is empty, it will work exactly like now.

@carlo-bramini carlo-bramini deleted the add-support-demo-levels-2 branch June 4, 2024 11:26
@rr- rr- added the TR1 label Oct 3, 2024
@lahm86 lahm86 mentioned this pull request Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Demo level support
5 participants