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

Fix/Add tracked locations rotating on subcrafts #728

Open
wants to merge 30 commits into
base: main
Choose a base branch
from

Conversation

DerToaster98
Copy link
Contributor

@DerToaster98 DerToaster98 commented Jan 9, 2025

Describe in detail what your pull request accomplishes

Adds proper support for subcrafts to tracked locations. Transfers them to the subcraft and back to the parent on release. The object stays the same so things that use the TrackedLocation can continue to use the same old object and that that updates accordingly.

Also fixes trackedlocations being wrongly rotated on subcrafts in general (the rotation code present does not rotate it correctly, it is necessary to recalculate the new absolute and to adjust the offset via that)

Also re-works trackedlocations so that they basically "move around" a cached value. This is necessary since the old approach used the craft's midpoint as reference location. But since that midpoint can and will change (for example via subcrafts or gradual destruction or launching a torpedo for example) it cant be used as a reference location as that will also move the effective location since the internally stored vector always stays the same

Checklist

  • Tested

Would be better to change this to use the same object but TrackedLocation is not mutable

(cherry picked from commit c1a4e3b)
(cherry picked from commit abeb7ed)
@DerToaster98 DerToaster98 marked this pull request as draft January 17, 2025 17:36
@DerToaster98 DerToaster98 changed the title Add support for SubCrafts in tracked locations Fix/Add tracked locations rotating on subcrafts Jan 17, 2025
(cherry picked from commit 65e1209)
Old logic rotated the vector around the wrong point. Its safer to recalculate the new absolute location and calculate the offset from that

(cherry picked from commit 771094b)
…ons around the rotation point, REGARDLESS of if they are part of the subcraft or not

(cherry picked from commit 7e55636)
…crafts such as squadrons

(cherry picked from commit 289ddbb)
Tested: Calculation wise, the correct result is put out, but either the debugger is inaccurate or something else is happening...
(cherry picked from commit 5085cbf)
(cherry picked from commit 166438c)
(cherry picked from commit d45567e)
it does not need to know the craft.
Also just moving around the cached coordinates is more reliable as it does not rely on a changing center of the craft

(cherry picked from commit 8fe3979)
(cherry picked from commit ab9322b)
(cherry picked from commit 41514c6)
(cherry picked from commit 2792c48)
@DerToaster98 DerToaster98 marked this pull request as ready for review January 18, 2025 17:51

// Java disallows private or protected fields in interfaces, this is a workaround
class Hidden {
// Concurrent so we don't have problems when accessing async (useful for addon plugins that want to do stuff async, for example NPC crafts with complex off-thread pathfinding)
protected static final Map<UUID, Craft> uuidToCraft = Collections.synchronizedMap(new WeakHashMap<>());
}

public class CraftOrigin {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not use a MovecraftLocation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cause thats is immutable

Comment on lines 11 to 13
private int dx;
private int dy;
private int dz;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not use a MovecraftLocation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cause thats is immutable

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And it adds additional overhead i dont need

Not necessary to use ints here as it is just a vector
Untested, but should work
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