-
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
debug overlay #1698
Merged
Merged
debug overlay #1698
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
81515fa
debug overlay
kianzarrin 1746d66
debug overlay
kianzarrin bd7283c
8156d4a
merge
kianzarrin fa5e5ba
improve arrow
kianzarrin 4703ecf
fixed release build
kianzarrin a14556e
safe dict
kianzarrin c11f07a
Merge branch 'master' into Debug-overlay
kianzarrin 98cb78a
Merge branch 'master' into Debug-overlay
kianzarrin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
namespace TrafficManager.UI.Helpers; | ||
using ColossalFramework.Math; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
using System; | ||
using System.Diagnostics; | ||
using TrafficManager.Util; | ||
using System.Linq; | ||
|
||
internal static class DebugOverlay { | ||
public class ActionDict { | ||
private static Dictionary<int, Action> dict_ = new(); | ||
|
||
public Action this[int key] { | ||
get { | ||
lock (dict_) { | ||
return dict_[key]; | ||
} | ||
} | ||
set { | ||
lock (dict_) { | ||
dict_[key] = value; | ||
} | ||
} | ||
} | ||
|
||
public Action[] Values { | ||
get { | ||
lock (dict_) { | ||
return dict_.Values.ToArray(); | ||
} | ||
} | ||
} | ||
|
||
public bool Remove(int key) { | ||
lock (dict_) { | ||
return dict_.Remove(key); | ||
} | ||
} | ||
|
||
public void Clear() { | ||
lock (dict_) { | ||
dict_.Clear(); | ||
} | ||
} | ||
} | ||
|
||
private static RenderManager.CameraInfo cameraInfo_; | ||
|
||
/// <summary> | ||
/// key : id | ||
/// value : render action | ||
/// </summary> | ||
public static ActionDict Actions; | ||
|
||
#if DEBUG | ||
static DebugOverlay() => Actions = new(); | ||
#endif | ||
|
||
public static void RenderDebugOverlay(this Bezier3 bezier, Color color) { | ||
float y = bezier.a.y; | ||
RenderManager.instance.OverlayEffect.DrawBezier( | ||
cameraInfo: cameraInfo_, | ||
color: color, | ||
bezier: bezier, | ||
size: 1, | ||
cutStart: 0, | ||
cutEnd: 0, | ||
minY: y - 5, | ||
maxY: y + 5, | ||
renderLimits: true, | ||
alphaBlend: true); | ||
} | ||
|
||
public static void RenderDebugOverlay(this Bezier3 bezier, Color color, float makredOffset) { | ||
float y = bezier.a.y; | ||
RenderManager.instance.OverlayEffect.DrawBezier( | ||
cameraInfo: cameraInfo_, | ||
color: color, | ||
bezier: bezier, | ||
size: 1, | ||
cutStart: 0, | ||
cutEnd: 0, | ||
minY: y - 5, | ||
maxY: y + 5, | ||
renderLimits: true, | ||
alphaBlend: true); | ||
Vector3 pos = bezier.Position(makredOffset); | ||
pos.RenderDebugOverlay(color); | ||
} | ||
|
||
public static void RenderDebugOverlay(this Vector3 pos, Color color) { | ||
RenderManager.instance.OverlayEffect.DrawCircle( | ||
cameraInfo: cameraInfo_, | ||
color: color, | ||
center: pos, | ||
size: 2, | ||
minY: pos.y - 5, | ||
maxY: pos.y + 5, | ||
renderLimits: true, | ||
alphaBlend: true); | ||
} | ||
|
||
public static void RenderDebugArrowOverlay(this Segment3 segment, Color color) { | ||
// draw line | ||
float y = segment.a.y; | ||
RenderManager.instance.OverlayEffect.DrawSegment( | ||
cameraInfo: cameraInfo_, | ||
color: color, | ||
segment: segment, | ||
dashLen: 0, | ||
size: 1, | ||
minY: y - 5, | ||
maxY: y + 5, | ||
renderLimits: true, | ||
alphaBlend: true); | ||
|
||
// draw arrow head: | ||
Vector3 dir = (segment.b - segment.a).normalized; | ||
Vector3 dir90 = dir.RotateXZ90CW(); | ||
Vector3 center = segment.b; | ||
|
||
Quad3 quad = new Quad3 { | ||
a = center + dir90, | ||
b = center - dir90, | ||
c = center + 2 * dir, | ||
d = center + 2 * dir, | ||
}; | ||
|
||
RenderManager.instance.OverlayEffect.DrawQuad( | ||
cameraInfo_, | ||
color, | ||
quad, | ||
y - 5, | ||
y + 5, | ||
renderLimits: true, | ||
alphaBlend: true); | ||
} | ||
|
||
[Conditional("DEBUG")] | ||
public static void RenderOverlay(RenderManager.CameraInfo cameraInfo) { | ||
cameraInfo_ = cameraInfo; | ||
foreach (var action in Actions.Values) { | ||
krzychu124 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
action(); | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
we need to remove these because the overlay needs to clear if vehicle exits node.