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

verify command line options #650

Merged
merged 26 commits into from
Jul 14, 2022

Conversation

rfomin
Copy link
Collaborator

@rfomin rfomin commented Jul 10, 2022

Inspired by this issue: coelckers/prboom-plus#515

I'm using docgen to generate a list of command line options to check.

src/m_argv.c Outdated
if (CheckParamsWithArgs(i))
{
// -file and -warp may have multiple arguments
if (!strcasecmp(myargv[i], "-file") ||
Copy link
Owner

Choose a reason for hiding this comment

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

Does -deh also take multiple args?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

-warp can take one or two arguments, depending on the version. Not sure if we should check everything.

Copy link
Owner

Choose a reason for hiding this comment

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

Hm, "do it right or don't do it". 😁 Honestly, I'd expect command line checking code to detect that -warp 1 2 3 4 5 cannot be right.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hm, "do it right or don't do it".

Yes, that's the question 😄 How do you like this approach, is it worth finishing it?
There is also -recordfrom which only takes two arguments.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

BTW with docgen we can also generate code for --help options list, or maybe even help <option> messages.

Copy link
Owner

Choose a reason for hiding this comment

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

We will also need to check the validity of the parameter passed to e.g. the -complevel argument, else this whole checking procedure won't make too much sense.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think we should check the validity of -complevel and other arguments in the game code, such as the -file argument if the path/file is not found. There is 36 options with arguments and most of them silently ignore wrong input.

@kraflab
Copy link
Collaborator

kraflab commented Jul 10, 2022

kraflab/dsda-doom@74a25a5 maybe some food for thought, an approach in dsda-doom (I see this as a more important precursor, but checking if they are used is easy to add on top).

@rfomin
Copy link
Collaborator Author

rfomin commented Jul 10, 2022

kraflab/dsda-doom@74a25a5 maybe some food for thought, an approach in dsda-doom (I see this as a more important precursor, but checking if they are used is easy to add on top).

Interesting, thanks. Looks like PrBoom+'s complevel is the only option that allows a negative integer as an argument? I want to use the - character as a delimiter.

@kraflab
Copy link
Collaborator

kraflab commented Jul 10, 2022

Looks like PrBoom+'s complevel is the only option that allows a negative integer as an argument?

-spechit would "work" with a negative number I think, although I don't really know what the implication would be. It's an address offset to use for certain overflow problems in some specific demos :^)

-setmem also works with negative numbers. It's another overrun thing that I haven't looked into :^)

-skipsec takes negative numbers to skip from the end of the demo instead of from the start

There may be other stuff that takes -1 for a default, I have no idea yet (but I guess I will have a full list when my refactoring is done...)

@rfomin
Copy link
Collaborator Author

rfomin commented Jul 10, 2022

-skipsec takes negative numbers to skip from the end of the demo instead of from the start

Ha, I didn't know that and implemented it differently.

As for memory overflows, I think they are only positive, at least in the Choco code we copied, it is unsigned.

src/d_main.c Outdated
}
else
{
I_Error("Wrong -episode parameter '%s', should be 1-4", myargv[p+1]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can't we have any episode from 0 to 9 now?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Right, in Woof we even support episodes 0-99.
@fabiangreffrath BTW -warp 9999 doesn't currently work, only -warp 99 99. Not sure how to validate -warp 😄

Copy link
Owner

Choose a reason for hiding this comment

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

I think it's okay as it is. No algorithm can know if -warp 999 means to warp to E99M9 or E9M99. 😉

@rfomin rfomin marked this pull request as ready for review July 12, 2022 05:58
@fabiangreffrath
Copy link
Owner

fabiangreffrath commented Jul 12, 2022

From my testing -skill 0 doesn't work at all, all monsters and items still spawn.

This should emulate Vanilla behaviour:

--- a/src/p_mobj.c
+++ b/src/p_mobj.c
@@ -1209,10 +1209,11 @@ void P_SpawnMapThing (mapthing_t* mthing)
     return;

   // killough 11/98: simplify
-  if (gameskill == sk_baby || gameskill == sk_easy ?
+  if ((gameskill == sk_none && demo_version < 203) ||
+      (gameskill == sk_baby || gameskill == sk_easy ?
       !(mthing->options & MTF_EASY) :
       gameskill == sk_hard || gameskill == sk_nightmare ?
-      !(mthing->options & MTF_HARD) : !(mthing->options & MTF_NORMAL))
+      !(mthing->options & MTF_HARD) : !(mthing->options & MTF_NORMAL)))
     return;

   // [crispy] support MUSINFO lump (dynamic music changing)

@fabiangreffrath
Copy link
Owner

This should emulate Vanilla behaviour:

Though, even Pr+ doesn't emulate this. But then the parameter help string needs to be adjusted.

@rfomin
Copy link
Collaborator Author

rfomin commented Jul 12, 2022

Though, even Pr+ doesn't emulate this. But then the parameter help string needs to be adjusted.

We need to emulate it as we support Choco netgame so there is a possibility of desync. Interesting that skill 0 doesn't work in demos.

@kraflab
Copy link
Collaborator

kraflab commented Jul 12, 2022

kraflab/dsda-doom#116 if you're curious how that went🥵
+1526 -936, slightly intrusive change :^)
Refactoring the use of 118 arguments is a real test of willpower 🤠
But, never seeing p < myargc - 1 in the code base is 💆

@rfomin
Copy link
Collaborator Author

rfomin commented Jul 13, 2022

+1526 -936, slightly intrusive change :^)
Refactoring the use of 118 arguments is a real test of willpower 🤠
But, never seeing p < myargc - 1 in the code base is 💆

I think Woof's motto is to preserve as much code as possible, so I take the simpler approach 😄 We have 82 options, but there are a few undocumented secret ones.
Not sure if people will be happy with this change, it might break some launchers/.bat files.

man/docgen Outdated

result += " " * (indent - len(result))

result += textwrap.fill(self.text, width = (90 - indent),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@fabiangreffrath Should we wrap help text for console output? Maybe we should write shorter help lines instead 😉

Copy link
Owner

Choose a reason for hiding this comment

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

Help text should fit into one console line ideally. Do you have an example of a help text line that doesn't fit?

Copy link
Collaborator Author

@rfomin rfomin Jul 13, 2022

Choose a reason for hiding this comment

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

Oops missed your answer.
This is about a response to the -help command. I just generate our CMDLINE documentation, but with selected categories and parameters. So we have a lot of long lines here with multiple sentences: help.txt

Copy link
Owner

Choose a reason for hiding this comment

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

Oh, I like this very much! However, 90 chars is too long for a terminal, e.g. MSYS2's mintty defaults to 80x24. To achieve this, I think we shouldn't cut down the help strings. I very much prefer them to be real sentences and actually helpful. Could you tune it so that each line is broken after at most 80 chars?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, 80 columns is the standard, but I have noticed that many modern applications do not respect it.
Anyway, my English is bad, so I'll just let the Python textwrap library do its job 😄

src/i_system.c Outdated
{
I_Error("Invalid parameter '%s' for -setmem, "
"valid values are dos622, dos71, dosbox "
"or memory offset.", myargv[p]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's not an offset is it? I think it's up to 10 bytes of data.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You're right, I'll correct it.


for t in targets:
# no video and obscure category
if t != c["video"] and t != c["obscure"]:
Copy link
Owner

Choose a reason for hiding this comment

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

Why no video?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't think we have a video option important enough to include in the -help output. However, I'm not sure.

Copy link
Owner

Choose a reason for hiding this comment

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

Okay, the most important options already have their switches in the menu.

src/d_main.c Outdated
startmap = 1;
autostart = true;
startepisode = M_ParmArgToInt(p);
if (startepisode >= 0 && startepisode <= 99)
Copy link
Owner

Choose a reason for hiding this comment

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

We are still unconditionally restricting episode to be > 0:

woof/src/g_game.c

Lines 2982 to 2983 in d8a068c

if (episode < 1)
episode = 1;

@fabiangreffrath
Copy link
Owner

So, is this ready for merging now?

@rfomin
Copy link
Collaborator Author

rfomin commented Jul 14, 2022

Yes, it's ready.

@fabiangreffrath fabiangreffrath merged commit 399e88c into fabiangreffrath:master Jul 14, 2022
@rfomin rfomin deleted the check_cmdline branch July 14, 2022 07:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants