Page MenuHomeWildfire Games

Stop dodging arrows by spamclicking or patrol: Acceleration
AbandonedPublic

Authored by bb on Sep 27 2020, 12:48 AM.

Details

Reviewers
None
Trac Tickets
#5106
Summary

As requested by wraitii, acceleration as an alternative to D2767 and D2837. Adding accelerations on every move. This fixes dancing much worse than D2837, the gameplay impact is much bigger by the looks of it, since one needs rather low accelerations even remotely stop dancing. Also chasing is beyond broken (can be fixed by a similar trick as D2767 and D2837, by not accelerating on all moves).

Note this can easily be combined with D2913, but not so easily with D2837 (see the code stopping the unit on big turns in this patch)

Test Plan

See the need for low accelerations for stopping dancing. Observer the gameplay impact.

Retest D2837 together with D2913.

Event Timeline

bb created this revision.Sep 27 2020, 12:48 AM

Build failure - The Moirai have given mortals hearts that can endure.

builderr-debug-gcc6.txt
<command-line>:0:0: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.
make[1]: *** [obj/simulation2_Debug/CCmpFootprint.o] Error 1
make: *** [simulation2] Error 2

Link to build: https://jenkins.wildfiregames.com/job/docker-differential/3251/display/redirect

bb added a subscriber: wraitii.Sep 27 2020, 12:50 AM
bb added inline comments.Sep 27 2020, 12:54 AM
source/simulation2/components/CCmpUnitMotion.cpp
1094–1098

These changes need to happen anyhow, the bug only gets showcased by this patch

Successful build - Chance fights ever on the side of the prudent.

builderr-debug-macos.txt
../../../source/simulation2/scripting/JSInterface_Simulation.cpp:155:4: warning: suggest braces around initialization of subobject [-Wmissing-braces]
                        CFixedVector2D(-halfSize.X, -halfSize.Y),
                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.
