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

Parking restrictions - lane highlight not working #827

Open
originalfoo opened this issue Apr 11, 2020 · 14 comments
Open

Parking restrictions - lane highlight not working #827

originalfoo opened this issue Apr 11, 2020 · 14 comments
Labels
BUG Defect detected confirmed Represents confirmed issue or bug LABS TM:PE LABS branch low priority Issue with low priority of work Overlays Overlays, data vis, etc. PARKING Feature: Parking AI / restrictions / etc Usability Make mod easier to use

Comments

@originalfoo
Copy link
Member

In LABS 11.3.0 release (or maybe earlier?) the parking restrictions lane highlight is no longer working.

Related PR where it was added: #708

Parking signs still show and can be toggled and seem to be functional. So it seems it's just the lane highlight that's gone.

@originalfoo originalfoo added BUG Defect detected low priority Issue with low priority of work Usability Make mod easier to use confirmed Represents confirmed issue or bug LABS TM:PE LABS branch PARKING Feature: Parking AI / restrictions / etc Overlays Overlays, data vis, etc. labels Apr 11, 2020
@originalfoo
Copy link
Member Author

@kvakvs could this be caused by similar tool controller issue that affected traffic lights?

@kvakvs
Copy link
Collaborator

kvakvs commented Apr 11, 2020

I did not change anything in the Parking tool, but what I did change is that there are now Legacy style tool classes and new tool classes, and they coexist. While the functionality is mostly retained compared to the release before, there seems to be some problems related to rendering order (such as # 824 always rendering above all UI).
This could be related to #824.
And it also could be related to #830 as that's an overlay problem too.

@originalfoo originalfoo added this to the 11.4.0 milestone Apr 11, 2020
@krzychu124
Copy link
Member

krzychu124 commented Apr 11, 2020

@aubergine10 have you tested it?
image

Edit: hover(green) works too.
Edit2: I'm a bit surprised that there is no throttling issue (GPU temp)

@originalfoo
Copy link
Member Author

Yes, it was me that reported it heh. I'll test again with current master but it was certainly not working with 11.3.0 last night.

@krzychu124
Copy link
Member

I'm running @kvakvs main menu PR, maybe he fixed something there (I remember that something was missing in Lane Arrows facelift)?

@originalfoo
Copy link
Member Author

Ok, so this is odd... It works in some places, but not others:

image

image

Apologies for dark images, it's nearly nighttime in my city and a thunderstorm just started.

These two image illustrate better (TMPE menu placed above the (P) icon I am hovering):

image

image

So maybe it is specific to certain roads or something?

Not working on Olive Street:

image

Works fine on Pine Street:

image

If you want to test with those roads, they are from UK Roads: Small Roads pack.

@originalfoo
Copy link
Member Author

Would bus stops have any effect? Do they add additional lane and the overlays don't notice the change in lanes?

@AllegedlyLuca
Copy link

AllegedlyLuca commented Apr 12, 2020

image

Bus stop on this road doesn't appear to have any impact. NExt2 3/2 asymmetrical.

image

Works fine on vanilla 1-way with bus stop too.

Personally I haven't noticed this bug at all.

@originalfoo
Copy link
Member Author

I modified method in ParkingRestrictionsTool.cs to log some debug trace when Alt key pressed:

private void RenderSegmentParkings(RenderManager.CameraInfo cameraInfo) {
    bool allowed = parkingManager.IsParkingAllowed(renderInfo_.SegmentId, renderInfo_.FinalDirection);
    bool pressed = Input.GetMouseButton(0);

    bool debug = Input.GetKey(KeyCode.LeftAlt);
    if (debug) {
        Log.Info($"[Segment: {renderInfo_.SegmentId}] allowed: {allowed}, pressed: {pressed}");
    }

    Color color;
    if (pressed) {
        color = MainTool.GetToolColor(true, false);
    } else if (allowed) {
        color = Color.green;
    } else {
        color = Color.red;
    }

    Bezier3 bezier = default;
    netService.IterateSegmentLanes(
        renderInfo_.SegmentId,
        (uint laneId,
        ref NetLane lane,
        NetInfo.Lane laneInfo,
        ushort _,
        ref NetSegment segment,
        byte laneIndex) => {
            bool isParking = laneInfo.m_laneType.IsFlagSet(NetInfo.LaneType.Parking);

            if (debug) {
                Log.Info($" - [Lane: {laneId}] isParking: {isParking}, laneDir: {laneInfo.m_finalDirection}, renderDir: {renderInfo_.FinalDirection}");
            }

            if (isParking && (laneInfo.m_finalDirection & renderInfo_.FinalDirection) != 0) {
                bezier = lane.m_bezier;
                laneMarker_ = new SegmentLaneMarker(bezier);
                laneMarker_.RenderOverlay(cameraInfo, color, enlarge: pressed);
            }

            return true;
        });
}

On this segment, highlighting works:

image

Trace:

+ Info 801.2018646: [Segment: 29732] allowed: True, pressed: False
  Info 801.2027105:  - [Lane: 238241] isParking: False, laneDir: None, renderDir: Backward
  Info 801.2032626:  - [Lane: 242835] isParking: False, laneDir: None, renderDir: Backward
  Info 801.2037823:  - [Lane: 67437] isParking: False, laneDir: None, renderDir: Backward
  Info 801.2043326:  - [Lane: 126872] isParking: False, laneDir: None, renderDir: Backward
  Info 801.2048620:  - [Lane: 18803] isParking: False, laneDir: None, renderDir: Backward
  Info 801.2053869:  - [Lane: 116100] isParking: False, laneDir: Backward, renderDir: Backward
+ Info 801.2059225:  - [Lane: 140059] isParking: True, laneDir: Backward, renderDir: Backward
+ Info 801.2065133:  - [Lane: 175182] isParking: True, laneDir: Backward, renderDir: Backward
  Info 801.2070670:  - [Lane: 243009] isParking: False, laneDir: Both, renderDir: Backward
  Info 801.2077417:  - [Lane: 144102] isParking: False, laneDir: Both, renderDir: Backward

On this segment, highlighting fails:

image

+ Info 1,183.9462637: [Segment: 14454] allowed: True, pressed: False
  Info 1,183.9471625:  - [Lane: 242170] isParking: False, laneDir: None, renderDir: Backward
  Info 1,183.9478688:  - [Lane: 158510] isParking: False, laneDir: None, renderDir: Backward
  Info 1,183.9484980:  - [Lane: 206640] isParking: False, laneDir: None, renderDir: Backward
  Info 1,183.9490779:  - [Lane: 185764] isParking: False, laneDir: None, renderDir: Backward
  Info 1,183.9496771:  - [Lane: 112831] isParking: False, laneDir: None, renderDir: Backward
  Info 1,183.9502507:  - [Lane: 141908] isParking: False, laneDir: Backward, renderDir: Backward
  Info 1,183.9508148:  - [Lane: 163894] isParking: False, laneDir: Forward, renderDir: Backward
- Info 1,183.9513744:  - [Lane: 127260] isParking: True, laneDir: Both, renderDir: Backward
- Info 1,183.9519440:  - [Lane: 141601] isParking: True, laneDir: Both, renderDir: Backward
  Info 1,183.9525139:  - [Lane: 63506] isParking: False, laneDir: Both, renderDir: Backward
  Info 1,183.9530717:  - [Lane: 22135] isParking: False, laneDir: Both, renderDir: Backward

So the issue seems to be that the lane dir and render dir mismatch (due to bad road asset; it's parking lanes have dir Both).

This is the line that's preventing the lane highlighting:

if (isParking && laneInfo.m_finalDirection == renderInfo_.FinalDirection) {

That line is required because when a road has parking in two directions, there will be two parking icons (as shown in image above), one for each direction, so depending on which icon is hovered (ie. which direction user wants to alter) we need to filter out the other direction.

Maybe it could be changed to:

if (isParking && (laneInfo.m_finalDirection & renderInfo_.FinalDirection) != 0) {

That should work due to the way the Direction enum is defined:

image

Will test that now... If it works, next step will be to only show one parking icon if any parking lane has dir Both.

@originalfoo originalfoo modified the milestones: 11.4.0, 11.3.2 Apr 14, 2020
@originalfoo
Copy link
Member Author

originalfoo commented Apr 14, 2020

Ok, that got the lane highlighting working again.

hover top icon:
bandicam 2020-04-14 04-23-22-219

hover bottom icon:
bandicam 2020-04-14 04-23-18-394

@kianzarrin Any suggestions on how to do next step:

  • If any parking lane for a segment has direction Both, then only one parking icon shown
    • The renderInfo_.FinalDirection should be Both
  • Also, how to handle the discrepency in the save game data?

@originalfoo
Copy link
Member Author

It looks like GeometryUtil.CalculateSegmentCenterByDir() won't record Both, possibly due to way enums are handled in dictionaries?

What I suspect to be happening:

Regardless, the dictionary segCenter (in ParkingRestrictionsTool.DrawParkingRestrictionHandles()) doesn't contain a Both direction.

Also, looking at the code, I notice that we're iterating all lanes in the segment several times.

Maybe it would be better to iterate lanes once to create a list of parking lanes for the segment, then pass that list around. During that iteration we could also identify if any are parking lanes.

I need to get some sleep, but will have a try and doing that tomorrow.

@kianzarrin
Copy link
Collaborator

this is related to #516

Also, looking at the code, I notice that we're iterating all lanes in the segment several times.
Maybe it would be better to iterate lanes once to create a list of parking lanes for the segment, then pass that list around. During that iteration we could also identify if any are parking lanes.

@aubergine10 if you recall we had a in-depth discussion about this in #516 (comment)

@originalfoo originalfoo removed this from the 11.3.2 milestone Apr 14, 2020
@kianzarrin
Copy link
Collaborator

kianzarrin commented Apr 22, 2020

This piece of code may have something to do with it (check for inconsistent dirIndex):

            int dirIndex = GetDirIndex(finalDir);
            parkingAllowed[segmentId][dirIndex] = flag;

            if (!flag || !parkingAllowed[segmentId][1 - dirIndex]) {// WHY 1 - dirIndex ?!!!!
                Services.SimulationService.AddAction(
                    () => {
                        // force relocation of illegaly parked vehicles
                        Services.NetService.ProcessSegment(
                            segmentId,
                            (ushort segId, ref NetSegment segment) => {
                                segment.UpdateSegment(segmentId);
                                return true;
                            });
                    });
            }

EDIT: on the second thought, this might prevent a lane update, but it should not influence the highlighting.

@originalfoo
Copy link
Member Author

It's also creating excessive GC, due to all the throwaway methods, etc. I will be reviewing all that code when I eradicate the old game bridge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BUG Defect detected confirmed Represents confirmed issue or bug LABS TM:PE LABS branch low priority Issue with low priority of work Overlays Overlays, data vis, etc. PARKING Feature: Parking AI / restrictions / etc Usability Make mod easier to use
Projects
None yet
Development

No branches or pull requests

5 participants