joaofarias / csl-traffic

A WIP mod for Cities: Skylines to improve traffic.
91 stars 30 forks source link

Idea: Variations of existing road types, without creating a new NetInfo (for compatibility) #84

Open boformer opened 9 years ago

boformer commented 9 years ago

Do you think it is possible to create variations of existing road types WITHOUT creating new NetInfo prefabs?

I only want to apply visual changes, like replacing:

Some Ideas: Cobblestone roads, roads with palm trees, roads with chinese lanterns, gravel roads using a different texture...

These roads would revert to the vanilla road types when people remove the mod. The normal roads can coexist with the variations. Also, no extra icon in the roads panel is needed for the variations.

joaofarias commented 9 years ago

I tried to find a way to do that but haven't found any way that wouldn't be very aggressive (in terms of overriding great amounts of core vanilla code) and that wouldn't (theoretically) reduce FPS by a lot since it would hook to the rendering system.

The way the game is set up is that the little structs that store the info for the laid down roads only store that very specific info leaving the data about textures, models and props to the netinfo class. This is obviously to save memory. Then, there is the problem that the roads that are available to be laid down correspond to the existent NetInfo. You wouldn't be able to select different types of roads without multiple NetInfo objects.

If you can find a way to show your new roads on the menu to be laid down (or even with a key shortcut) you would need to store this info separately, hook up to the rendering system, check the road that is being rendered to see if it has special props or textures and apply them when they do. You can see how this can easily become a huge mess.

Having said that, let me know if you find a better way.

boformer commented 9 years ago

Here is my idea for props:

We store the extra information (like which propset to use for a lane) in a separate xml config, like this:

Then we have to detour all methods which render the props (2 or 3 methods). It should not affect the performance too much.
joaofarias commented 9 years ago

You can use xml to define the types of roads but you'll need something to identify them in-game. Take the 6-lane road for example, you have the vanilla and imagine you have 2 more of your custom types. Now, the player lays down 5 of each. When rendering, you have to know which is which to apply the custom stuff (or none if it's the vanilla).

Regarding detouring the methods, I think it would be better to detour the one where it gets the netinfo and starts rendering. You could then swap the stuff in the netinfo for yours, whether it is props or textures, the vanilla code would then handle it correctly. But this swapping takes time and when you have thousands of roads and it needs to swap thousands of times, it's going to take a toll on the FPS.

This would be so much simpler if CO added a fallback for the roads...

benklop commented 8 years ago

I realize this is quite an old discussion, and I don't know whether a better solution has presented itself since this took place, but it strikes me that districts are perfect for this. It's already possible to use per-district themes to control building styles, so I wonder if it would be easier to detour rendering and modify based on district settings for where the road is located, rather than based on any other property of the road itself?

personally, I'd find this much more appealing anyway, since I could lay down roads more generically, and set the style for an entire district to something like 'chinatown' or 'gaslamp district' afterward, without cluttering up the road selection panels even more.

boformer commented 8 years ago

I developed NetworkSkins to do this: http://steamcommunity.com/sharedfiles/filedetails/?id=543722850

Road textures and meshes are still not implemented. Maybe you want to take a look at the code? https://github.com/boformer/NetworkSkins/tree/master/NetworkSkins