CitiesSkylinesMods / TMPE

Cities: Skylines Traffic Manager: President Edition
https://steamcommunity.com/sharedfiles/filedetails/?id=1637663252
MIT License
574 stars 85 forks source link

lane connector should hide tracks that are not connected #734

Closed kianzarrin closed 2 years ago

kianzarrin commented 4 years ago

Depends on #782

image

Setting max turn angle is one way of disconnecting sharp tracks. But it limited to disconnecting by angles. More customizable way of doing this is using lane connector.

To do this we need to patch NetNode.RenderNode() NetNode.PupulateGroupData() and NetNode.CalculateGroupData() . specially around the check flags code.

Use the same version of Harmony as Hide TMPE crosswalks and NS2 to be compatible with those mods. (boformer told me NS2 is buggy and different versions of NS2 don't work with each other :( )

EDIT:

Tasks:

PLAN: see https://github.com/CitiesSkylinesMods/TMPE/issues/734#issuecomment-590807175

This task needs to be divided into several steps:

  1. exclude unconnected direct train connections one a per segment basis
  2. exclude unconnected direct train connections one a per direction basis
  3. support lod (die hards can use ULOD mod can be used until this is supported). PS: lane connector should post UpdateNode()
  4. exclude unconnected direct train connections on a per lane basis for custom assets that have more than one pair of tracks.
kianzarrin commented 4 years ago

The catch is you cannot disconnect all tracks using this mehtod but as long as we are fixing vast majority of problems then i say its an improvement.

kianzarrin commented 4 years ago

This is close to hide TMPE crosswalks mod but much easier since it does not require any image processing.

kianzarrin commented 4 years ago

This approach does not work for multi track

originalfoo commented 4 years ago

I'll close #647 as this 734 has better detail.

originalfoo commented 4 years ago

Image from #647:

img

Would be great if lane connector could toggle the tracks crossing that junction in the image above so that only connected tracks were shown.

originalfoo commented 4 years ago

The catch is you cannot disconnect all tracks using this mehtod but as long as we are fixing vast majority of problems then i say its an improvement.

This approach does not work for multi track

Please elaborate.

kianzarrin commented 4 years ago

@aubergine10 Please elaborate.

This approach does not work for multi track

Now that I see that nice picture of yours I take it back!

The catch is you cannot disconnect all tracks using this method but as long as we are fixing vast majority of problems then i say its an improvement.

I don' think anyone ever wants to do this. but lets say in this picture someone wants all tracks to be disconnected from one another (maybe he wants to paint the connections himself ? maybe he wants to create a funny clip ?) it is not possible to do so using lane connector. if there are no lane connection we fall back to the vanilla connection method.

kianzarrin commented 4 years ago

progress note: my TranspilerUtil has very easy to use code to search for nodeDD, segmentID and instructions. This should be easy.

PS: This is good learning experience for https://github.com/kianzarrin/myrepo/issues/2 :D PS2: my code https://github.com/kianzarrin/KianButtonMod/tree/hide-unconnected-tracks

originalfoo commented 4 years ago
kianzarrin commented 4 years ago

Metro overhaul is too heavy for my computer. I think I can make it work for a small test.

kianzarrin commented 4 years ago

None of the NetNode.PupulateGroupData() NetNode.CalculateGroupData() ShouldDrawConnectTexture() check for lanes. So I do not understand how do they connect the lanes together. It does check for Info.m_forwardVehicleLane/Info.m_backwardVehicleLanes. I have to patch the code to exclude some code paths to see what happens. EDIT: I am suspecting it has something to do with Info.m_nodes . I should check the materials

kianzarrin commented 4 years ago

These pictures show I can disconnect tacks on an on segment basis for close camera: Screenshot (583) Screenshot (584)

@aubergine10 remember when I said:

The catch is you cannot disconnect all tracks using this method but as long as we are fixing vast majority of problems then i say its an improvement.

I meant that to achieve no connection at all like in the first screenshot is not an option ... not using lane connector anyways. LaneConnector GUI is setup such that each lane is connected to at least one other lane.

originalfoo commented 4 years ago

I meant that to achieve no connection at all like in the first screenshot is not an option ... not using lane connector anyways. LaneConnector GUI is setup such that each lane is connected to at least one other lane.

The way it currently works is correct. An incoming vehicle lane should be connected to at least one outgoing vehicle lane.

kianzarrin commented 4 years ago

The way the lane connections are handled is by Info.m_nodes The relevant field is m_connectGroup.

Two way track node Info has m_connectGroup=DoubleTracks.

One way track has some extra connection node infos to deal with various conditions. m_connectGroup is one of the following combos:

m_connectGroup for connection node infos of Train station track network has the following combos:

This means its going to be difficult to hide unused tracks in the image bellow. I need to EITHER do some mesh processing (cut the mesh in half) and produce the extra meshes OR borrow node infos from single train track. The latter approach works for vanilla networks. for custom roads I EITHER need to ask assert creators to add extra node textures OR look at the name of ALL NetInfos and guess which one is the matching single track NetInfo.

Supporting the situation in the screen shot bellow on the other hand is going to be much easier because it is on a per segment basis rather than one a per lane basis:

This task needs to be divided into several steps:

  1. exclude unconnected direct train connections one a per segment basis
  2. exclude unconnected direct train connections one a per direction basis
  3. support lod (die hards can use ULOD mod can be used until this is supported).
  4. exclude unconnected direction train connections on a per lane basis for custom assets that have more than one pair of tracks.

I am reopening #647 to support the second step.

originalfoo commented 4 years ago

See if this is any use: #634 - specifically there's a flag (at least for station tracks, but maybe all tracks?) that is used to create X junctions like those either side of train station. So maybe tracks contain a single track variant to make that work?

kianzarrin commented 4 years ago

as far as I understand that flag is used to create junctions and does not influence already existing junctions. I tried it and observed no difference. I don't think we can solve the problem of mesh and textures with a flag or even extra code (unless if that code generates mesh!).

kianzarrin commented 4 years ago

Progress! Screenshot (597) Screenshot (596) Screenshot (595) Screenshot (594)

works for close and medium camera range.

This might cause some user complaints : https://github.com/CitiesSkylinesMods/TMPE/milestone/20

originalfoo commented 4 years ago

This might cause some user complaints

??

kianzarrin commented 4 years ago

in the link (https://github.com/CitiesSkylinesMods/TMPE/milestone/20) there is a list of issues related to selecting tracks which overlap with road. If the tram is overlapping with road and user cannot hide tracks because of it they cannot select the track in the lane connector, it would be such a bummer!

originalfoo commented 4 years ago

Good point. So it seems we need to solve the track vs. road issues first before we can properly tackle the hiding of tracks based on lane connectors.

And there is also the Harmony version issue discussed in Discord chat. :/

Suggested plan:

  1. Fix last remaining bug in #721 - then I think we are in good position to release TMPE v11.1.1 LABS (which will later get moved to v11 STABLE)
  2. Then we focus on the track vs. road issues (and some other stuff, eg. route tool PR that pretty much done) for v11.2.* with regular updates to LABS
  3. Come back to #734 and #647 for v11.3?

Possibly in parallel a separate mod could be done to start testing out the #734 and #647 stuff? Similar to the hide crosswalks mod. Would allow much faster iteration without need for translations, PR, etc., and users can more easily opt in/out of testing it.

What do you think?

kianzarrin commented 4 years ago

I don't think we need to fix them we need to solve the track vs. road issues FIRST we should just increases their priority. this is only a problem only with track lanes on the top of car lanes. this is unlike Vanilla tracks in which the same lane supports both trams and cars. Only when tram and car lanes are separated (and tram lane has higher landex) this MIGHT be an issue.

originalfoo commented 4 years ago

Ok, that should be focus of v11.2 then.

Random thought: For the lane highlights, is there a way to have the border line dashed? Would be nice if the lane highlight could be visibly different when working with tracks.

krzychu124 commented 4 years ago

Random thought: For the lane highlights, is there a way to have the border line dashed? Would be nice if the lane highlight could be visibly different when working with tracks.

Nope, changing border style is not supported by vanilla overlay shapes (I will consider it when I'll be working on improvements for new shader)

kianzarrin commented 4 years ago

TMPE needs to patch RenderInstance() in order to solve this issue.

The problem is that NS2 is also patching RenderInstance() using incompatible version of Harmony. see https://github.com/pardeike/Harmony#harmony-12 .

We are using harmony V1.2 while NS2 is using intermediate V2.0 -NS2 readme explains why.

I think NS2 should change to 1.2 and find a way around __state problem (would patching 1.2 work?). I probably be the one who ends up doing that.

Other alternative is for TMPE to switch to version 2 but that is not going to work out well with other mods. TMPE could hold 2 versions of Harmony but I don't think that's a good idea because then explaining it to mod creators is going to be hard.

my conversation with boformer: Screenshot (600)

@krzychu124 I heard you are good at Harmony any ideas?

krzychu124 commented 4 years ago

There are some problems which v2.0 resolves, but not available in 1.2, like ref struct params. I haven't looks into NS2 code yet, so I don't know where is/could be the exact problem. I only patched some Ui methods in FPS_Booster to make them compatible

kianzarrin commented 4 years ago

I noticed that TMPE has worked around the ref struct params using manual harmony patching. NS2 could do the same.

kianzarrin commented 4 years ago

EDIT: This issue Depends on #782

We must go to harmony 2.0.0.8 to resolve this issue. This is because I need to patch NetNode.RenderInstance() which cannot be done in harmony 1.2.1 . I did not manage to find a work around either.

Here is my conversation with @Brraiz

kian.zarrinToday at 20:30 Hi, Short version: does harmony 1.2.1 support by ref struct types? is there a list of bugs in for harmony 1.2.1? Long version: I am having trouble to patch a function with by ref struct parameter. It works on harmony 2.0.0.8 ... but on harmony 1.2.1, but I am getting format exception. I am patching it manually using Harmony.Patch(target:mytarget, transpiler:mytrasniler)

// the last parameter RenderManager/Instance& is a by ref struct type
FormatException: Method NetNode.RenderInstance(RenderManager+CameraInfo, System.UInt16, NetInfo, System.Int32, NetNode+Flags, System.UInt32&, RenderManager+Instance&) cannot be patched. Reason: Invalid IL code in (wrapper dynamic-method) NetNode:RenderInstance_Patch0 (object,RenderManager/CameraInfo,uint16,NetInfo,int,NetNode/Flags,uint&,RenderManager/Instance&): IL_0e64: callvirt  0x000003b3

Brrainz Today at 20:45 It probably does not work

kianzarrin commented 4 years ago

This is how the mesh looks like: from right to left ConnectGroup = oneway track:SingleTrack,OnewayStart - SingleTrack,OnewayEnd, SingleTrack,Oneway twoway track: DoubleTrack train station track: SingleTrack - DoubleTrack image

These meshes are insufficient to cover all circumstances. I need to cut the material for two-way track in half. for more combos.

kianzarrin commented 4 years ago

The UV map looks like this: UV map for the right track: image UV map for the left track: image They are intertwined. So I don't thin we need to cut the textures at all. We just need to modify the mesh and that's all. I don't want to go through the route of dynamic mesh creation. For now I will just create the mesh offline. I wonder if the mesh for the single track mesh could be shifted left or right without the need for mesh generation

kianzarrin commented 4 years ago

I created the meshes for left and right track by loading the track in blender and deleting the virtexes for left or right. image Left and right track.zip

Hopefully it will work as it is :)

EDIT: I have not got around doing the mesh for wires yet. but I need to do that at some point. EDIT2: IN any case even without this mesh I can do some stuff with train station tracks with the one way and two way meshes I already have.

kianzarrin commented 4 years ago

Progress! image

originalfoo commented 4 years ago

that's freaking awesome!

kianzarrin commented 4 years ago

for quad networks we need meshes from asset creators. We have to let asset creators to use TMPE flags as required/forbidden flags for their assets. This means we need to work on Asset editor. I think I can create an add-on for that.

kianzarrin commented 4 years ago

The code works for train tracks (not the wires yet) image image Now all that remains is dynamic mesh generation. Lods atlas could be tricky.

kianzarrin commented 2 years ago

I closed this because this is now covered by the new AR tracks

kianzarrin commented 2 years ago

image

originalfoo commented 2 years ago

Those RWY2 quad tracks? And procgen rails! Nice!

Can concrete/wood railway sleepers be added programatically to help fill some of the clipped region? Railway/BVU Track Customizations mod gives some indication of what to look for (at least for RWY1 assets).