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

Have clients select weapons by ID, rather than by name #212

Merged
merged 1 commit into from
Aug 19, 2023

Conversation

Toodles2You
Copy link
Contributor

The usercmd_t struct has a weaponselect field, used in the weapon prediction code, to select weapons by ID. Being a part of the client's command struct, it can also be sent over the net. Using this instead of sending a "weapon_" command every time a client wants to change weapons should substantially reduce the number of string comparisons that the server has to handle in multiplayer. In network/delta.lst, I set it to be sent as 6 bits, as weapon IDs only go up to 64.

(I also removed the SelectItem definition on the client, as it seems to be dead code.)

@Toodles2You
Copy link
Contributor Author

Also, the original method of selecting weapons is still available, so it won't break existing configs that use them.

player->SelectItem(pcmd);
auto weapon = player->GetNamedPlayerItem(pcmd);

if (weapon != nullptr)
Copy link
Collaborator

Choose a reason for hiding this comment

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

It would be better to have a SelectItem overload that takes a classname and do what the original method did, then you don't need these changes here. People who merge changes into their projects won't have to make extra changes as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea. If I update my branch, would you recommend amending the existing commit or creating a new one?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Amend the commit. No need to add multiple commits to a pull request.

@SamVanheer
Copy link
Collaborator

Have you tested this in a multiplayer environment with host_limitlocal set to 1? This limits command updates when running a local multiplayer server which can delay transmission of commands and thus delay the server's weapon switching logic.

@Toodles2You
Copy link
Contributor Author

Toodles2You commented Aug 18, 2023

I just did a quick comparison between the two with host_limitlocal set to 1 and fakelag set to 30. In the past, I had done both tests with fakelag and LAN multiplayer with one other person. The only difference I've ever observed is that, with the cmd->weaponselect method, it's less likely for a switch to get delayed or ignored when rapidly switching between weapons. The actual delay between the client sending the command and server receiving it seems indistinguishable.

I should also mention that I discovered this because of it's use in Deathmatch: Classic.
https://github.com/ValveSoftware/halflife/blob/master/dmc/dlls/client.cpp#L1669

My thought process is that, even if they're functionally identical, less data being sent over the wire is a win. And that because it's officially implemented in a multiplayer GoldSrc game, it's likely a stable feature.

@SamVanheer
Copy link
Collaborator

This method is also used in Source:
https://github.com/ValveSoftware/source-sdk-2013/blob/0d8dceea4310fde5706b3ce1c70609d72a38efdf/mp/src/game/client/in_main.cpp#L1165-L1175
https://github.com/ValveSoftware/source-sdk-2013/blob/0d8dceea4310fde5706b3ce1c70609d72a38efdf/mp/src/game/server/player_command.cpp#L378-L387

So they probably planned on doing it during HL1's development, got around to it when making DMC and then used it in Source games from that point onward.

@SamVanheer SamVanheer merged commit 7709454 into twhl-community:master Aug 19, 2023
3 checks passed
@SamVanheer
Copy link
Collaborator

Sorry, i merged this by accident. Looks like i can't reopen it, can you create a new PR with the changes?

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.

2 participants