Skip to content
This repository has been archived by the owner on Feb 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #180 from Henry00IS/DebugMode
Browse files Browse the repository at this point in the history
Added SABRE_CSG_DEBUG mode to prevent performance regressions.
  • Loading branch information
Henry00IS committed Nov 4, 2018
2 parents c3031aa + d5a718e commit 5ea9eca
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
15 changes: 10 additions & 5 deletions Scripts/Core/CSG/Edge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@ public Vector3 CenterPoint
/// </exception>
public Edge(Vertex vertex1, Vertex vertex2)
{
#if SABRE_CSG_DEBUG
if (vertex1 == null) throw new ArgumentNullException("vertex1");
if (vertex2 == null) throw new ArgumentNullException("vertex2");

#endif
this.vertex1 = vertex1;
this.vertex2 = vertex2;
}
Expand All @@ -93,8 +94,9 @@ public Edge(Vertex vertex1, Vertex vertex2)
/// </exception>
public bool Matches(Edge other)
{
#if SABRE_CSG_DEBUG
if (other == null) throw new ArgumentNullException("other");

#endif
// check whether we approximately match the other edge:
if (vertex1.Position.EqualsWithEpsilon(other.vertex1.Position)
&& vertex2.Position.EqualsWithEpsilon(other.Vertex2.Position))
Expand All @@ -121,8 +123,9 @@ public bool Matches(Edge other)
/// </exception>
public bool Parallel(Edge other)
{
#if SABRE_CSG_DEBUG
if (other == null) throw new ArgumentNullException("other");

#endif
Vector3 direction1 = vertex2.Position - vertex1.Position;
Vector3 direction2 = other.Vertex2.Position - other.Vertex1.Position;

Expand All @@ -145,8 +148,9 @@ public bool Parallel(Edge other)
/// </exception>
public bool Intersects(Edge other)
{
#if SABRE_CSG_DEBUG
if (other == null) throw new ArgumentNullException("other");

#endif
// early out: if the edges aren't parallel to each other, they can't be collinear.
if (!Parallel(other))
return false;
Expand Down Expand Up @@ -208,8 +212,9 @@ public bool Intersects(Edge other)
/// </exception>
public bool Collinear(Edge other)
{
#if SABRE_CSG_DEBUG
if (other == null) throw new ArgumentNullException("other");

#endif
return EdgeUtility.EdgeMatches(this, other);
}

Expand Down
3 changes: 2 additions & 1 deletion Scripts/Core/CSG/Vertex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,10 @@ public void FlipNormal()
/// </exception>
public static Vertex Lerp(Vertex a, Vertex b, float t)
{
#if SABRE_CSG_DEBUG
if (a == null) throw new ArgumentNullException("a");
if (b == null) throw new ArgumentNullException("b");

#endif
return new Vertex()
{
Position = Vector3.Lerp(a.Position, b.Position, t),
Expand Down
31 changes: 30 additions & 1 deletion Scripts/UI/SabreCSGPreferences.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ namespace Sabresaurus.SabreCSG
public class SabreCSGPreferences : EditorWindow
{
private const string RUNTIME_CSG_DEFINE = "RUNTIME_CSG";
private static readonly Vector2 WINDOW_SIZE = new Vector2(370, 360);
private const string SABRE_CSG_DEBUG_DEFINE = "SABRE_CSG_DEBUG";
private static readonly Vector2 WINDOW_SIZE = new Vector2(370, 400);

//private static Event cachedEvent;

Expand Down Expand Up @@ -151,6 +152,34 @@ public static void PreferencesGUI()
}
}

GUILayout.Space(20);
GUILayout.Label("Debug mode executes additional code for verbose error checking. Used by SabreCSG developers.", style);
buildTargetGroup = EditorUserBuildSettings.selectedBuildTargetGroup;
defines = PlayerSettings.GetScriptingDefineSymbolsForGroup(buildTargetGroup);
definesSplit = defines.Split(';').ToList();
enabled = definesSplit.Contains(SABRE_CSG_DEBUG_DEFINE);
if (enabled)
{
if (GUILayout.Button("Disable Debug Mode (Recommended)"))
{
definesSplit.Remove(SABRE_CSG_DEBUG_DEFINE);
defines = string.Join(";", definesSplit.ToArray());
PlayerSettings.SetScriptingDefineSymbolsForGroup(buildTargetGroup, defines);
}
}
else
{
if (GUILayout.Button("Enable Debug Mode (Not Recommended)"))
{
if (!definesSplit.Contains(SABRE_CSG_DEBUG_DEFINE))
{
definesSplit.Add(SABRE_CSG_DEBUG_DEFINE);
}
defines = string.Join(";", definesSplit.ToArray());
PlayerSettings.SetScriptingDefineSymbolsForGroup(buildTargetGroup, defines);
}
}

GUILayout.FlexibleSpace();

GUILayout.Label("SabreCSG Version " + CSGModel.VERSION_STRING, SabreGUILayout.GetForeStyle());
Expand Down

0 comments on commit 5ea9eca

Please sign in to comment.