Server list, lighting/los optimization
This commit is contained in:
@@ -17,27 +17,44 @@ namespace Subsurface.Lights
|
||||
|
||||
bool[] backFacing;
|
||||
VertexPositionColor[] shadowVertices;
|
||||
|
||||
private Rectangle boundingBox;
|
||||
|
||||
public bool Enabled
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
|
||||
public Rectangle BoundingBox
|
||||
{
|
||||
get { return boundingBox; }
|
||||
}
|
||||
|
||||
public ConvexHull(Vector2[] points, Color color)
|
||||
{
|
||||
int vertexCount = points.Length;
|
||||
vertices = new VertexPositionColor[vertexCount + 1];
|
||||
Vector2 center = Vector2.Zero;
|
||||
|
||||
float? minX = null, minY = null, maxX = null, maxY = null;
|
||||
|
||||
for (int i = 0; i < vertexCount; i++)
|
||||
{
|
||||
vertices[i] = new VertexPositionColor(new Vector3(points[i], 0), color);
|
||||
center += points[i];
|
||||
|
||||
if (minX == null || points[i].X < minX) minX = points[i].X;
|
||||
if (minY == null || points[i].Y < minY) minY = points[i].Y;
|
||||
|
||||
if (maxX == null || points[i].X > maxX) maxX = points[i].X;
|
||||
if (maxY == null || points[i].Y > minY) maxY = points[i].Y;
|
||||
}
|
||||
center /= points.Length;
|
||||
vertices[vertexCount] = new VertexPositionColor(new Vector3(center, 0), color);
|
||||
|
||||
boundingBox = new Rectangle((int)minX, (int)minY, (int)(maxX-minX), (int)(maxY-minY));
|
||||
|
||||
primitiveCount = points.Length;
|
||||
indices = new short[primitiveCount * 3];
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Subsurface.Lights
|
||||
{
|
||||
@@ -56,15 +57,28 @@ namespace Subsurface.Lights
|
||||
|
||||
public void DrawLOS(GraphicsDevice graphics, Camera cam, Vector2 pos)
|
||||
{
|
||||
Stopwatch sw = new Stopwatch();
|
||||
sw.Start();
|
||||
|
||||
Rectangle camView = new Rectangle(cam.WorldView.X, cam.WorldView.Y - cam.WorldView.Height, cam.WorldView.Width, cam.WorldView.Height);
|
||||
|
||||
if (!LosEnabled) return;
|
||||
foreach (ConvexHull convexHull in ConvexHull.list)
|
||||
{
|
||||
if (!camView.Intersects(convexHull.BoundingBox)) continue;
|
||||
|
||||
convexHull.DrawShadows(graphics, cam, pos);
|
||||
}
|
||||
|
||||
long elapsed = sw.ElapsedTicks;
|
||||
Debug.WriteLine("los: "+elapsed);
|
||||
}
|
||||
|
||||
public void DrawLightmap(GraphicsDevice graphics, SpriteBatch spriteBatch, Camera cam)
|
||||
{
|
||||
Stopwatch sw = new Stopwatch();
|
||||
sw.Start();
|
||||
|
||||
graphics.SetRenderTarget(lightMap);
|
||||
|
||||
Rectangle viewRect = cam.WorldView;
|
||||
@@ -88,6 +102,7 @@ namespace Subsurface.Lights
|
||||
|
||||
foreach (ConvexHull ch in ConvexHull.list)
|
||||
{
|
||||
if (!MathUtils.CircleIntersectsRectangle(light.Position, light.Range, ch.BoundingBox)) continue;
|
||||
//draw shadow
|
||||
ch.DrawShadows(graphics, cam, light.Position, false);
|
||||
}
|
||||
@@ -101,6 +116,10 @@ namespace Subsurface.Lights
|
||||
//clear alpha, to avoid messing stuff up later
|
||||
ClearAlphaToOne(graphics, spriteBatch);
|
||||
graphics.SetRenderTarget(null);
|
||||
|
||||
|
||||
long elapsed = sw.ElapsedTicks;
|
||||
Debug.WriteLine("lights: " + elapsed);
|
||||
}
|
||||
|
||||
private void ClearAlphaToOne(GraphicsDevice graphics, SpriteBatch spriteBatch)
|
||||
|
||||
Reference in New Issue
Block a user