-
Notifications
You must be signed in to change notification settings - Fork 164
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
Refactor planet orbital assignment #869
Refactor planet orbital assignment #869
Conversation
d246bd4
to
6c03792
Compare
// if not, put object into the orbit, and remove from any other | ||
// orbit it currently occupies. | ||
if (!OrbitOccupied(orbit)) { | ||
// planet given a specific oribt, check if already assigned |
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.
Typo: oribt -> orbit
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.
My fingers take exception to this, apparently determined that this is the correct spelling. Thank you, will fix.
Ok, @dbenage-cx, I think I need a little help to understand what this PR exactly tries to achieve. Obviously your refactored code is more streamlined/efficient, but the only functional difference I could glance from the changes is how the case is handled when trying to insert a planet at a specific orbit that is already occpied by another planet. The old code apparently did nothing in that case. Your code tries to insert the planet at a randomly chosen different orbit, and making sure that planet gets removed from any orbit it might have occupied before. So, if I understand correctly, there are actually two cases where old and new code will yield different results:
Hence my question: what exactly is the issue this PR tries to address? Have you came across cases where 1) actually lead to buggy results/behavior? I have no idea if those edge cases actually even ever happen, if there are any instances where |
@Vezzra Apologies for the long delay. To address this, I made some assumptions/descisions on the scope of
Issues with old code:
The current method to name planets in universe creation should result in a disordered display of planets in the sidepanel. Since orbits all return Looking at the existing code, there should be at least one planet with a valid orbit (in each system with any planets). I failed to find any planets with a valid orbit. With the new code I have not found any planets without an orbit. I need to address |
6c03792
to
92f6c4d
Compare
No problem. You're not getting paid for this, after all 😉 Ok, I think that it begins to dawn on me where we're heading, but there is still a lot of confusion left, so please bear with me 😉 From what I've understood so far, apparently you ran into that whole mess with the orbits when you tried to fix the issue that all planets and asteroid belts that get created by FOCS effects (currently only this nebula thing) get the same name (which is the name of the system without roman numeral suffix). Then your attempts to find a solution didn't work, and you traced that back to planets getting ordered weirdly, and not being able to get consistent odering between universe generation and FOCS, which ultimately lead to the orbit stuff. Right so far? Hopefully 😉
That's... utterly baffling. Looking at the code (both old and new) I don't understand how that could happen, and how the changes you made might have fixed it. Where/how exactly did you observe that? Client side or serve side? Because server side that should not be happening. The universe generation scripts dutifully iterate over the available orbits when trying to populate the star systems, and specify the orbit when creating and inserting a planet. Furthermore, the interface code specifically checks if an orbit is free before calling That's at least two safety nets that have to malfunction (without reporting any errors in any way on top of that), which strikes me as highly unlikely. Furthermore, map generation would be severely impaired, especially planet placement would be pretty much screwed. As your changes to
Because of the glitch in
Without reporting the failure back to the calling code (just logging an error message), which is definitely a problem. Your code is an improvement insofar as it tries to find another orbit, and if that fails too, doesn't insert the planet at all (also doesn't move it). However, still no feedback to the calling code, so only a partial fix (I'm aware though that a more thorough fix will require some substantial refactoring, so I agree that is the best you could do without having to fix things on a much larger scale). Still, I wonder about the side effects in the various places where
AFAIK
This lets me believe that you ran into all those issues client side, specifically when examining what happens in the sidepanel code. Am I correct in assuming that it's there where all orbits return That would indicate that So basically I think we need to further investigate what really goes wrong here and where. I guess some debugging to check if orbit assignment server side really works correctly as I'm assuming, or if the problem actually does has its source there. I'll help you trying to get to the bottom of this, as far as I can. I'm really curious now, so I guess I'm going to do some debugging in the universe generation code and see what happens to orbit assignment there. Expect to get to that today in the evening and tomorrow, so should be able to report back soon. Regarding the scope of If As that will require a more comprehensive refactoring of all the code where We can either stick with having no orbit assignment for planets we can't place in an orbit (which I don't consider a good idea), or by extending the set of orbits in that case and assign the planet to the newly added orbit. The most obvious in-game case that comes to mind that can trigger this is the Planetary Starlane Drive. It potentially enables the player to stack an unlimited number of planets in one system. If |
Attempts to rely on orbit kept failing, so I started using the debug dump to check the current orbit (will post PR shortly). I did not suspect to be working off of a copy here, the change in
L334 is an assignment to the first orbit, a pretty simple fix by itself.
I actually checked with this to troubleshoot moving into a full system. To my surprise (I expected something bad), the planet bumped right back to its original system with a correct orbit. It still incurred the costs (effects) of a move, which was a concern, though minor for now due to the rarity of such a situation. This PR has changed since, though I suspect in the worst case it is the same outcome. I agree with your points here. Will increase the system orbits as a fallback to insertion in a full system (as a stopgap). |
Oh crap! I've completely missed all the time that this is an assignment, not a comparison here (obviously didn't notice the missing second Honestly, I don't think that this has ever been intended as a fix, but is just a typo and a bug. And needs to be fixed, no question. |
92f6c4d
to
2398498
Compare
Recreated branch with smaller changes (assumed new PRs were not desired in this instance). To summarize:
|
Nifty. So you went with the bare minimum of changes and decided not to expand the set of orbits to accomodate planets if the system is full. Instead, if
line and the fix to I went ahead and merged so we can get on with #761. Of course, now we need to address two issues:
|
Fixes issue with orbits not persisting after planet creation.
As part of the PR, new planets are assigned a random free orbit, consistent with universe generation.
Planets created with a specific orbit are only assigned a random free orbit if the requested orbit is occupied.
If the system has no free orbits for a new planet, it is not added to system.
The ordering of planets in the side panel is by orbit position, since they currently return
-1
, the perceived order is due to the ID.Planets from universe generation are named in order of creation, without regard to orbit position.
As this PR corrects the orbit reported, planets will seem to be in the wrong order. PR #761 corrects the naming.