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

Move player movement code into Player class #7220

Closed
wants to merge 1 commit into from

Conversation

bendeutsch
Copy link
Contributor

This allows running the same code on the server, for example for server-side movement checks.

This set of changes is actually a large part of pull request #6219 , "server side movement". But this pull request does not contain any of the network code or server-side checking or reconciliation. All it does is move the main movement methods from LocalPlayer to Player (and thus RemotePlayer), without changing any functionality.

There are just two points that are not "pure" in this sense:

  • the player attribute control has been changed to m_control, to avoid overshadowing by a function parameter of this name
  • the Android "autojump via stepheight" has, yet again, been removed and needs a replacement

player->control.sneak = (keyPressed & 64);
player->control.LMB = (keyPressed & 128);
player->control.RMB = (keyPressed & 256);
player->m_control.up = (keyPressed & 1);
Copy link
Member

Choose a reason for hiding this comment

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

m_* class member variables are supposed to be private

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, that explains why it didn't have the m_ before – I could change it back (it's just confusing with the step and move parameters), or remove the const from the (pre-existing) accessor?

Copy link
Member

Choose a reason for hiding this comment

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

Since it has multiple variables .. -> key_controls ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Technically it's keys, mouse, and joystick 😉

I'll try it with a private member and a non-const accessor-by-reference, sec…

@bendeutsch bendeutsch mentioned this pull request Apr 6, 2018
src/localplayer.h Outdated Show resolved Hide resolved
src/player.cpp Outdated Show resolved Hide resolved
@SmallJoker SmallJoker added @ Server / Client / Env. Maintenance Tasks to keep the codebase and related parts in order, including architectural improvements labels Apr 6, 2018
src/client.cpp Outdated Show resolved Hide resolved
src/clientenvironment.cpp Outdated Show resolved Hide resolved
src/clientenvironment.cpp Outdated Show resolved Hide resolved
@bendeutsch bendeutsch force-pushed the lift-player-move branch 2 times, most recently from 5e519e7 to 5b8b873 Compare April 7, 2018 13:49
@paramat
Copy link
Contributor

paramat commented Apr 7, 2018

the Android "autojump via stepheight" has, yet again, been removed and needs a replacement

Yes good :]

@stujones11
Copy link
Contributor

I am not sure how making the game unplayable for many people can be a good thing. IMO it just makes them more likely to use unofficial clients.

@rubenwardy rubenwardy added the WIP label Apr 8, 2018
@paramat
Copy link
Contributor

paramat commented Apr 9, 2018

I agree, the current code is a nasty hardcoded hack though, it's good that it goes but it certainly needs a replacement. However, a per-player optional stepheight of 1.1 (either chosen by server or server allows each player to choose) is already possible using player object properties, it could be lua code added to builtin or done another way. I won't let 0.5.0 go out without autojump.

The issue for this is #6183

@bendeutsch
Copy link
Contributor Author

@stujones11 : please take a look at PR #7228 as a suggestion for replacing the Android step height hack.

@bendeutsch bendeutsch force-pushed the lift-player-move branch 2 times, most recently from 7cd4c0c to db796a8 Compare April 14, 2018 16:03
@bendeutsch
Copy link
Contributor Author

I've reenabled the Android step height hack! 😱

There's another PR, #7228 , which replaces the step height hack with a real autojump. Originally, the plan was to merge that one, then this (and then adjust the original server side movement, #6219 , and then start on my actual plans for player movement). But then I might as well just not touch the step height hack here, so that this PR can be merged immediately without any change in behaviour.

@bendeutsch
Copy link
Contributor Author

Rebased again, mainly incorporating changes from #7243 .

Could you please reconsider the "WIP" label? I consider this PR finished and mergeable, even if it does not directly add a feature or fix a bug.

src/localplayer.cpp Outdated Show resolved Hide resolved
src/localplayer.cpp Outdated Show resolved Hide resolved
src/player.cpp Outdated Show resolved Hide resolved
src/player.cpp Outdated Show resolved Hide resolved
src/player.cpp Outdated Show resolved Hide resolved
src/remoteplayer.h Outdated Show resolved Hide resolved
src/player.h Outdated
{}
void step(float dtime, const PlayerControl &control,
const PlayerSettings &player_settings, Environment *env,
std::vector<CollisionInfo> *player_collisions = NULL);
Copy link
Member

Choose a reason for hiding this comment

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

The code doesn't seem to account for player_collisions == NULL at all, why does it default to this?

also: should be nullptr

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure, I'll need to check.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it: the Player::step function does not care about the CollisionInfo, but this is used as a parameter when calling Player::move. This function does account for a null pointer.

