-
Notifications
You must be signed in to change notification settings - Fork 89
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
Ladder Progress #325
Conversation
Hi, @thokkat and thanks for PR! I have had a quick look at the code, one thing that is suspicious:
Why this function is no longer needed? What about other interactive objects? PS: will look more closely at the end of the week |
It was only used in the processLadder function. |
Testing right now(Jarkentar only): |
game/world/objects/interactive.cpp
Outdated
pl.setPosition(pos); | ||
return; | ||
} | ||
if (state==0 || state==stateNum) |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
game/world/objects/interactive.cpp
Outdated
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
game/game/playercontrol.cpp
Outdated
if(key==KeyCodec::Forward) { | ||
inter.nextState(pl); | ||
if(key==KeyCodec::Forward && !isPressed(KeyCodec::Back)) { | ||
inter.nextLadderMove(false); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure
game/game/playercontrol.cpp
Outdated
if(key==KeyCodec::Back) { | ||
pl.setInteraction(nullptr); | ||
if(key==KeyCodec::Back && !isPressed(KeyCodec::Forward)) { | ||
inter.nextLadderMove(false,true); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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. |
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. |
I tried the original nextState like this
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. |
Hi, @thokkat ! Setting MAX_FPS to low values in gothic.ini file can also be useful. |
f87dea7
to
09b9000
Compare
9bcf975
to
f99ed9d
Compare
@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:
|
There was a problem hiding this 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/game/movealgo.cpp
Outdated
auto pos = npc.position(); | ||
if(npc.interactive()->isLadder()) { | ||
auto rotY=-npc.rotationY(); | ||
if (std::abs(rotY)>0.001 && std::abs(dp.y)>0.001) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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/interactive.h
Outdated
@@ -151,6 +151,7 @@ class Interactive : public Vob { | |||
int stepsCount = 0; | |||
|
|||
int32_t state = -1; | |||
bool wait = false; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
Some footage so you know what i mean with tilted ladders. ladderup.mp4ladderdown.mp4ladderFixed.mp4 |
I made the aforementioned changes. Tell me if there*s more to do. |
@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. |
There was a problem hiding this 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
Outdated
@@ -196,12 +198,13 @@ void PlayerControl::tickFocus() { | |||
currentFocus = findFocus(¤tFocus); | |||
setTarget(currentFocus.npc); | |||
|
|||
if(!ctrl[Action::ActionGeneric]) | |||
if(!ctrl[Action::ActionGeneric] || Gothic::inst().world()->player()->interactive()!=nullptr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- nullptr checks - there is no guaranies , that player always will be around
- What is the purpose if this change?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
game/game/movealgo.cpp
Outdated
auto pos = npc.position(); | ||
if(npc.interactive()->isLadder()) { | ||
auto rotY=-npc.rotationY(); | ||
if (std::abs(rotY)>0.001 && std::abs(dp.y)>0.001) { |
There was a problem hiding this comment.
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)
game/ui/inventorymenu.cpp
Outdated
@@ -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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
@Try, I cleaned up the |
Merged, thanks! |
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