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

Spawn first rail when chunk_0_0 unloaded #525

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

custodian
Copy link
Contributor

@custodian custodian commented Aug 10, 2023

Fixes #438

Steps to reproduce:

  1. Create new world
  2. Move camera away from chunk_0_0 so it unloads (i.e. to 4 0 with visibility of 2 chunks)
  3. Save world
  4. Load world. Move further 1 chunk to trigger chunk_0_0 loaded by default to unload
  5. Try to place first rail within the map

Core reason is that preloaded rail origin is used and it lead to chunk which is not available.

Proposal is to use current camera origin right away.

@HaSa1002 HaSa1002 added bug Something isn't working editor everthing that belongs to the editor functions of Libre TrainSim crash Crashes Godot and thus is a very important issue. chunks When the chunk system inevitably breaks again labels Aug 10, 2023
@HaSa1002 HaSa1002 added this to the 0.9 milestone Aug 10, 2023
@HaSa1002
Copy link
Member

I think this solution is only fixing a symptom and not the core bug while introducing undeterministic save behaviour (we already have some but I want to get red of that completely because it creates versioning noise and easily breakes your maps)

@HaSa1002
Copy link
Member

CC @DasCapschen

@HaSa1002 HaSa1002 changed the title Fixes #438 Spawn first rail when chunk_0_0 unloaded Spawn first rail when chunk_0_0 unloaded Aug 10, 2023
@HaSa1002 HaSa1002 requested a review from a team August 10, 2023 09:36
@nalquas
Copy link
Member

nalquas commented Aug 20, 2023

I'm not sure, but wouldn't using the camera origin mean that track objects could end up in the wrong chunk? Especially if the camera is in one chunk and the rail in another, e.g. due to being close to a chunk's edge?

If I understand correctly, the issue is that the rail origin may not be set (e.g. is 0,0,0). The function _spawn_poles_for_rail is called as part of _spawn_rail, which instances the rail. However, the rail position is only set after calls of _spawn_rail, so may not be set at the time _spawn_poles_for_rail is run.

Here's an example of _spawn_rail being used (taken from Editor.gd lines 734-741):

var rail2: Node = _spawn_rail()
rail2.translation = selected_object.end_pos
rail2.start_pos = selected_object.end_pos
rail2.rotation.y = selected_object.end_rot
rail2.start_rot = selected_object.end_rot
rail2.radius = 0
rail2.length = y_length - x_length
rail2.update()

Perhaps we should adjust _spawn_rail to take a position as a parameter and have it set the translation before _spawn_poles_for_rail is called? I'm not sure what else would be affected though.

@custodian
Copy link
Contributor Author

custodian commented Aug 21, 2023

track objects could end up in the wrong chunk

This is a valid remark, let me dig into this

@custodian custodian marked this pull request as draft August 21, 2023 21:27
@DasCapschen
Copy link
Member

I'm with @nalquas on this one. _spawn_rail() should probably specify the rail position right away.
Also, iirc, we added the chunk of the rail to its metadata at some point. Maybe this should happen in _spawn_rail() too. Then we do not have to calculate the chunk for the rail's track objects.

There's an Edge Case also, which I'm not sure is currently covered:

  • if the rail itself is moved, the chunk must be recalculated and all track objects must be moved to the new chunk...
  • instead of doing that every move, do it on save ?

@HaSa1002
Copy link
Member

instead of doing that every move, do it on save ?

@DasCapschen I thought it's done on save already? Or do I confuse that with the chunk manager and the conversion?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working chunks When the chunk system inevitably breaks again crash Crashes Godot and thus is a very important issue. editor everthing that belongs to the editor functions of Libre TrainSim
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Creation of rails fails far away from (0,0,0) crashes editor
4 participants