builderr-release-macos.txt
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: ../../../binaries/system/libnetwork.a(precompiled.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: ../../../binaries/system/libtinygettext.a(precompiled.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: ../../../binaries/system/libtinygettext.a(tinygettext.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: ../../../binaries/system/liblobby.a(precompiled.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: ../../../binaries/system/libglooxwrapper.a(precompiled.o) has no symbols
../../../source/simulation2/scripting/JSInterface_Simulation.cpp:155:4: warning: suggest braces around initialization of subobject [-Wmissing-braces]
                        CFixedVector2D(-halfSize.X, -halfSize.Y),
                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: ../../../binaries/system/libsimulation2.a(precompiled.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: ../../../binaries/system/libscriptinterface.a(precompiled.o) has no symbols
../../../source/third_party/fmt/format.cpp:145:7: warning: '_POSIX_C_SOURCE' is not defined, evaluates to 0 [-Wundef]
#if ((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && !_GNU_SOURCE) || (defined(__ANDROID__) && __ANDROID__)
      ^
../../../source/third_party/fmt/format.cpp:145:37: warning: '_XOPEN_SOURCE' is not defined, evaluates to 0 [-Wundef]
#if ((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && !_GNU_SOURCE) || (defined(__ANDROID__) && __ANDROID__)
                                    ^
2 warnings generated.
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: ../../../binaries/system/libengine.a(precompiled.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: ../../../binaries/system/libgraphics.a(precompiled.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: ../../../binaries/system/libatlas.a(precompiled.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: ../../../binaries/system/libgui.a(precompiled.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: ../../../binaries/system/liblowlevel.a(dbghelp.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: ../../../binaries/system/liblowlevel.a(file_stats.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: ../../../binaries/system/liblowlevel.a(vfs_path.o) has no symbols
In file included from ../../../source/graphics/tests/test_Camera.cpp:17:
/Users/wfg/Jenkins/workspace/macos-differential/source/graphics/tests/test_Camera.h:168:4: warning: suggest braces around initialization of subobject [-Wmissing-braces]
                        CVector3D(-101.0f, -101.0f, 101.0f),
                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.
In file included from ../../../source/simulation2/tests/test_SerializeTemplates.cpp:17:
/Users/wfg/Jenkins/workspace/macos-differential/source/simulation2/tests/test_SerializeTemplates.h:39:4: warning: suggest braces around initialization of subobject [-Wmissing-braces]
                        3, 0, 1, 4, 1, 5
                        ^~~~~~~~~~~~~~~~
                        {               }
1 warning generated.

Link to build: https://jenkins.wildfiregames.com/job/macos-differential/1599/display/redirect

bb requested review of this revision.Sep 27 2020, 12:58 AM
bb added inline comments.Sep 27 2020, 3:26 PM
source/simulation2/components/CCmpUnitMotion.cpp
355

nuke

415–424

unitMotionFlying needs same update

Also chasing is beyond broken

I actually find it a tad easier to hunt now, since the hunt does not speed away ^^

Even though the I very much like the concept, I don't know whether this works gameplay-wise indeed.

source/simulation2/components/CCmpUnitMotion.cpp
289

Is this (the duplication) on purpose?

bb added a comment.Sep 28 2020, 12:09 PM

Also chasing is beyond broken

I actually find it a tad easier to hunt now, since the hunt does not speed away ^^

Have you tried attacking an infantry unit which is walking away with melee cav?

source/simulation2/components/CCmpUnitMotion.cpp
289

Don't see the duplication m_CurSpeed and m_RealCurSpeed are different values and since the both change the simstate, they both need to be serialized.

bb updated this revision to Diff 13567.Sep 28 2020, 5:16 PM

Fix OOS noticed by Freagarach

Successful build - Chance fights ever on the side of the prudent.

builderr-release-macos.txt
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: ../../../binaries/system/libsimulation2.a(precompiled.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: ../../../binaries/system/libatlas.a(precompiled.o) has no symbols

Link to build: https://jenkins.wildfiregames.com/job/macos-differential/1604/display/redirect

Stan added a subscriber: Stan.Sep 28 2020, 6:15 PM

Do we have deceleration as well?

Freagarach added inline comments.Sep 30 2020, 5:33 PM
source/simulation2/components/CCmpUnitMotion.cpp
195
1077
vladislavbelov added inline comments.
source/simulation2/components/CCmpUnitMotion.cpp
196

Having CurSpeed and RealCurSpeed seems misleading to me. Because they both are real speed, but maybe in different time points. I think they should have different names and a more detailed comment.

198

The acceleration breaks path finder more, since the acceleration isn't accounted.

1025

Dividing by 2 seems incorrect to me, since accelerations means how the speed is growing (m/s per second = m/s^2).

bb updated this revision to Diff 13616.Oct 10 2020, 4:52 PM

Comments

Successful build - Chance fights ever on the side of the prudent.

builderr-release-macos.txt
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: ../../../binaries/system/libsimulation2.a(precompiled.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: ../../../binaries/system/libatlas.a(precompiled.o) has no symbols

Link to build: https://jenkins.wildfiregames.com/job/macos-differential/1637/display/redirect

bb added inline comments.Oct 10 2020, 5:12 PM
source/simulation2/components/CCmpUnitMotion.cpp
198

Only short range pathfinder collision tests will be less accurate. Else doesn't seem affected.

1025

Ahhaa, can explain some classical mechanics here: I hope you argree that a=d^2/dt^2x(t) (acceleration being the second derivative of the position of the unit). The general solution to this differential equation is x(t)=1/2at^2+v_0t+x_0 (where v_0 and x_0 are the initial position and velocity). Assuming x_0=0 (since we are interested in a difference between two points, not the global position), we see dist=1/2at^2+v_0t. Which is the formula used.
Intuitively it should also be clear: the final speed should be speed+m_Acceleration.Multiply(dt), but I start at with a speed of speed, so the covered distance must be in between speed *dt and (speed+m_Acceleration *dt)*dt since my average speed during the timestep is somewhere in between the initial and final speed.

Palaxin added a subscriber: Palaxin.Dec 3 2020, 5:00 PM
Palaxin added inline comments.
source/simulation2/components/CCmpUnitMotion.cpp
1025

I hold a B.Sc. in physics so I may be helpful here... All of the formulas you have stated here seem to be correct. If we want to calculate the distance x that is covered, we must use x(t) = 1/2*at^2 (+v_0*t (+x_0)).
The constant of 1/2 is a result of the velocity v(t) changing over time. If you want a graphic representation of that, draw diagram with v(t)=a*t on the y axis and t on the x axis. The covered distance (which is the integral of v(t)) is the area between v(t) and the t axis. Here it is readily visible that x(t) = 1/2*v(t)*t = 1/2*at^2. You cannot see that constant it if you just look at the units, @vladislavbelov, since constants do not have units.
However, since velocity is capped at maxSpeed v_max, m_Acceleration a may change from a>0 to a=0 at a certain point of time t_1 and we must split the calculation into several steps. I tried to refer to the variable names in the code, however, from looking just at the piece around line 1025, I don't understand why dt and timeLeft are mixed there, how they are calculated exactly and refer to dt, dt_1 and dt_2 in my calculation. I assume that the total time left dt is known - otherwise you need to make some modifications...

(A) accelerating to v_max with a>0
(1) calculate the time dt_1 we need to reach v_max:
a = dv * dt_1 = (v_max - v_0) * dt_1
--> dt_1 = a / (v_max - v_0)
(2) calculate the distance x_1 until we reach v_max (a>0, v_0=speed x_0=0):
x_1 = 1/2*a*dt_1^2 + v_0*dt_1 = (1/2*a*dt_1 + v_0) * dt_1

(B) moving constantly with v_max and a=0
(3) calculate the remaining time dt_2 we are moving with v_max:
dt_2 = dt - dt_1
(4) calculate the distance x_2 during moving with v_max (a=0, x_0=0):
x_2 = v_max*dt_2

(C) combine
(5) calculate the cumulative distance x=maxdist:
x = x_1 + x_2

In order to reduce the steps, you can also calculate (1), (3) and then (5) where you insert (2) and (4) - however that will make readability much worse...

Palaxin added inline comments.Dec 3 2020, 5:23 PM
source/simulation2/components/CCmpUnitMotion.cpp
1025

Sorry, on a quick look I interpreted your first sentence as a question :/
So actually you probably already were confident about what you were doing...

Freagarach added inline comments.Dec 4 2020, 7:35 AM
source/simulation2/components/CCmpUnitMotion.cpp
1025

An interesting read nevertheless :)

Palaxin added inline comments.Dec 4 2020, 11:28 AM
source/simulation2/components/CCmpUnitMotion.cpp
1025

thx!
For the sake of correctness, in (1) it should read a = dv/dt_1 --> ... --> dt_1 = (v_max - v_0) / a

I think you overcomplicated this diff, compared to D2837. The visual acceleration should be done in Interpolate(), based on initial speed and end speed. Reduce timeLeft by some fraction to account for accelerating, and you should be fine, the rest of the code ought to work natively.

It should probably be done afterr d2837 though.

bb added a comment.Dec 5 2020, 1:46 PM

Don't see a visual acceleration in this patch, it is actual acceleration. Obviously one can also implement an additional visual acceleration in the interpolate, but that is irrelevant for the problem we try to fix (only it might look nice, since well, its visual). Also this can't be combined with D2837.

bb added inline comments.Dec 9 2020, 11:16 PM
source/simulation2/components/CCmpUnitMotion.cpp
1025

You indeed found a mistake: using dt is inherently wrong (since it has no meaning inside the loop) and I wasn't capping the speed correctly at maxSpeed. FYI my physics should be enough (master student), maybe not at 3AM when I wrote the patch though...
(The mistake I made was that in all distance computations I never cap at maxSpeed, but just accelerate a bit more, But as a real physicist: "that computation is still correct in first order dt")

bb abandoned this revision.Dec 17 2020, 11:55 PM

Unmergable since rP24415. Also superseeded by D3200