-
Notifications
You must be signed in to change notification settings - Fork 85
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
Timed traffic lights is a mess and needs house keeping. #967
Comments
@kvakvs are you planning to fix this code as part of your TTL uplift? |
this blocks #959 |
This may happen after i am done with speed limits UI, which is in progress right now. |
Is there any progress? |
No |
Does anyone want to fix it? |
Yes, me. Eventually, after the previous task is done. |
It is blocked by this task. |
Please add this to the 11.6.0 milestone. |
@kvakvs Please it now. |
This is also hindering progress in #278 ... |
Well, I guess it's time I joined the party here. I have begun work on enhancing timed traffic lights to group lanes according to more properties than just vehicle type. The specific objective is to support flags related to lane displacement, #1392 (the issue is out-of-date as compared to the current development plan). I initially planned to keep the API changes as isolated as possible and maintain backward compatibility. However, after examining the code and its history, and discussing it with @krzychu124, I have concluded that the current code has what I would call a false API. This "API" is really just a complete exposure of the internal implementation to the outside world. It is evident that the interfaces were never meant to be used that way. The original purpose of the interfaces is unclear. Maybe someone had unit testing in mind, but they really don't help with that. You can't just slap an interface on something and call it testable. There are design methodologies that need to be followed. As it stands now, these interfaces just create an added layer of complexity that contributes to what @kianzarrin was saying:
My proposal is that we completely remove these interfaces, while leaving the underlying implementation intact. @krzychu124 is adamant that the traffic light API has no users at this time. This is the right time to get rid of the mess, while we still can. It will allow us to focus on the implementation without having to worry about an untenable API layer. We can take a minimalist approach to rebuilding the API as use cases are identified. I have a branch which does just that. It completely removes the https://github.com/Elesbaan70/TMPE/tree/delete-false-api Comments? |
Big rewrites only possible and successful if you 100% clearly understand the current code and have a new plan and uninterrupted attention for the entire duration. If for any reason you're not able to 100% fully commit your attention to this, then you should go gradually removing small things and replacing with new small things, while checking that the code isn't broken beyond repair on each step of your work. For now i'd be carefully sceptical about any full rewrite of anything. |
You mean, code users, right? I use it much (not very much, but much) in my cities. I do confess I spend too much time with them... |
Hey guys, If you guys like I am happy to assist in rewriting and cleaning out the code. You guys know me as snowflitzer and I am good friend of LemonG Please let me know |
Fork on Github, check out source, build it and experiment with it, create a branch with your changes (make sure the changes are short and easy to review and the intent for the changes is clear), and create a pull request when done. https://github.com/CitiesSkylinesMods/TMPE/wiki/Contributing |
15 years in C# and about 40 years programming (30 professionally). Looks like we have a powerhouse here? :D @snowflitzer we could probably collaborate. |
@kvakvs This is true, of course. Explaining my plan a little more thoroughly might help. On the point of uninterrupted attention, I don't think any of us are being paid for this, so "uninterrupted" is relative. I do have a day job, but it's not in software and is not mentally demanding, so this is as uninterrupted as it gets unless someone tells us they're retired and doing this full time. ;-) I could rewrite this, but that's not what I'm doing. I am doing work to make it easier to revise what is already there. My plan is to leave the existing structure and logic completely intact. If you look at the single commit that I've made in my Why would I do this? Because the interfaces are not serving any of the purposes interfaces normally serve, and they are in the way. Removing interfaces is certainly unusual, but consider this:
This was my original plan. Unfortunately, this isn't really possible because all the traffic light classes are so tightly coupled. Every class goes in and plays with the internal implementation of every other class, so anything you do has a cascading effect across the whole thing. This is a weird situation because well-designed interfaces are supposed to keep this from happening. But because of their design, they have the opposite effect. Strange as it is, removing them makes future work simpler. (A quick note: When I committed these changes, I had not yet done a detailed line-by-line review. When I did this, I discovered that Visual Studio had done some automatic refactoring that I did not expect, removing extraneous parentheses from some mathematical expressions. None of these represent functional changes, but it's still a mystery to me why VS would do this. I'm considering rolling all of these back, but I'm afraid that might be more error-prone than just leaving them.) |
@brunoais Do you just mean that you use TMPE in your cities? Or do you mean that you've written code that relies on traffic light types in If the latter, then any significant change will impact you because the current "API" design is untenable. But the work I have done makes no logic changes and negligible structural changes, so it would be very easy to account for on your end. Your needs could also provide a use case to study when designing a new API. |
I use custom semaphores in my city and I don't use the API. I'm not a code user but I am a feature user (as a player) |
Gotcha. No breaking changes are planned, functionally. That's not how I roll. ;-) Even breaking the API would only be acceptable based on its extreme unviability combined with the belief/assumption that no one is actually using it. |
IMO we should just rewrite TTL in a way that makes sense, with no regards to backwards compatibility or API.... And only once that's done, then try and find a way to convert old data/api to the new format. I don't expect many mods will be using TTL API - maybe Adaptive Networks? |
I'm actually a future consumer of the API, but I won't be doing anything with it for a while (probably months before I'm even to that point in development), and I'd rather have something stable that doesn't expose TMPE's innards. I will only need the ability to request traffic light state by lane, and to be notified when the state changes. This should be simple calls to a manager, not a deep dive into TTL's object model. |
There are many untracked TODOs in TTL code explaining what a mess the code is. there are too many to list here but some of them are:
TMPE/TLM/TLM/TrafficLight/Impl/TimedTrafficLightsStep.cs
Line 17 in 7b7bc45
TMPE/TLM/TLM/TrafficLight/Impl/TimedTrafficLightsStep.cs
Line 483 in 7b7bc45
TMPE/TLM/TLM/TrafficLight/Impl/TimedTrafficLightsStep.cs
Line 790 in 7b7bc45
TMPE/TLM/TLM/TrafficLight/Impl/TimedTrafficLightsStep.cs
Line 1357 in 7b7bc45
TMPE/TLM/TLM/TrafficLight/Impl/TimedTrafficLights.cs
Line 332 in a7ccdfc
TMPE/TLM/TLM/Manager/Impl/TrafficLightSimulationManager.cs
Line 556 in a7ccdfc
TMPE/TLM/TLM/TrafficLight/Impl/CustomSegmentLights.cs
Line 69 in a7ccdfc
in each of the files above search for TODO to get a more complete list.
messy code prevents future progress. In particular, as part of #959 I want to take a snapshot of timed traffic lights without causing too much future deserialization challenges.
EDIT: TTL should also invoke the notifier.
The text was updated successfully, but these errors were encountered: