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

Added auto move feature #2647

Merged
merged 3 commits into from
Dec 8, 2016
Merged

Added auto move feature #2647

merged 3 commits into from
Dec 8, 2016

Conversation

zeokav
Copy link
Contributor

@zeokav zeokav commented Dec 7, 2016

Contains

A PR to address #2557 . I have added a binding to enable auto run.

How to test

Open up a game and press R (default binding - can be changed from the inputs menu). Any other action will stop the auto run state.

Notes

More like questions before merging -

  • I have made impulse events fire up every 200 milliseconds. Will this have a negative impact on the performance? If I increase the deltas, the movement looks more jerky than how it does if I keep it at 200ms.
  • I would like some feedback though because using this method makes the movement looks slightly sluggish.

@GooeyHub
Copy link
Member

GooeyHub commented Dec 7, 2016

Can one of the admins please verify this patch?

Copy link
Member

@skaldarnar skaldarnar left a comment

Choose a reason for hiding this comment

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

Overall, the code looks clean and I think you've got the right idea. Please have a look at the suggested changes.

private void startAutoMove(EntityRef entity) {
isAutoMove = true;
ClientComponent clientComponent = entity.getComponent(ClientComponent.class);
new Thread(() -> {
Copy link
Member

Choose a reason for hiding this comment

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

Imho this should not be done with a new Thread, but with the help of DelayManager. You can schedule events there, and cancel the periodic events if auto-move should stop.

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 an issue. I'll fix this bit! 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@skaldarnar I looked up DelayManager but I could not find any implementation of it. What should my action Id be? And where exactly am I supposed to define the action that has to happen periodically?

Copy link
Contributor

Choose a reason for hiding this comment

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

@zeokav I have some usage of DelayManager in one of my repos.
Check out Line 40 (get an instance), Line 78 (register delayed action) and Line 82F (handle the event). I think there are two different events for delayed and periodic action, so if you need the other one, you may want to inspect the source of delaymanager directly :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @oniatus! Some small changes and I got it working. 👍

while(isAutoMove) {
try {
Vector3f viewDir = entity.getComponent(LocationComponent.class).getWorldDirection();
clientComponent.character.send(new CharacterImpulseEvent(viewDir.mul(8f)));
Copy link
Member

Choose a reason for hiding this comment

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

The CharacterImpulseEvent likely makes the movement feel sluggish. The impulse will actually push the player forward, instigated by some external force, not actually the player moving by himself.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@skaldarnar : What can I use to make it feel smooth? I was looking for something that could simulate a key press event with the Forwards key pressed at all times but that drops inputs because of too many inputs from the entity.

Copy link
Member

Choose a reason for hiding this comment

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

That is a good question. Programmatic triggering of the movement key would be the best option imho. I have to look into that as well and will come back to you on this topic later 😉 For now, using the impulse event to get working in the first place is fine!

@zeokav
Copy link
Contributor Author

zeokav commented Dec 8, 2016

@skaldarnar I have made the change you asked for (Using delayed manager instead of making a new thread). :)

@skaldarnar skaldarnar merged commit c6e6111 into MovingBlocks:develop Dec 8, 2016
@skaldarnar
Copy link
Member

@zeokav merged!

What do you think about staying in automove mode when jumping? That way you could travel long distances in non-flat worlds as well. I still have to look into the key press event vs impulse event.

@zeokav
Copy link
Contributor Author

zeokav commented Dec 8, 2016

@skaldarnar I was thinking of that too since the world is more multi-levelled than flat. Just have to change a line or two for that anyway. I'll club it along with my next PR. 😄

@zeokav zeokav deleted the automove branch December 8, 2016 19:10
@Cervator Cervator modified the milestone: Alpha 7 Dec 10, 2016
@smsunarto smsunarto mentioned this pull request Dec 10, 2016
@rzats rzats added Topic: Architecture Requests, Issues and Changes related to software architecture, programming patterns, etc. Google Code-in labels Dec 17, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Topic: Architecture Requests, Issues and Changes related to software architecture, programming patterns, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants