RegEx, FindPickable & DrawShadows optimization
This commit is contained in:
@@ -10,6 +10,11 @@ namespace Subsurface.Items.Components
|
||||
private string expression;
|
||||
|
||||
private string receivedSignal;
|
||||
private string previousReceivedSignal;
|
||||
|
||||
bool previousResult;
|
||||
|
||||
private Regex regex;
|
||||
|
||||
[InGameEditable, HasDefaultValue("1", true)]
|
||||
public string Output
|
||||
@@ -22,7 +27,22 @@ namespace Subsurface.Items.Components
|
||||
public string Expression
|
||||
{
|
||||
get { return expression; }
|
||||
set { expression = value; }
|
||||
set
|
||||
{
|
||||
if (expression == value) return;
|
||||
expression = value;
|
||||
|
||||
try
|
||||
{
|
||||
regex = new Regex(@expression);
|
||||
}
|
||||
|
||||
catch
|
||||
{
|
||||
item.SendSignal("ERROR", "signal_out");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public RegExFindComponent(Item item, XElement element)
|
||||
@@ -33,22 +53,26 @@ namespace Subsurface.Items.Components
|
||||
|
||||
public override void Update(float deltaTime, Camera cam)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(expression)) return;
|
||||
if (string.IsNullOrWhiteSpace(expression) || regex==null) return;
|
||||
|
||||
bool success = false;
|
||||
try
|
||||
if (receivedSignal!=previousReceivedSignal)
|
||||
{
|
||||
Regex regex = new Regex(@expression);
|
||||
Match match = regex.Match(receivedSignal);
|
||||
success = match.Success;
|
||||
}
|
||||
catch
|
||||
{
|
||||
item.SendSignal("ERROR", "signal_out");
|
||||
return;
|
||||
try
|
||||
{
|
||||
Match match = regex.Match(receivedSignal);
|
||||
previousResult = match.Success;
|
||||
|
||||
}
|
||||
catch
|
||||
{
|
||||
item.SendSignal("ERROR", "signal_out");
|
||||
previousResult = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
item.SendSignal(success ? output : "0", "signal_out");
|
||||
|
||||
item.SendSignal(previousResult ? output : "0", "signal_out");
|
||||
}
|
||||
|
||||
public override void ReceiveSignal(string signal, Connection connection, Item sender, float power = 0.0f)
|
||||
@@ -57,7 +81,6 @@ namespace Subsurface.Items.Components
|
||||
{
|
||||
case "signal_in":
|
||||
receivedSignal = signal;
|
||||
|
||||
break;
|
||||
case "set_output":
|
||||
output = signal;
|
||||
|
||||
@@ -326,11 +326,7 @@ namespace Subsurface
|
||||
|
||||
public void SetTransform(Vector2 simPosition, float rotation)
|
||||
{
|
||||
if (body != null)
|
||||
{
|
||||
body.SetTransform(simPosition, rotation);
|
||||
}
|
||||
|
||||
if (body != null) body.SetTransform(simPosition, rotation);
|
||||
|
||||
Vector2 displayPos = ConvertUnits.ToDisplayUnits(simPosition);
|
||||
|
||||
@@ -770,7 +766,7 @@ namespace Subsurface
|
||||
foreach (Item item in itemList)
|
||||
{
|
||||
if (ignoredItems!=null && ignoredItems.Contains(item)) continue;
|
||||
if (hull != null && item.CurrentHull != hull) continue;
|
||||
if (hull != item.CurrentHull) continue;
|
||||
if (item.body != null && !item.body.Enabled) continue;
|
||||
|
||||
Pickable pickableComponent = item.GetComponent<Pickable>();
|
||||
|
||||
Reference in New Issue
Block a user