RegEx, FindPickable & DrawShadows optimization
This commit is contained in:
@@ -487,7 +487,9 @@ namespace Subsurface
|
||||
return Info.Job.GetSkillLevel(skillName);
|
||||
}
|
||||
|
||||
public void Control(float deltaTime, Camera cam, bool forcePick = false)
|
||||
float findClosestTimer;
|
||||
|
||||
public void Control(float deltaTime, Camera cam)
|
||||
{
|
||||
if (isDead) return;
|
||||
|
||||
@@ -530,63 +532,6 @@ namespace Subsurface
|
||||
}
|
||||
}
|
||||
|
||||
//find the closest item if selectkey has been hit, or if the character is being
|
||||
//controlled by the player (in order to highlight it)
|
||||
if (controlled == this)
|
||||
{
|
||||
Vector2 mouseSimPos = ConvertUnits.ToSimUnits(cam.ScreenToWorld(PlayerInput.MousePosition));
|
||||
|
||||
closestCharacter = FindClosestCharacter(mouseSimPos);
|
||||
if (closestCharacter != null)
|
||||
{
|
||||
if (closestCharacter != selectedCharacter) selectedCharacter = null;
|
||||
if (!closestCharacter.isHumanoid) closestCharacter = null;
|
||||
}
|
||||
|
||||
|
||||
closestItem = FindClosestItem(mouseSimPos);
|
||||
|
||||
if (closestCharacter != null && closestItem != null)
|
||||
{
|
||||
if (Vector2.Distance(closestCharacter.SimPosition, mouseSimPos) < Vector2.Distance(closestItem.SimPosition, mouseSimPos))
|
||||
{
|
||||
if (selectedConstruction!=closestItem) closestItem = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
closestCharacter = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (selectedCharacter==null)
|
||||
{
|
||||
if (closestItem != null)
|
||||
{
|
||||
closestItem.IsHighlighted = true;
|
||||
if (GetInputState(InputType.Select) && closestItem.Pick(this, forcePick))
|
||||
{
|
||||
new NetworkEvent(NetworkEventType.PickItem, ID, true, closestItem.ID);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Vector2.Distance(selectedCharacter.SimPosition, SimPosition) > 2.0f) selectedCharacter = null;
|
||||
}
|
||||
|
||||
if (GetInputState(InputType.Select))
|
||||
{
|
||||
if (selectedCharacter!=null)
|
||||
{
|
||||
selectedCharacter = null;
|
||||
}
|
||||
else if (closestCharacter!=null && closestCharacter.isDead && closestCharacter.isHumanoid)
|
||||
{
|
||||
selectedCharacter = closestCharacter;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < selectedItems.Length; i++ )
|
||||
{
|
||||
if (selectedItems[i] == null) continue;
|
||||
@@ -616,7 +561,7 @@ namespace Subsurface
|
||||
Limb torso = AnimController.GetLimb(LimbType.Torso);
|
||||
Vector2 pos = (torso.body.TargetPosition != Vector2.Zero) ? torso.body.TargetPosition : torso.SimPosition;
|
||||
|
||||
return Item.FindPickable(pos, selectedConstruction == null ? mouseSimPos : selectedConstruction.SimPosition, null, selectedItems);
|
||||
return Item.FindPickable(pos, selectedConstruction == null ? mouseSimPos : selectedConstruction.SimPosition, AnimController.CurrentHull, selectedItems);
|
||||
}
|
||||
|
||||
private Character FindClosestCharacter(Vector2 mouseSimPos, float maxDist = 150.0f)
|
||||
@@ -647,7 +592,7 @@ namespace Subsurface
|
||||
/// <summary>
|
||||
/// Control the character according to player input
|
||||
/// </summary>
|
||||
public void ControlLocalPlayer(Camera cam, bool moveCam = true)
|
||||
public void ControlLocalPlayer(float deltaTime, Camera cam, bool moveCam = true)
|
||||
{
|
||||
//if (isDead)
|
||||
//{
|
||||
@@ -704,6 +649,69 @@ namespace Subsurface
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//find the closest item if selectkey has been hit, or if the character is being
|
||||
//controlled by the player (in order to highlight it)
|
||||
|
||||
if (findClosestTimer <= 0.0f || Screen.Selected == GameMain.EditMapScreen)
|
||||
{
|
||||
closestCharacter = FindClosestCharacter(mouseSimPos);
|
||||
if (closestCharacter != null)
|
||||
{
|
||||
if (closestCharacter != selectedCharacter) selectedCharacter = null;
|
||||
if (!closestCharacter.isHumanoid) closestCharacter = null;
|
||||
}
|
||||
|
||||
closestItem = FindClosestItem(mouseSimPos);
|
||||
|
||||
if (closestCharacter != null && closestItem != null)
|
||||
{
|
||||
if (Vector2.Distance(closestCharacter.SimPosition, mouseSimPos) < Vector2.Distance(closestItem.SimPosition, mouseSimPos))
|
||||
{
|
||||
if (selectedConstruction != closestItem) closestItem = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
closestCharacter = null;
|
||||
}
|
||||
}
|
||||
|
||||
findClosestTimer = 0.1f;
|
||||
}
|
||||
else
|
||||
{
|
||||
findClosestTimer -= deltaTime;
|
||||
}
|
||||
|
||||
if (selectedCharacter == null)
|
||||
{
|
||||
if (closestItem != null)
|
||||
{
|
||||
closestItem.IsHighlighted = true;
|
||||
if (GetInputState(InputType.Select) && closestItem.Pick(this, false))
|
||||
{
|
||||
new NetworkEvent(NetworkEventType.PickItem, ID, true, closestItem.ID);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Vector2.Distance(selectedCharacter.SimPosition, SimPosition) > 2.0f) selectedCharacter = null;
|
||||
}
|
||||
|
||||
if (GetInputState(InputType.Select))
|
||||
{
|
||||
if (selectedCharacter != null)
|
||||
{
|
||||
selectedCharacter = null;
|
||||
}
|
||||
else if (closestCharacter != null && closestCharacter.isDead && closestCharacter.isHumanoid)
|
||||
{
|
||||
selectedCharacter = closestCharacter;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
DisableControls = false;
|
||||
}
|
||||
|
||||
@@ -744,7 +752,7 @@ namespace Subsurface
|
||||
if (controlled == this)
|
||||
{
|
||||
CharacterHUD.Update(deltaTime,this);
|
||||
ControlLocalPlayer(cam);
|
||||
ControlLocalPlayer(deltaTime, cam);
|
||||
}
|
||||
|
||||
Control(deltaTime, cam);
|
||||
|
||||
@@ -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>();
|
||||
|
||||
@@ -111,7 +111,7 @@ namespace Subsurface.Lights
|
||||
}
|
||||
}
|
||||
|
||||
public void DrawShadows(GraphicsDevice graphicsDevice, Camera cam, Vector2 lightSourcePos, bool los = true)
|
||||
public void DrawShadows(GraphicsDevice graphicsDevice, Camera cam, Vector2 lightSourcePos, Matrix transform, bool los = true)
|
||||
{
|
||||
if (!Enabled) return;
|
||||
|
||||
@@ -224,8 +224,7 @@ namespace Subsurface.Lights
|
||||
currentIndex = (currentIndex + 1) % primitiveCount;
|
||||
}
|
||||
|
||||
shadowEffect.World = cam.ShaderTransform
|
||||
* Matrix.CreateOrthographic(GameMain.GraphicsWidth, GameMain.GraphicsHeight, -1, 1) * 0.5f;
|
||||
shadowEffect.World = transform;
|
||||
shadowEffect.CurrentTechnique.Passes[0].Apply();
|
||||
|
||||
graphicsDevice.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.TriangleStrip, shadowVertices, 0, shadowVertexCount * 2 - 2);
|
||||
|
||||
@@ -59,18 +59,24 @@ namespace Subsurface.Lights
|
||||
{
|
||||
Rectangle camView = new Rectangle(cam.WorldView.X, cam.WorldView.Y - cam.WorldView.Height, cam.WorldView.Width, cam.WorldView.Height);
|
||||
|
||||
Matrix shadowTransform = cam.ShaderTransform
|
||||
* Matrix.CreateOrthographic(GameMain.GraphicsWidth, GameMain.GraphicsHeight, -1, 1) * 0.5f;
|
||||
|
||||
if (!LosEnabled) return;
|
||||
foreach (ConvexHull convexHull in ConvexHull.list)
|
||||
{
|
||||
if (!camView.Intersects(convexHull.BoundingBox)) continue;
|
||||
|
||||
convexHull.DrawShadows(graphics, cam, pos);
|
||||
convexHull.DrawShadows(graphics, cam, pos, shadowTransform);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void DrawLightmap(GraphicsDevice graphics, SpriteBatch spriteBatch, Camera cam)
|
||||
{
|
||||
Matrix shadowTransform = cam.ShaderTransform
|
||||
* Matrix.CreateOrthographic(GameMain.GraphicsWidth, GameMain.GraphicsHeight, -1, 1) * 0.5f;
|
||||
|
||||
graphics.SetRenderTarget(lightMap);
|
||||
|
||||
Rectangle viewRect = cam.WorldView;
|
||||
@@ -96,7 +102,7 @@ namespace Subsurface.Lights
|
||||
{
|
||||
if (!MathUtils.CircleIntersectsRectangle(light.Position, light.Range, ch.BoundingBox)) continue;
|
||||
//draw shadow
|
||||
ch.DrawShadows(graphics, cam, light.Position, false);
|
||||
ch.DrawShadows(graphics, cam, light.Position, shadowTransform, false);
|
||||
}
|
||||
|
||||
//draw the light shape
|
||||
|
||||
@@ -225,7 +225,7 @@ namespace Subsurface
|
||||
}
|
||||
}
|
||||
|
||||
dummyCharacter.ControlLocalPlayer(cam, false);
|
||||
dummyCharacter.ControlLocalPlayer((float)deltaTime, cam);
|
||||
dummyCharacter.Control((float)deltaTime, cam);
|
||||
}
|
||||
else
|
||||
@@ -287,6 +287,8 @@ namespace Subsurface
|
||||
{
|
||||
if (dummyCharacter != null)
|
||||
{
|
||||
dummyCharacter.AnimController.FindHull();
|
||||
|
||||
foreach (Item item in dummyCharacter.SelectedItems)
|
||||
{
|
||||
if (item == null) continue;
|
||||
@@ -311,10 +313,6 @@ namespace Subsurface
|
||||
|
||||
if (PlayerInput.GetMouseState.LeftButton != ButtonState.Pressed)
|
||||
{
|
||||
//if (Inventory.draggingItem!=null)
|
||||
//{
|
||||
// Inventory.draggingItem.see
|
||||
//}
|
||||
Inventory.draggingItem = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -396,4 +396,7 @@ Global
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(Performance) = preSolution
|
||||
HasPerformanceSessions = true
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user