Please keep in mind that all this PR is trying to do is lift the existing code and algorithms from LocalPlayer to Player. So answering for, or even changing, the existing movement code and call chain is outside of the scope of this PR.

@SmallJoker SmallJoker added the Action / change needed Code still needs changes (PR) / more information requested (Issues) label Jun 19, 2018
@bendeutsch
Copy link
Contributor Author

Oops; I just noticed several requested changes – sorry, @sfan5 , I must have missed the notifications :-(

I'll get on these over the next few days, I hope.

@paramat paramat added the Rebase needed The PR needs to be rebased by its author label Jul 2, 2018
This allows running the same code on the server, for example
for server-side movement checks.
Copy link
Member

@sfan5 sfan5 left a comment

Choose a reason for hiding this comment

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

I don't remember if I'd tested this at the time of my last review, code looks good to me either way.

@sfan5 sfan5 added One approval ✅ ◻️ and removed Rebase needed The PR needs to be rebased by its author Action / change needed Code still needs changes (PR) / more information requested (Issues) labels Jul 3, 2018
@paramat paramat added this to the 5.1.0 milestone Dec 30, 2018
@nerzhul
Copy link
Member

nerzhul commented Mar 5, 2019

rebase needed

@nerzhul nerzhul added Rebase needed The PR needs to be rebased by its author and removed One approval ✅ ◻️ labels Mar 5, 2019
@paramat
Copy link
Contributor

paramat commented Mar 16, 2019

Bump for review attention, this is a high priority issue as it leads to #6219

@ClobberXD
Copy link
Contributor

What should I expect while testing this? There should be no difference in test results whatsoever, right?

@@ -406,7 +406,8 @@ void Client::step(float dtime)
// Control local player (0ms)
LocalPlayer *player = m_env.getLocalPlayer();
assert(player);
player->applyControl(dtime, &m_env);
player->applyControl(dtime, player->getPlayerControl(),
Copy link
Member

Choose a reason for hiding this comment

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

why we pass already owned objects to the player class ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's been a while, but some of these things are because the same code (the same methods) need to be called on the server and the client side, where different things are available.

Or it really is unnecessary, but I'll need to get into the code again first.

@bendeutsch
Copy link
Contributor Author

Hi, sorry, I had just about abandoned this PR; it's a deep change for no visible benefit, after all. No, there should be no changes in tests or behaviour (that I'm aware of).

As a reminder, the goal of this PR is just to make the player movement code available to the server, so that some kind of server-side movement check or replay can be developed. My first attempt was all in one branch, which got out of hand as other work was done on the movement code.

Rebasing will take some time, I fear, but I'll pick it up again. Maintainers can edit, or anyone else can just grab the code and run with it, it's all good.

@paramat
Copy link
Contributor

paramat commented Mar 21, 2019

I'd like to see indication of potential approval from a second core dev before you are required to rebase.
Personally i don't expect contributors to constantly rebase unless there is good chance of a merge.

@ClobberXD
Copy link
Contributor

it's a deep change for no visible benefit, after all. No, there should be no changes in tests or behaviour (that I'm aware of).

Thought so, but just wanted to confirm. I've tested this PR, and I did not notice any oddities or glitches. I ran around and flew around for around 5 minutes each, and didn't encounter any issues. I guess this PR works. :)

👍

@paramat paramat removed this from the 5.1.0 milestone May 8, 2019
@paramat paramat added the Adoption needed The pull request needs someone to adopt it. Adoption welcomed! label Jun 14, 2019
@rubenwardy rubenwardy force-pushed the master branch 2 times, most recently from 0e3b135 to 39c54e1 Compare June 21, 2019 00:46
@paramat
Copy link
Contributor

paramat commented Dec 6, 2019

This is necessary for #6219
Seems to be waiting for more review and support, so that the author sees rebasing as worthwhile (if they are still interested in working on it, see below).

@bendeutsch i seem to have marked all your PRs as 'adoption needed' but cannot remember why, is it the case that you are not interested in working on them? (which is fine by the way).

@rubenwardy
Copy link
Member

@bendeutsch Please work on this, it has one approval and would be a very nice addition

@rubenwardy rubenwardy closed this Mar 6, 2020
@Zughy Zughy removed the Adoption needed The pull request needs someone to adopt it. Adoption welcomed! label May 1, 2022
@Zughy Zughy added the Adoption needed The pull request needs someone to adopt it. Adoption welcomed! label Aug 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Adoption needed The pull request needs someone to adopt it. Adoption welcomed! High priority Maintenance Tasks to keep the codebase and related parts in order, including architectural improvements One approval ✅ ◻️ Possible close Rebase needed The PR needs to be rebased by its author @ Server / Client / Env.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants