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

Ladder Progress #325

Merged
merged 3 commits into from
Nov 9, 2022
Merged

Ladder Progress #325

merged 3 commits into from
Nov 9, 2022

Conversation

thokkat
Copy link
Contributor

@thokkat thokkat commented Sep 21, 2022

Climbing upstairs works now. Might require some adaptions once downstairs climbing is possible.

I tested only in the swamp/-camp. I guess in the Mines there could be some problems sometimes thanks to the steep edges.

#120

@Try
Copy link
Owner

Try commented Sep 21, 2022

Hi, @thokkat and thanks for PR!

I have had a quick look at the code, one thing that is suspicious:

- void Interactive::nextState(Npc& npc)

Why this function is no longer needed? What about other interactive objects?

PS: will look more closely at the end of the week

@thokkat
Copy link
Contributor Author

thokkat commented Sep 22, 2022

It was only used in the processLadder function.

@Try
Copy link
Owner

Try commented Sep 25, 2022

Testing right now(Jarkentar only):
can't climb down - ladder is not interactive. Can be unrelated issue
when holding UpKey, upon climbing, there is a point when key-repeat stops working, at begin at climb

pl.setPosition(pos);
return;
}
if (state==0 || state==stateNum)
Copy link
Owner

Choose a reason for hiding this comment

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

when holding UpKey, upon climbing, there is a point when key-repeat stops working, at begin at climb

Should be state==-1 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually this doesn't happen for me. Can it be keyboard related? Anyway you are right, changing this to -1, why else should it be excluded in the first if statement.

float rot = pl.rotationRad();
float s = std::sin(rot), c = std::cos(rot);
Tempest::Vec3 dp(s,0.0f,-c);
pos += dp*6.f*float(dt);
Copy link
Owner

Choose a reason for hiding this comment

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

6.f is arbitrary, right? While it's achieving the purpose, I have droughts about correctness.
On previous iteration, (back at nextState days), I found that position of npc changes after detaching from ladder. We should probably exam closely animations here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently it's identical to marvin k. I tested some ladders in the G1 swamp camp and one only worked with 6f.

Hmm i have no other idea than "cheating" the character upwards. I only remember that devs said ladders were a nightmare so they left them out of G2 :D. My test ladder in vanilla G1 funnily didn't work too and dropped the character back down at the top.

I look into some other ladders in vanilla to see whats happening there

if(key==KeyCodec::Forward) {
inter.nextState(pl);
if(key==KeyCodec::Forward && !isPressed(KeyCodec::Back)) {
inter.nextLadderMove(false);
Copy link
Owner

Choose a reason for hiding this comment

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

It's probably better to stick with nextState notation, as regular MOBSI are also allowed to have multiple states.
Not in use in vanilla, but can be in mods.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure

if(key==KeyCodec::Back) {
pl.setInteraction(nullptr);
if(key==KeyCodec::Back && !isPressed(KeyCodec::Forward)) {
inter.nextLadderMove(false,true);
Copy link
Owner

Choose a reason for hiding this comment

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

false, true - is not good from readability point of view.
It's probably better to handle key-repeat in implMoveMobsi routine.

Copy link
Contributor Author

@thokkat thokkat Sep 25, 2022

Choose a reason for hiding this comment

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

I kinda had that feeling but couldn't come up with something better.

@thokkat
Copy link
Contributor Author

thokkat commented Sep 26, 2022

Yes non-interactive ladder upstairs was already the case. After some tries there's sometimes an interactive object found but not at the correct place, The climbing animation is played but the character doesn't move.

@thokkat
Copy link
Contributor Author

thokkat commented Sep 29, 2022

When you climb up, reach the end of the ladder and press the action key after the climbing animation ends, you are now again attached to the ladder but a bit shifted. For most ladders i tested that point looks like the vanilla endpoint after climbing is finished, but could also be coincidental.

@thokkat
Copy link
Contributor Author

thokkat commented Sep 30, 2022

I tried the original nextState like this

const int prev = state;
reverseState=reverse;
if(!setAnim(&npc,Anim::In))
  return;
if (reverse)
  setState(std::max(0,state-1));
else
  setState(std::min(stateNum,state+1));
loopState = (prev==state);

but it shows micro stuttering because the animation for the next state is only started after a key press triggers it. Stuttering was also happening before but less noticeable. Also removed the marvin stuff. Like you said it's artificial. Got a bit tricked by memory but vanilla shows it's a smooth process.

@Try
Copy link
Owner

Try commented Oct 3, 2022

Hi, @thokkat !
Sorry, for late response, bit to much code review in flight :)
for debugging, you can use F9/F10, to have frame-by-frame debugging:
F9 - pause
F10 - next frame

Setting MAX_FPS to low values in gothic.ini file can also be useful.

@thokkat thokkat force-pushed the ladder branch 2 times, most recently from f87dea7 to 09b9000 Compare October 9, 2022 22:50
@thokkat thokkat force-pushed the ladder branch 2 times, most recently from 9bcf975 to f99ed9d Compare October 13, 2022 18:14
@thokkat
Copy link
Contributor Author

thokkat commented Oct 13, 2022

@Try, everything works so far, i think you can review. Vanilla G2 crashes for me when entering Jharkendar so i don't know if G2 behavior is replicated correctly.

Still to do but i don't know how:

  • Stuttering issue. At the end of an animation the character is lifted for like 2 frames and then moved back. This results in mini stuttering, less noticeable if fps are high and causes a bit of camera shaking sometimes after climbing upstairs is finished.
  • AI

Copy link
Owner

@Try Try left a comment

Choose a reason for hiding this comment

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

Look very good in game already - left some comments, need to cleanup code a little

game/world/objects/interactive.cpp Outdated Show resolved Hide resolved
game/graphics/mdlvisual.cpp Outdated Show resolved Hide resolved
auto pos = npc.position();
if(npc.interactive()->isLadder()) {
auto rotY=-npc.rotationY();
if (std::abs(rotY)>0.001 && std::abs(dp.y)>0.001) {
Copy link
Owner

Choose a reason for hiding this comment

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

What this code do? I've tested without it - no notifiable difference.

Copy link
Contributor Author

@thokkat thokkat Oct 16, 2022

Choose a reason for hiding this comment

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

For tilted ladders. Character fails to properly climb up at top. And if the ladder is attached to a wall, the character climbs into the wall if climbing down. There is one close to the south gate in old camp.

Copy link
Owner

Choose a reason for hiding this comment

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

Let's not do it for now - in test Jarkendar ladder works most of the time. Top-most ladder sometimes works poorly, but it same as in vanilla.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They shouldn't be affected by it. There are only a few in G1.

Copy link
Owner

Choose a reason for hiding this comment

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

This is quite awkward code still :(
Why std::abs? There is seemingly no divisions downstream or something. And cos/sin should be way faster than the if

AFAIR this is G1 only, right? Can we decouple this change into another PR. This *=-2 fell like fine tuning; Vec3(s,0,-c) - in other places it's usually Vec3(c,0,s)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I only want to test if both values are nonzero, is there a better way? If rotY=0 only a zero vector is added, so this check could be left out. std::abs(dp.y)>0.001 is needed to know if the character is moving and don't add anything if not.

Vec3(s,0,-c) stuff is copied from marvinF8/K routines. Factor 2 is needed to make downstairs climbing look nice and yeah tilted ladders occur only in G1.

game/world/objects/npc.cpp Show resolved Hide resolved
game/world/spaceindex.cpp Show resolved Hide resolved
game/world/objects/npc.cpp Show resolved Hide resolved
@@ -151,6 +151,7 @@ class Interactive : public Vob {
int stepsCount = 0;

int32_t state = -1;
bool wait = false;
Copy link
Owner

Choose a reason for hiding this comment

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

Can it be moved to PlayerControl ? Having this for every interactive object is unnecessary

Copy link
Contributor Author

@thokkat thokkat Oct 16, 2022

Choose a reason for hiding this comment

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

I could use a variable that already exists like isLockCracked? It even does the same just for chests and it should be safe since interactive can't be chest and ladder at the same time.

Copy link
Owner

Choose a reason for hiding this comment

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

Idea is to have cleaner code by keeping player interaction stuff in PlayerControl and common stuff (npc and player) in Interactive.

Copy link
Contributor Author

@thokkat thokkat Oct 16, 2022

Choose a reason for hiding this comment

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

I just don't see how. For chest

  if(needToLockpick(npc)) {
      ...
      return; // chest is locked - need to crack lock first
      }

is checked to prevent playing the chest opening animation too early. The same is needed for ladder to check if player has up or down key pressed.

Edit: Ok going back to original "nextState" may work but then i basically have to copy half of the implTick routine and tailor it to ladder needs.

Just a question about key repeat. For action key, onKeyPressed is called on press and onKeyReleased on release. But for arrow keys these function calls are spammed when holding the key. Is this intended?

Copy link
Owner

Choose a reason for hiding this comment

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

Is this intended?

No, it's not. There is keyPress - ketRepeat - keyRelease workflow, should work same for any key-type.

@thokkat
Copy link
Contributor Author

thokkat commented Oct 16, 2022

Some footage so you know what i mean with tilted ladders.

ladderup.mp4
ladderdown.mp4
ladderFixed.mp4

@thokkat
Copy link
Contributor Author

thokkat commented Oct 19, 2022

I made the aforementioned changes. Tell me if there*s more to do.

@thokkat
Copy link
Contributor Author

thokkat commented Nov 7, 2022

@Try, reminder for review, now that phoenix has been merged ;) . G2 works as expected. In G1 there's now a general bug so animations aren't played.

Copy link
Owner

@Try Try left a comment

Choose a reason for hiding this comment

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

movealgo trigonometry is still suspicious. Other than that look good.

game/game/playercontrol.cpp Show resolved Hide resolved
@@ -196,12 +198,13 @@ void PlayerControl::tickFocus() {
currentFocus = findFocus(&currentFocus);
setTarget(currentFocus.npc);

if(!ctrl[Action::ActionGeneric])
if(!ctrl[Action::ActionGeneric] || Gothic::inst().world()->player()->interactive()!=nullptr)
Copy link
Owner

Choose a reason for hiding this comment

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

  1. nullptr checks - there is no guaranies , that player always will be around
  2. What is the purpose if this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Again for G1 controls. Some ladders showed buggy behavior when interacting at top. This change prevents interaction, if player already interacts.

Copy link
Owner

Choose a reason for hiding this comment

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

Should this kind of check then be placed into Focus World::findFocus(const Npc &pl, const Focus& def)?
if player already interacts with something, then search can simply early-out.

auto pos = npc.position();
if(npc.interactive()->isLadder()) {
auto rotY=-npc.rotationY();
if (std::abs(rotY)>0.001 && std::abs(dp.y)>0.001) {
Copy link
Owner

Choose a reason for hiding this comment

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

This is quite awkward code still :(
Why std::abs? There is seemingly no divisions downstream or something. And cos/sin should be way faster than the if

AFAIR this is G1 only, right? Can we decouple this change into another PR. This *=-2 fell like fine tuning; Vec3(s,0,-c) - in other places it's usually Vec3(c,0,s)

@@ -105,7 +105,7 @@ void InventoryMenu::close() {
}

void InventoryMenu::open(Npc &pl) {
if(pl.isDown() || pl.isMonster() || pl.isInAir() || pl.isSlide() || (pl.interactive()!=nullptr))
if(pl.isDown() || pl.isMonster() || pl.isInAir() || pl.isSlide() || pl.interactive()!=nullptr)
Copy link
Owner

Choose a reason for hiding this comment

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

nitpick: code-style only change - not related to PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So this should be a separate PR?

Copy link
Owner

Choose a reason for hiding this comment

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

No - I'll fix it as separated commit, as followup

@thokkat
Copy link
Contributor Author

thokkat commented Nov 9, 2022

@Try, I cleaned up the abs stuff. Vec3(c,0,s) moves the character leftwards and i only found it in camera.cpp. Vec3(s,0,-c) is copied from marvinF8/K routines,

@Try Try merged commit 46dcdc7 into Try:master Nov 9, 2022
@Try
Copy link
Owner

Try commented Nov 9, 2022

Merged, thanks!

@thokkat thokkat deleted the ladder branch November 12, 2022 17:01
@thokkat thokkat mentioned this pull request Mar 21, 2023
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