-
Notifications
You must be signed in to change notification settings - Fork 39
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
Add support demo levels (try 2) #1378
Conversation
66f7919
to
2a7ecb3
Compare
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. |
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? |
@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:
|
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. |
Good call on editing the files especially since there is finite amount of them IMO. |
Ok, no problem! |
src/game/gameflow.c
Outdated
@@ -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[] = { |
There was a problem hiding this comment.
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.
src/game/gameflow.c
Outdated
{ NULL, -1 }, | ||
}; | ||
|
||
static const STRING_TO_ENUM_TYPE map_GAMEFLOW_SEQ_TYPE[] = { |
There was a problem hiding this comment.
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.
src/game/gameflow.c
Outdated
}; | ||
|
||
static int32_t GameFlow_StringToEnumType( | ||
const char *str, const STRING_TO_ENUM_TYPE *map) |
There was a problem hiding this comment.
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.)
src/game/gameflow.c
Outdated
@@ -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; |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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.
Oops I meant to comment rather than approving. |
fe22246
to
e57caf7
Compare
e57caf7
to
0f1928a
Compare
I'm not sure if I did something wrong but my game crashes like this: 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/ |
The gameflow refers to the demo files with |
For running demo files, you must provide |
Oops I think was using |
There was a problem hiding this 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, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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- ?
There was a problem hiding this comment.
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.
Thanks. We'll follow-up with subsequent PRs to try and remove the need for the new gameflow option. |
I just made an interesting discover: I downloaded the Terracide demo bundle which includes also a different TR demo.
Unlike the two demo levels that you can download separately, these ones have the sections like the full game. 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:
If this prefix is not written in the json file or it is empty, it will work exactly like now. |
Checklist
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:
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.