-
Notifications
You must be signed in to change notification settings - Fork 186
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
Add crossover rendering #1739
Conversation
@@ -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' |
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.
these strings should be constants
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.
OK.
@@ -411,7 +428,19 @@ def render_part | |||
'stroke-dasharray': @dash, | |||
) if @terminal | |||
|
|||
h(:path, props) | |||
children = [] |
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.
children = [h(:path, props)]
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.
OK
children = [] | ||
children.append(h(:path, props)) | ||
if @crossover_dash | ||
intersect_props = props.dup |
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.
does this dup actually do what you want? dup is usually just a shallow copy, so nested dictionaries would still be mutated?
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.
It seems to work, but I can change to a a deep copy.
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.
maybe separate out the hashes
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.
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.
lib/engine/part/path.rb
Outdated
end | ||
|
||
def terminal? | ||
@_terminal ||= !!@terminal | ||
return @_terminal if defined?(@_terminal) |
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.
there's no reason to cache this, it's not expensive at all just do
def terminal?
!!@Terminal
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.
OK.
lib/engine/tile.rb
Outdated
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? |
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.
use << in favor of append
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.
OK.
lib/engine/tile.rb
Outdated
@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 |
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.
net unless p.nodes.one?
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.
OK.
lib/engine/tile.rb
Outdated
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] |
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.
what's the point of these 3 lines? they don't do anything
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.
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.
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.
what's the point of caching them here? why don't you just do it lazily?
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.
ohhhhh, wait what, you rely on the order for caching? that's a really dangerous pattern. the cache should take into consideration arguments
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.
Revamped this to not use arguments at all and to avoid this entire problem.
lib/engine/tile.rb
Outdated
end | ||
|
||
@paths.each do |p| | ||
next if p.nodes.size > 2 |
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.
how can a path have more than two nodes?
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.
Damn. Should be 1.
Fixes #513
Also fixed boolean calls in path.rb and one random tile.
New rendering: