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

Add crossover rendering #1739

Merged
merged 2 commits into from
Sep 28, 2020
Merged

Add crossover rendering #1739

merged 2 commits into from
Sep 28, 2020

Conversation

roseundy
Copy link
Collaborator

@roseundy roseundy commented Sep 27, 2020

Fixes #513

Also fixed boolean calls in path.rb and one random tile.

New rendering:
crossover
crossover_2
56_crossover
crossover_route

@@ -256,6 +260,13 @@ def load_from_tile
@end_x = edge_x_pos(@end_edge, 87)
@end_y = edge_y_pos(@end_edge, 87)
lanes = @path.lanes

if @tile.crossover? && @path.straight?
@crossover_dash = '1 55 63 56'
Copy link
Owner

Choose a reason for hiding this comment

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

these strings should be constants

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

OK.

@@ -411,7 +428,19 @@ def render_part
'stroke-dasharray': @dash,
) if @terminal

h(:path, props)
children = []
Copy link
Owner

Choose a reason for hiding this comment

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

children = [h(:path, props)]

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

OK

children = []
children.append(h(:path, props))
if @crossover_dash
intersect_props = props.dup
Copy link
Owner

Choose a reason for hiding this comment

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

does this dup actually do what you want? dup is usually just a shallow copy, so nested dictionaries would still be mutated?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It seems to work, but I can change to a a deep copy.

Copy link
Owner

Choose a reason for hiding this comment

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

maybe separate out the hashes

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually I don't need to do either. It seems each call of h(:path, props) is essentially a call by value of the properties, so I'm free to change props between calls.

end

def terminal?
@_terminal ||= !!@terminal
return @_terminal if defined?(@_terminal)
Copy link
Owner

Choose a reason for hiding this comment

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

there's no reason to cache this, it's not expensive at all just do

def terminal?
!!@Terminal

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

OK.

def compute_crossover
edge_paths = Hash.new { |h, k| h[k] = [] }
@paths.each do |p|
edge_paths[p.a.num].append(p) if p.a.edge?
Copy link
Owner

Choose a reason for hiding this comment

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

use << in favor of append

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

OK.

@paths.each do |p|
edge_paths[p.a.num].append(p) if p.a.edge?
edge_paths[p.b.num].append(p) if p.b.edge?
next unless p.nodes.size == 1
Copy link
Owner

Choose a reason for hiding this comment

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

net unless p.nodes.one?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

OK.

edge_paths[p.b.num].append(p) if p.b.edge?
next unless p.nodes.size == 1

ct_edge = preferred_city_town_edges[p.nodes.first]
Copy link
Owner

Choose a reason for hiding this comment

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

what's the point of these 3 lines? they don't do anything

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It calls those methods in path with the proper city/town thus causing them to cache. I don't want to call preferred_city_town_edges in Path.

Copy link
Owner

Choose a reason for hiding this comment

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

what's the point of caching them here? why don't you just do it lazily?

Copy link
Owner

Choose a reason for hiding this comment

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

ohhhhh, wait what, you rely on the order for caching? that's a really dangerous pattern. the cache should take into consideration arguments

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Revamped this to not use arguments at all and to avoid this entire problem.

end

@paths.each do |p|
next if p.nodes.size > 2
Copy link
Owner

Choose a reason for hiding this comment

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

how can a path have more than two nodes?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Damn. Should be 1.

@tobymao tobymao merged commit dbeee81 into tobymao:master Sep 28, 2020
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.

Redraw tiles to make it obvious that you cannot change track at a crossover
2 participants