Work in progress

This commit is contained in:
Silver
2015-12-12 19:43:04 -07:00
parent 55fc105a49
commit 882825599d
16 changed files with 757 additions and 596 deletions
+1
View File
@@ -0,0 +1 @@
{ q_!5̦ 
+21
View File
@@ -0,0 +1,21 @@
# IgnoreList is a UTF-8 encoded .txt file that helps you specify single files, paths and rules
# for ignoring during the synchronization job. It supports "?" and "*" wildcard symbols.
#
#
# OS generated files #
.DS_Store
.Spotlight-V100
.Trashes
ehthumbs.db
desktop.ini
Thumbs.db
# Temporary files #
~*
*~
.~lock.*
*.part
*.crdownload
@eaDir
@SynoResource
.@__thumb
._*
+7
View File
@@ -0,0 +1,7 @@
# StreamsList is a UTF-8 encoded .txt file that helps you specify alternate streams,
# xattrs and resource forks white list. It supports "?" and "*" wildcard symbols.
#
#
com.apple.metadata:_kMDItemUserTags
com.apple.ResourceFork
com.apple.metadata:kMDItemFinderComment
+190 -183
View File
@@ -1,12 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Color = SFML.Graphics.Color;
using SFML.Graphics;
using BaseSprite = SFML.Graphics.Sprite;
using Image = SFML.Graphics.Image;
using SFML.Graphics;
using SFML.System;
using SS14.Shared.Maths;
using System;
using System.Collections.Generic;
using System.Diagnostics;
namespace SS14.Client.Graphics.Sprite
@@ -14,238 +10,249 @@ namespace SS14.Client.Graphics.Sprite
/// <summary>
/// Provides optimized drawing of sprites
/// </summary>
public class SpriteBatch : Drawable,IDisposable
{
private class QueueItem
{
public Texture Texture;
public VertexArray vertices;
public QueueItem(Texture tex) {
Texture=tex;
vertices=new VertexArray(PrimitiveType.Quads);
}
}
bool disposed = false;
private QueueItem activeTexture;
private List<QueueItem> textures = new List<QueueItem>();
private Queue<QueueItem> recycle = new Queue<QueueItem>();
[DebuggerDisplay("[SpriteBatch] IsDrawing: {Drawing} | ")]
public class SpriteBatch : Drawable
{
private QueueItem activeItem;
private List<QueueItem> QueuedTextures = new List<QueueItem>();
private Queue<QueueItem> RecycleQueue = new Queue<QueueItem>();
private readonly uint Max;
private int count;
private bool Drawing;
private uint queueCount;
public int Count
{
get { return count; }
}
private int count;
private bool active;
private uint queueCount;
public void Begin()
public BlendMode BlendingSettings;
public SpriteBatch(uint maxCapacity = 100000)
{
if (active) throw new Exception("Already active");
Max = maxCapacity * 4;
BlendingSettings = new BlendMode();
}
public void BeginDrawing()
{
count = 0;
// we use these a lot, and the overall number of textures
// remains stable, so recycle them to avoid excess calls into
// the native constructor.
foreach(var tex in textures)
foreach (var Entry in QueuedTextures)
{
tex.vertices.Clear();
tex.Texture=null;
recycle.Enqueue(tex);
Entry.Verticies.Clear();
Entry.Texture = null;
RecycleQueue.Enqueue(Entry);
}
textures.Clear();
active = true;
activeTexture = null;
QueuedTextures.Clear();
Drawing = true;
activeItem = null;
}
public void End()
{
if (!active) throw new Exception("Call end first.");
active = false;
public void EndDrawing()
{
Drawing = false;
}
private void Using(Texture texture)
private void Using(string name , Texture texture)
{
if (!active) throw new Exception("Call Begin first.");
if (!Drawing)
throw new Exception("Call Begin first.");
if (activeTexture==null || activeTexture.Texture != texture) {
if (recycle.Count > 0) {
activeTexture=recycle.Dequeue();
activeTexture.Texture=texture;
} else
activeTexture=new QueueItem(texture);
textures.Add(activeTexture);
if (activeItem == null || activeItem.Texture != texture)
{
if (RecycleQueue.Count > 0)
{
activeItem = RecycleQueue.Dequeue();
activeItem.Texture = texture;
}
else
{
activeItem = new QueueItem(name,texture);
}
QueuedTextures.Add(activeItem);
}
}
public void Draw(IEnumerable<BaseSprite> sprites)
public void Draw(IEnumerable<CluwneSprite> sprites)
{
foreach (var s in sprites)
Draw(s);
}
public void Draw(BaseSprite sprite)
{
Draw(sprite.Texture, sprite.Position, sprite.TextureRect, sprite.Color, sprite.Scale, sprite.Origin,
sprite.Rotation);
}
public void Draw(Texture texture, Vector2f position, IntRect rec, Color color, Vector2f scale,
Vector2f origin, float rotation = 0)
public void Draw(CluwneSprite S)
{
count++;
Using(texture);
Using(S.Key,S.Texture);
Vector2 Scale = new Vector2();
float sin = 0, cos = 1;
//FloatMath.SinCos(rotation, out sin, out cos);
if (true)
{
rotation = rotation / 180 * (float)Math.PI;
sin = (float)Math.Sin(rotation);
cos = (float)Math.Cos(rotation);
S.Rotation = S.Rotation / 180 * (float)Math.PI;
sin = (float)Math.Sin(S.Rotation);
cos = (float)Math.Cos(S.Rotation);
}
var pX = -origin.X * scale.X;
var pY = -origin.Y * scale.Y;
scale.X *= rec.Width;
scale.Y *= rec.Height;
var pX = -S.Origin.X * S.Scale.X;
var pY = -S.Origin.Y * S.Scale.Y;
Scale.X *= S.TextureRect.Width;
Scale.Y *= S.TextureRect.Height;
activeTexture.vertices.Append(
activeItem.Verticies.Append
(
new Vertex(
new Vector2f(
pX * cos - pY * sin + S.Position.X,
pX * sin + pY * cos + S.Position.Y),
S.SFMLColor,
new Vector2f(
S.TextureRect.Left,
S.TextureRect.Top)
)
);
pX += Scale.X;
activeItem.Verticies.Append
(
new Vertex(
new Vector2f(pX * cos - pY * sin + position.X,
pX * sin + pY * cos + position.Y),
color,
new Vector2f(rec.Left, rec.Top)));
new Vector2f(
pX * cos - pY * sin + S.Position.X,
pX * sin + pY * cos + S.Position.Y),
S.SFMLColor,
new Vector2f(
S.TextureRect.Left + S.TextureRect.Width,
S.TextureRect.Top)
)
);
pX += scale.X;
activeTexture.vertices.Append(
pY += Scale.Y;
activeItem.Verticies.Append
(
new Vertex(
new Vector2f(pX * cos - pY * sin + position.X,
pX * sin + pY * cos + position.Y),
color,
new Vector2f(rec.Left + rec.Width, rec.Top)));
new Vector2f(
pX * cos - pY * sin + S.Position.X,
pX * sin + pY * cos + S.Position.Y),
S.SFMLColor,
new Vector2f(
S.TextureRect.Left + S.TextureRect.Width,
S.TextureRect.Top + S.TextureRect.Height)
)
);
pY += scale.Y;
activeTexture.vertices.Append(
pX -= Scale.X;
activeItem.Verticies.Append(
new Vertex(
new Vector2f(pX * cos - pY * sin + position.X,
pX * sin + pY * cos + position.Y),
color,
new Vector2f(rec.Left+rec.Width, rec.Top+rec.Height)));
pX -= scale.X;
activeTexture.vertices.Append(
new Vertex(
new Vector2f(pX * cos - pY * sin + position.X,
pX * sin + pY * cos + position.Y),
color,
new Vector2f(rec.Left, rec.Top+rec.Height)));
}
/*
public unsafe void Draw(Texture texture, FloatRect rec, IntRect src, Color color)
{
var index = Create(texture);
fixed (Vertex* fptr = vertices)
{
var ptr = fptr + index;
ptr->Position.X = rec.Left;
ptr->Position.Y = rec.Top;
ptr->TexCoords.X = src.Left;
ptr->TexCoords.Y = src.Top;
ptr->Color = color;
ptr++;
ptr->Position.X = rec.Left + rec.Width;
ptr->Position.Y = rec.Top;
ptr->TexCoords.X = src.Left + src.Width;
ptr->TexCoords.Y = src.Top;
ptr->Color = color;
ptr++;
ptr->Position.X = rec.Left + rec.Width;
ptr->Position.Y = rec.Top + rec.Height;
ptr->TexCoords.X = src.Left + src.Width;
ptr->TexCoords.Y = src.Top + src.Height;
ptr->Color = color;
ptr++;
ptr->Position.X = rec.Left;
ptr->Position.Y = rec.Top + rec.Height;
ptr->TexCoords.X = src.Left;
ptr->TexCoords.Y = src.Top + src.Height;
ptr->Color = color;
}
new Vector2f(
pX * cos - pY * sin + S.Position.X,
pX * sin + pY * cos + S.Position.Y),
S.SFMLColor,
new Vector2f(
S.TextureRect.Left,
S.TextureRect.Top + S.TextureRect.Height)
)
);
}
public void Draw(Texture texture, FloatRect rec, Color color)
{
int width = 1, height = 1;
if (texture != null)
{
width = (int)texture.Size.X;
height = (int)texture.Size.Y;
}
Draw(texture, rec, new IntRect(0, 0, width, height), color);
}
/*
public unsafe void Draw(Texture texture, FloatRect rec, IntRect src, Color color)
{
var index = Create(texture);
public void Draw(Texture texture, Vector2f pos, Color color)
{
if (texture == null) throw new ArgumentNullException();
var width = (int)texture.Size.X;
var height = (int)texture.Size.Y;
Draw(texture, new FloatRect(pos.X, pos.Y, width, height), new IntRect(0, 0, width, height), color);
}
fixed (Vertex* fptr = vertices)
{
var ptr = fptr + index;
*/
public void Draw(RenderTarget target, RenderStates states)
{
if (active) throw new Exception("Call End first.");
ptr->Position.X = rec.Left;
ptr->Position.Y = rec.Top;
ptr->TexCoords.X = src.Left;
ptr->TexCoords.Y = src.Top;
ptr->Color = color;
ptr++;
foreach (var item in textures)
{
Debug.Assert(item.vertices.VertexCount > 0);
states.Texture = item.Texture;
ptr->Position.X = rec.Left + rec.Width;
ptr->Position.Y = rec.Top;
ptr->TexCoords.X = src.Left + src.Width;
ptr->TexCoords.Y = src.Top;
ptr->Color = color;
ptr++;
//item.vertices.Draw(target,states);
ptr->Position.X = rec.Left + rec.Width;
ptr->Position.Y = rec.Top + rec.Height;
ptr->TexCoords.X = src.Left + src.Width;
ptr->TexCoords.Y = src.Top + src.Height;
ptr->Color = color;
ptr++;
if (CluwneLib.Debug.RenderingDelay > 0) {
CluwneLib.Screen.Display();
System.Threading.Thread.Sleep(CluwneLib.Debug.RenderingDelay);
ptr->Position.X = rec.Left;
ptr->Position.Y = rec.Top + rec.Height;
ptr->TexCoords.X = src.Left;
ptr->TexCoords.Y = src.Top + src.Height;
ptr->Color = color;
}
}
public void Draw(Texture texture, FloatRect rec, Color color)
{
int width = 1, height = 1;
if (texture != null)
{
width = (int)texture.Size.X;
height = (int)texture.Size.Y;
}
Draw(texture, rec, new IntRect(0, 0, width, height), color);
}
public void Draw(Texture texture, Vector2f pos, Color color)
{
if (texture == null) throw new ArgumentNullException();
var width = (int)texture.Size.X;
var height = (int)texture.Size.Y;
Draw(texture, new FloatRect(pos.X, pos.Y, width, height), new IntRect(0, 0, width, height), color);
}
*/
public void Draw(RenderTarget target, RenderStates Renderstates)
{
if (Drawing) throw new Exception("Call End first.");
foreach (var item in QueuedTextures)
{
Renderstates.Texture = item.Texture;
Renderstates.BlendMode = BlendingSettings;
item.Verticies.Draw(target, Renderstates);
}
}
public void Dispose() {
Dispose(true);
GC.SuppressFinalize(this);
public void Dispose()
{
}
protected virtual void Dispose(bool disposing) {
if (disposed)
return;
if (disposing) {
foreach (var tex in textures) {
tex.vertices.Dispose();
tex.Texture=null;
}
textures.Clear();
while(recycle.Count > 0) {
var tex=recycle.Dequeue();
tex.vertices.Dispose();
tex.Texture=null;
}
[DebuggerDisplay("[QueueItem] Name: {ID} | Texture: {Texture} | Verticies: {Verticies}")]
private class QueueItem
{
public Texture Texture;
public VertexArray Verticies;
public string ID;
public QueueItem(string TextureName, Texture Tex)
{
ID = TextureName;
Texture = Tex;
Verticies = new VertexArray(PrimitiveType.Quads);
}
disposed=true;
}
~SpriteBatch() {
Dispose(true);
}
}
}
+2 -4
View File
@@ -6,8 +6,7 @@ using SFML.Graphics;
namespace SS14.Client.Graphics
{
public class TextureList
: BaseCollection<Texture>
public class TextureList : BaseCollection<Texture>
{
public Texture this[int index]
{
@@ -22,8 +21,7 @@ namespace SS14.Client.Graphics
{
AddItem(name, tex);
}
internal TextureList()
: base(16, false) {}
internal TextureList() : base(16, false) {}
}
public static class TextureCache
{
+46 -39
View File
@@ -16,63 +16,64 @@ namespace SS14.Client.Graphics.Timing
#endregion
#region Variables.
private double _lastFrameTime; // Last frame time.
private double _frameDrawTime; // Time to draw a frame in milliseconds.
private double _lastFPSFrameTime; // Last FPS.
private float _averageFps; // Average FPS.
private float _highestFps; // Highest FPS.
private float _lowestFps; // Lowest FPS.
private float _currentFps; // Current FPS.
private long _frameCount; // Frame count.
private long _totalFrameCount; // Total frame count.
private Clock _timer; // FPS timer.
private int _frameAvgCounter; // Counter for frame average.
private double _frameAvgSum; // Frame average sum.
private double lastFrameTime; // Last frame time.
private double frameDrawTime; // Time to draw a frame in milliseconds.
private double lastFPSFrameTime; // Last FPS.
private double averageFps; // Average FPS.
private double highestFps; // Highest FPS.
private double lowestFps; // Lowest FPS.
private double currentFps; // Current FPS.
private long frameCount; // Frame count.
private long totalFrameCount; // Total frame count.
private Clock timer; // FPS timer.
private int frameAvgCounter; // Counter for frame average.
private double frameAvgSum;
private double CurrentFrameTime;
// Frame average sum.
#endregion
#region Properties
public double FrameDrawTime
{
get { return _frameDrawTime; }
get { return frameDrawTime; }
}
public Clock Timer
{
get { return _timer; }
set { _timer = value; }
get { return timer; }
set { timer = value; }
}
public float AverageFps
public double AverageFps
{
get { return _averageFps; }
get { return averageFps; }
}
public float HighestFps
public double HighestFps
{
get { return _highestFps; }
get { return highestFps; }
}
public float LowestFps
public double LowestFps
{
get { return _lowestFps; }
get { return lowestFps; }
}
public float CurrentFps
public double CurrentFps
{
get { return _currentFps; }
get { return currentFps; }
}
public long FrameCount
{
get { return _totalFrameCount; }
get { return totalFrameCount; }
}
#endregion
#region Constructor
public TimingData(Clock timer)
public TimingData(Clock sfmltimer)
{
_timer = timer;
timer = sfmltimer;
}
#endregion
@@ -87,21 +88,27 @@ namespace SS14.Client.Graphics.Timing
public void Reset()
{
if (_timer != null)
_timer.Restart();
_lastFPSFrameTime = 0.0;
_currentFps = 0.0f;
_frameCount = 0;
_lastFrameTime = 0.0;
_frameDrawTime = 0.0;
_frameAvgCounter = 0;
_frameAvgSum = 0.0;
_totalFrameCount = 0;
if (timer != null)
timer.Restart();
lastFPSFrameTime = 0.0;
currentFps = 0;
frameCount = 0;
lastFrameTime = 0.0;
frameDrawTime = 0.0;
frameAvgCounter = 0;
frameAvgSum = 0.0;
totalFrameCount = 0;
}
public bool Update()
public void Update()
{
return false;
CurrentFrameTime = Timer.ElapsedTime.AsSeconds();
Timer.Restart();
lastFrameTime = CurrentFrameTime;
currentFps = 1 / (CurrentFrameTime - lastFrameTime);
}
#endregion
}
@@ -8,7 +8,7 @@ namespace SS14.Client.Interfaces.Lighting
{
public interface ILightArea
{
RenderImage renderTarget { get; }
RenderImage RenderTarget { get; }
Vector2 LightPosition { get; set; }
Vector2 LightAreaSize { get; set; }
bool Calculated { get; set; }
+34 -42
View File
@@ -12,32 +12,8 @@ namespace SS14.Client.Services.Lighting
{
public class LightArea : ILightArea
{
private ShadowmapSize shadowmapSize;
public LightArea(int size)
{
int baseSize = 2 << (int)size;
LightAreaSize = new Vector2(baseSize, baseSize);
renderTarget = new RenderImage("LightArea"+ size, (uint)baseSize, (uint)baseSize);
Mask = IoCManager.Resolve<IResourceManager>().GetSprite("whitemask");
}
public LightArea(ShadowmapSize shadowmapSize)
{
int baseSize = 2 << (int)shadowmapSize;
LightAreaSize = new Vector2(baseSize, baseSize);
renderTarget = new RenderImage("LightArea"+ shadowmapSize,(uint)baseSize, (uint)baseSize);
Mask = IoCManager.Resolve<IResourceManager>().GetSprite("whitemask");
}
#region ILightArea Members
public RenderImage renderTarget { get; private set; }
public RenderImage RenderTarget { get; private set; }
/// <summary>
/// World position coordinates of the light's center
@@ -46,11 +22,12 @@ namespace SS14.Client.Services.Lighting
public Vector2 LightAreaSize { get; set; }
public bool Calculated { get; set; }
public CluwneSprite Mask { get; set; }
public CluwneSprite Mask { get; set; }
public bool MaskFlipX { get; set; }
public bool MaskFlipY { get; set; }
public bool Rot90 { get; set; }
public Vector4 MaskProps
{
get
@@ -74,6 +51,32 @@ namespace SS14.Client.Services.Lighting
}
}
public LightArea(int size)
{
int baseSize = 2 << (int) size;
LightAreaSize = new Vector2(baseSize, baseSize);
RenderTarget = new RenderImage("LightArea"+ size, (uint)baseSize, (uint)baseSize);
Mask = IoCManager.Resolve<IResourceManager>().GetSprite("whitemask");
}
public LightArea(ShadowmapSize shadowmapSize)
{
int baseSize = 2 << (int)shadowmapSize;
LightAreaSize = new Vector2(baseSize, baseSize);
RenderTarget = new RenderImage("LightArea"+ shadowmapSize,(uint)baseSize, (uint)baseSize);
Mask = IoCManager.Resolve<IResourceManager>().GetSprite("whitemask");
}
#region ILightArea Members
public Vector2 ToRelativePosition(Vector2 worldPosition)
{
return worldPosition - (LightPosition - LightAreaSize*0.5f);
@@ -81,14 +84,14 @@ namespace SS14.Client.Services.Lighting
public void BeginDrawingShadowCasters()
{
CluwneLib.CurrentRenderTarget = renderTarget;
CluwneLib.ClearCurrentRendertarget(Color.FromArgb(0, 0, 0, 0));
RenderTarget.BeginDrawing();
RenderTarget.Clear(Color.FromArgb(0, 0, 0, 0));
}
public void EndDrawingShadowCasters()
{
CluwneLib.CurrentRenderTarget = null;
RenderTarget.EndDrawing();
}
public void SetMask(string mask)
@@ -104,17 +107,6 @@ namespace SS14.Client.Services.Lighting
}
//TODO Mask
CluwneSprite ILightArea.Mask
{
get
{
return Mask;
}
set
{
Mask = value;
}
}
}
}
@@ -3,7 +3,7 @@ using SS14.Client.Graphics;
using SS14.Client.Graphics.VertexData;
using SS14.Shared.Maths;
using System.Drawing;
using Color = System.Drawing.Color;
using Color = SFML.Graphics.Color;
namespace SS14.Client.Services.Lighting
{
@@ -23,10 +23,10 @@ namespace SS14.Client.Services.Lighting
// };
vertex = new VertexArray(PrimitiveType.Lines, 4);
vertex[0] = new Vertex(new Vector2(1,-1), Color.Transparent.ToSFMLColor(),new Vector2(1,1));
vertex[1] = new Vertex(new Vector2(-1, -1), Color.Transparent.ToSFMLColor(), new Vector2(0, 1));
vertex[2] = new Vertex(new Vector2(-1, 1), Color.Transparent.ToSFMLColor(), new Vector2(0, 0));
vertex[3] = new Vertex(new Vector2(1, 1), Color.Transparent.ToSFMLColor(), new Vector2(1, 0));
vertex[0] = new Vertex(new Vector2( 1,-1), Color.Transparent, new Vector2(1, 1));
vertex[1] = new Vertex(new Vector2(-1,-1), Color.Transparent, new Vector2(0, 1));
vertex[2] = new Vertex(new Vector2(-1, 1), Color.Transparent, new Vector2(0, 0));
vertex[3] = new Vertex(new Vector2( 1, 1), Color.Transparent, new Vector2(1, 0));
@@ -38,7 +38,7 @@ namespace SS14.Client.Services.Lighting
// What is the purpose of Quadrenderer? all it is doing is drawing transparent verts.
CluwneLib.CurrentRenderTarget.Draw(vertex);
// CluwneLib.CurrentRenderTarget.Draw(vertex);
@@ -64,22 +64,61 @@ namespace SS14.Client.Services.Lighting
ImageBufferFormats.BufferRGB888A8);
}
public void ResolveShadows(Texture shadowCastersTexture, RenderImage result, Vector2 lightPosition,
bool attenuateShadows, Texture mask, Vector4 maskProps, Vector4 diffuseColor)
public void ResolveShadows(LightArea Area, bool attenuateShadows, Texture mask)
{
Texture shadowCastersTexture = Area.RenderTarget.Texture;
RenderImage Result = Area.RenderTarget;
Vector2 LightPosition = Area.LightPosition;
Texture Mask = mask;
Vector4 MaskProps = Vector4.Zero;
Vector4 diffuseColor = Vector4.One;
//only DrawShadows needs these vars
resolveShadowsEffectTechnique["DrawShadows"].SetParameter("AttenuateShadows", attenuateShadows ? 0 : 1);
resolveShadowsEffectTechnique["DrawShadows"].SetParameter("MaskProps", maskProps);
resolveShadowsEffectTechnique["DrawShadows"].SetParameter("MaskProps", MaskProps);
resolveShadowsEffectTechnique["DrawShadows"].SetParameter("DiffuseColor", diffuseColor);
// CluwneLib.CurrentRenderTarget.BlendingMode = BlendingModes.None;
ExecuteTechnique(shadowCastersTexture, distancesRT, "ComputeDistances");
ExecuteTechnique(distancesRT.Texture, distortRT, "Distort");
ApplyHorizontalReduction(distortRT, shadowMap);
ExecuteTechnique(mask, result, "DrawShadows", shadowMap);
ExecuteTechnique(Mask, Result, "DrawShadows", shadowMap);
ExecuteTechnique(shadowsRT.Texture, processedShadowsRT, "BlurHorizontally");
ExecuteTechnique(processedShadowsRT.Texture, result, "BlurVerticallyAndAttenuate");
CluwneLib.CurrentShader = null;
ExecuteTechnique(processedShadowsRT.Texture, Result, "BlurVerticallyAndAttenuate");
resolveShadowsEffectTechnique["DrawShadows"].ResetCurrentShader();
}
public void ResolveShadows(LightArea Area, bool attenuateShadows)
{
Texture shadowCastersTexture = Area.RenderTarget.Texture;
RenderImage Result = Area.RenderTarget;
Vector2 LightPosition = Area.LightPosition;
Texture Mask = Area.Mask.Texture;
Vector4 MaskProps = Area.MaskProps;
Vector4 diffuseColor = Vector4.One;
//only DrawShadows needs these vars
resolveShadowsEffectTechnique["DrawShadows"].SetParameter("AttenuateShadows", attenuateShadows ? 0 : 1);
resolveShadowsEffectTechnique["DrawShadows"].SetParameter("MaskProps", MaskProps);
resolveShadowsEffectTechnique["DrawShadows"].SetParameter("DiffuseColor", diffuseColor);
ExecuteTechnique(shadowCastersTexture, distancesRT, "ComputeDistances");
ExecuteTechnique(distancesRT.Texture, distortRT, "Distort");
ApplyHorizontalReduction(distortRT, shadowMap);
ExecuteTechnique(Mask, Result, "DrawShadows", shadowMap);
ExecuteTechnique(shadowsRT.Texture, processedShadowsRT, "BlurHorizontally");
ExecuteTechnique(processedShadowsRT.Texture, Result, "BlurVerticallyAndAttenuate");
resolveShadowsEffectTechnique["DrawShadows"].ResetCurrentShader();
}
private void ExecuteTechnique(Texture source, RenderImage destination, string techniqueName)
@@ -87,15 +126,15 @@ namespace SS14.Client.Services.Lighting
ExecuteTechnique(source, destination, techniqueName, null);
}
private void ExecuteTechnique(Texture source, RenderImage destination, string techniqueName, RenderImage shadowMap)
private void ExecuteTechnique(Texture source, RenderImage destinationTarget, string techniqueName, RenderImage shadowMap)
{
Vector2 renderTargetSize;
renderTargetSize = new Vector2(baseSize, baseSize);
CluwneLib.CurrentRenderTarget = destination;
CluwneLib.CurrentRenderTarget.Clear(Color.White);
CluwneLib.CurrentShader = resolveShadowsEffectTechnique[techniqueName];
destinationTarget.BeginDrawing();
destinationTarget.Clear(Color.White);
resolveShadowsEffectTechnique[techniqueName].setAsCurrentShader() ;
resolveShadowsEffectTechnique[techniqueName].SetParameter("renderTargetSize", renderTargetSize);
if (source != null)
@@ -103,45 +142,48 @@ namespace SS14.Client.Services.Lighting
if (shadowMap != null)
resolveShadowsEffectTechnique[techniqueName].SetParameter("ShadowMapTexture", shadowMap);
quadRender.Render(new Vector2(1, 1)*-1, new Vector2(1, 1));
CluwneLib.CurrentRenderTarget = null;
destinationTarget.EndDrawing();
}
private void ApplyHorizontalReduction(RenderImage source, RenderImage destination)
{
int step = reductionChainCount - 1;
RenderImage s = source;
RenderImage d = reductionRT[step];
CluwneLib.CurrentShader = reductionEffectTechnique["HorizontalReduction"];
RenderImage src = source;
RenderImage HorizontalReduction= reductionRT[step];
reductionEffectTechnique["HorizontalReduction"].setAsCurrentShader();
while (step >= 0)
{
d = reductionRT[step];
HorizontalReduction = reductionRT[step];
CluwneLib.CurrentRenderTarget = d;
d.Clear(Color.White);
HorizontalReduction.BeginDrawing();
HorizontalReduction.Clear(Color.White);
var textureDim = new Vector2(1.0f/s.Width, 1.0f/s.Height);
reductionEffectTechnique["HorizontalReduction"].SetParameter("SourceTexture", s);
reductionEffectTechnique["HorizontalReduction"].SetParameter("TextureDimensions",textureDim);
quadRender.Render(new Vector2(1, 1)*-1, new Vector2(1, 1));
s = d;
var textureDim = new Vector2(1.0f/src.Width, 1.0f/src.Height);
reductionEffectTechnique["HorizontalReduction"].SetParameter("SourceTexture", GLSLShader.CurrentTexture);
reductionEffectTechnique["HorizontalReduction"].SetParameter("TextureDimensions",textureDim);
src.Blit(HorizontalReduction);
HorizontalReduction.EndDrawing();
src = HorizontalReduction;
step--;
}
//copy to destination
CluwneLib.CurrentRenderTarget = destination;
destination.BeginDrawing();
destination.Clear(Color.White);
reductionEffectTechnique["Copy"].SetParameter("SourceTexture",d);
reductionEffectTechnique["Copy"].SetParameter("SourceTexture", reductionRT[reductionChainCount - 1]);
CluwneLib.CurrentShader = reductionEffectTechnique["Copy"];
reductionEffectTechnique["Copy"].SetParameter("SourceTexture", GLSLShader.CurrentTexture);
reductionEffectTechnique["Copy"].setAsCurrentShader();
CluwneLib.CurrentRenderTarget.Clear(Color.White);
quadRender.Render(new Vector2(1, 1)*-1, new Vector2(1, 1));
HorizontalReduction.Blit(destination);
CluwneLib.CurrentRenderTarget = null;
CluwneLib.ResetRenderTarget();
}
public void Dispose()
@@ -69,7 +69,7 @@ namespace SS14.Client.Services.Network
totalRecBytes += _dataPoints[i].RecievedBytes;
totalSentBytes += _dataPoints[i].SentBytes;
CluwneLib.CurrentRenderTarget = null;
CluwneLib.ResetRenderTarget();
//Draw recieved line
CluwneLib.drawRectangle((int)CluwneLib.CurrentRenderTarget.Size.X - (4*(MaxDataPoints - i)),
+344 -270
View File
@@ -1,7 +1,7 @@
using Lidgren.Network;
using SFML.Graphics;
using SFML.Window;
using SS14.Client.ClientWindow;
using SS14.Client.GameObjects;
using SS14.Client.Graphics;
using SS14.Client.Graphics.Event;
@@ -115,6 +115,7 @@ namespace SS14.Client.Services.State.States
private LightArea lightArea512;
private ILight playerVision;
private ISS14Serializer serializer;
private RenderImage playerOcclusionTarget;
private RenderImage _occluderDebugTarget;
@@ -153,28 +154,39 @@ namespace SS14.Client.Services.State.States
UserInterfaceManager.DisposeAllComponents();
//Init serializer
var serializer = IoCManager.Resolve<ISS14Serializer>();
serializer = IoCManager.Resolve<ISS14Serializer>();
_entityManager = new EntityManager(NetworkManager);
IoCManager.Resolve<IEntityManagerContainer>().EntityManager = _entityManager;
NetworkManager.MessageArrived += NetworkManagerMessageArrived;
NetworkManager.RequestMap();
IoCManager.Resolve<IMapManager>().TileChanged += OnTileChanged;
IoCManager.Resolve<IPlayerManager>().OnPlayerMove += OnPlayerMove;
NetworkManager.MessageArrived += NetworkManagerMessageArrived;
NetworkManager.RequestMap();
// TODO This should go somewhere else, there should be explicit session setup and teardown at some point.
NetworkManager.SendClientName(ConfigurationManager.GetPlayerName());
// Create new
_gaussianBlur = new GaussianBlur(ResourceManager);
_realScreenWidthTiles = (float)CluwneLib.Screen.Size.X / MapManager.TileSize;
_realScreenHeightTiles = (float)CluwneLib.Screen.Size.Y / MapManager.TileSize;
InitializeRenderTargets();
InitializeSpriteBatches();
InitalizeLighting();
InitializeGUI();
}
private void InitializeRenderTargets()
{
_baseTarget = new RenderImage("baseTarget", (uint)CluwneLib.Screen.GetView().Size.X,
(uint)CluwneLib.Screen.GetView().Size.Y, true);
(uint)CluwneLib.Screen.GetView().Size.Y, true);
_cleanupList.Add(_baseTarget);
//_baseTargetSprite = new CluwneSprite(_baseTarget);
//_cleanupSpriteList.Add(_baseTargetSprite);
_baseTargetSprite = new CluwneSprite("BaseTargetSprite",_baseTarget.Texture);
_cleanupSpriteList.Add(_baseTargetSprite);
_sceneTarget = new RenderImage("sceneTarget", (uint)CluwneLib.Screen.GetView().Size.X,
(uint)CluwneLib.Screen.GetView().Size.Y, true);
@@ -185,11 +197,18 @@ namespace SS14.Client.Services.State.States
_overlayTarget = new RenderImage("OverlayTarget", (uint)CluwneLib.Screen.GetView().Size.X,
(uint)CluwneLib.Screen.GetView().Size.Y, true);
_cleanupList.Add(_overlayTarget);
// _overlayTarget.SourceBlend = AlphaBlendOperation.SourceAlpha;
// _overlayTarget.DestinationBlend = AlphaBlendOperation.InverseSourceAlpha;
// _overlayTarget.SourceBlendAlpha = AlphaBlendOperation.SourceAlpha;
_cleanupList.Add(_overlayTarget);
//_overlayTarget.SourceBlend = AlphaBlendOperation.SourceAlpha;
//_overlayTarget.DestinationBlend = AlphaBlendOperation.InverseSourceAlpha;
//_overlayTarget.SourceBlendAlpha = AlphaBlendOperation.SourceAlpha;
//_overlayTarget.DestinationBlendAlpha = AlphaBlendOperation.InverseSourceAlpha;
_overlayTarget.BlendSettings.ColorSrcFactor = BlendMode.Factor.SrcAlpha;
_overlayTarget.BlendSettings.ColorDstFactor = BlendMode.Factor.OneMinusSrcAlpha;
_overlayTarget.BlendSettings.AlphaSrcFactor = BlendMode.Factor.SrcAlpha;
_overlayTarget.BlendSettings.AlphaDstFactor = BlendMode.Factor.OneMinusSrcAlpha;
_composedSceneTarget = new RenderImage("composedSceneTarget", (uint)CluwneLib.Screen.GetView().Size.X,
(uint)CluwneLib.Screen.GetView().Size.Y,
@@ -210,33 +229,48 @@ namespace SS14.Client.Services.State.States
_cleanupList.Add(_lightTargetIntermediate);
_lightTargetIntermediateSprite = new CluwneSprite("lightTargetIntermediateSprite", _lightTargetIntermediate) { DepthWriteEnabled = false };
_cleanupSpriteList.Add(_lightTargetIntermediateSprite);
}
private void InitializeSpriteBatches()
{
_gasBatch = new SpriteBatch();
//_gasBatch.SourceBlend = AlphaBlendOperation.SourceAlpha;
//_gasBatch.DestinationBlend = AlphaBlendOperation.InverseSourceAlpha;
//_gasBatch.SourceBlendAlpha = AlphaBlendOperation.SourceAlpha;
//_gasBatch.DestinationBlendAlpha = AlphaBlendOperation.InverseSourceAlpha;
//_gasBatch.SourceBlend = AlphaBlendOperation.SourceAlpha;
//_gasBatch.DestinationBlend = AlphaBlendOperation.InverseSourceAlpha;
//_gasBatch.SourceBlendAlpha = AlphaBlendOperation.SourceAlpha;
//_gasBatch.DestinationBlendAlpha = AlphaBlendOperation.InverseSourceAlpha;
_gasBatch.BlendingSettings.ColorSrcFactor = BlendMode.Factor.SrcAlpha;
_gasBatch.BlendingSettings.ColorDstFactor = BlendMode.Factor.OneMinusDstAlpha;
_gasBatch.BlendingSettings.AlphaSrcFactor = BlendMode.Factor.SrcAlpha;
_gasBatch.BlendingSettings.AlphaDstFactor = BlendMode.Factor.OneMinusSrcAlpha;
_wallTopsBatch = new SpriteBatch();
//_wallTopsBatch.SourceBlend = AlphaBlendOperation.SourceAlpha;
//_wallTopsBatch.DestinationBlend = AlphaBlendOperation.InverseSourceAlpha;
//_wallTopsBatch.SourceBlendAlpha = AlphaBlendOperation.SourceAlpha;
//_wallTopsBatch.DestinationBlendAlpha = AlphaBlendOperation.InverseSourceAlpha;
//_wallTopsBatch.SourceBlend = AlphaBlendOperation.SourceAlpha;
//_wallTopsBatch.DestinationBlend = AlphaBlendOperation.InverseSourceAlpha;
//_wallTopsBatch.SourceBlendAlpha = AlphaBlendOperation.SourceAlpha;
//_wallTopsBatch.DestinationBlendAlpha = AlphaBlendOperation.InverseSourceAlpha;
_wallTopsBatch.BlendingSettings.ColorSrcFactor = BlendMode.Factor.SrcAlpha;
_wallTopsBatch.BlendingSettings.ColorDstFactor = BlendMode.Factor.OneMinusDstAlpha;
_wallTopsBatch.BlendingSettings.AlphaSrcFactor = BlendMode.Factor.SrcAlpha;
_wallTopsBatch.BlendingSettings.AlphaDstFactor = BlendMode.Factor.OneMinusSrcAlpha;
_decalBatch = new SpriteBatch();
//_decalBatch.SourceBlend = AlphaBlendOperation.SourceAlpha;
//_decalBatch.DestinationBlend = AlphaBlendOperation.InverseSourceAlpha;
//_decalBatch.SourceBlendAlpha = AlphaBlendOperation.SourceAlpha;
//_decalBatch.DestinationBlendAlpha = AlphaBlendOperation.InverseSourceAlpha;
//_decalBatch.SourceBlend = AlphaBlendOperation.SourceAlpha;
//_decalBatch.DestinationBlend = AlphaBlendOperation.InverseSourceAlpha;
//_decalBatch.SourceBlendAlpha = AlphaBlendOperation.SourceAlpha;
//_decalBatch.DestinationBlendAlpha = AlphaBlendOperation.InverseSourceAlpha;
_decalBatch.BlendingSettings.ColorSrcFactor = BlendMode.Factor.SrcAlpha;
_decalBatch.BlendingSettings.ColorDstFactor = BlendMode.Factor.OneMinusDstAlpha;
_decalBatch.BlendingSettings.AlphaSrcFactor = BlendMode.Factor.SrcAlpha;
_decalBatch.BlendingSettings.AlphaDstFactor = BlendMode.Factor.OneMinusSrcAlpha;
_floorBatch = new SpriteBatch();
_wallBatch = new SpriteBatch();
}
_gaussianBlur = new GaussianBlur(ResourceManager);
_realScreenWidthTiles = (float)CluwneLib.Screen.Size.X / MapManager.TileSize;
_realScreenHeightTiles = (float)CluwneLib.Screen.Size.Y / MapManager.TileSize;
private void InitializeGUI()
{
//Init GUI components
_gameChat = new Chatbox(ResourceManager, UserInterfaceManager, KeyBindingManager);
_gameChat.TextSubmitted += ChatTextboxTextSubmitted;
@@ -249,59 +283,14 @@ namespace SS14.Client.Services.State.States
UserInterfaceManager.AddComponent(statusBar);
var hotbar = new Hotbar(ResourceManager);
hotbar.Position = new Point(5, (int)CluwneLib.Screen.Size.Y - hotbar.ClientArea.Height - 5);
hotbar.Position = new Point((int)CluwneLib.Screen.Size.X, (int)CluwneLib.Screen.Size.Y - hotbar.ClientArea.Height - 5);
hotbar.Update(0);
UserInterfaceManager.AddComponent(hotbar);
#region Lighting
quadRenderer = new QuadRenderer();
quadRenderer.LoadContent();
shadowMapResolver = new ShadowMapResolver(quadRenderer, ShadowmapSize.Size1024, ShadowmapSize.Size1024,
ResourceManager);
shadowMapResolver.LoadContent();
lightArea128 = new LightArea(ShadowmapSize.Size128);
lightArea256 = new LightArea(ShadowmapSize.Size256);
lightArea512 = new LightArea(ShadowmapSize.Size512);
lightArea1024 = new LightArea(ShadowmapSize.Size1024);
screenShadows = new RenderImage("screenShadows", CluwneLib.CurrentClippingViewport.Width,
CluwneLib.CurrentClippingViewport.Height, ImageBufferFormats.BufferRGB888A8);
_cleanupList.Add(screenShadows);
screenShadows.UseDepthBuffer = false;
shadowIntermediate = new RenderImage("shadowIntermediate", CluwneLib.CurrentClippingViewport.Width,
CluwneLib.CurrentClippingViewport.Height,
ImageBufferFormats.BufferRGB888A8);
_cleanupList.Add(shadowIntermediate);
shadowIntermediate.UseDepthBuffer = false;
shadowBlendIntermediate = new RenderImage("shadowBlendIntermediate", CluwneLib.CurrentClippingViewport.Width,
CluwneLib.CurrentClippingViewport.Height,
ImageBufferFormats.BufferRGB888A8);
_cleanupList.Add(shadowBlendIntermediate);
shadowBlendIntermediate.UseDepthBuffer = false;
playerOcclusionTarget = new RenderImage("playerOcclusionTarget", CluwneLib.CurrentClippingViewport.Width,
CluwneLib.CurrentClippingViewport.Height,
ImageBufferFormats.BufferRGB888A8);
_cleanupList.Add(playerOcclusionTarget);
playerOcclusionTarget.UseDepthBuffer = false;
LightblendTechnique = IoCManager.Resolve<IResourceManager>().GetTechnique("lightblend");
Lightmap = IoCManager.Resolve<IResourceManager>().GetShader("lightmap");
playerVision = IoCManager.Resolve<ILightManager>().CreateLight();
playerVision.SetColor(0, 0, 0, 0);
playerVision.SetRadius(1024);
playerVision.Move(Vector2.Zero);
#endregion
_handsGui = new HandsGui();
_handsGui.Position = new Point(hotbar.Position.X + 5, hotbar.Position.Y + 7);
UserInterfaceManager.AddComponent(_handsGui);
var combo = new HumanComboGui(PlayerManager, NetworkManager, ResourceManager, UserInterfaceManager);
combo.Update(0);
combo.Position = new Point(hotbar.ClientArea.Right - combo.ClientArea.Width + 5,
@@ -354,110 +343,183 @@ namespace SS14.Client.Services.State.States
menuButton.Update(0);
menuButton.Clicked += menuButton_Clicked;
UserInterfaceManager.AddComponent(menuButton);
}
}
private void InitalizeLighting()
{
quadRenderer = new QuadRenderer();
quadRenderer.LoadContent();
shadowMapResolver = new ShadowMapResolver(quadRenderer, ShadowmapSize.Size1024, ShadowmapSize.Size1024,
ResourceManager);
shadowMapResolver.LoadContent();
lightArea128 = new LightArea(ShadowmapSize.Size128);
lightArea256 = new LightArea(ShadowmapSize.Size256);
lightArea512 = new LightArea(ShadowmapSize.Size512);
lightArea1024 = new LightArea(ShadowmapSize.Size1024);
screenShadows = new RenderImage("screenShadows", CluwneLib.CurrentClippingViewport.Width,
CluwneLib.CurrentClippingViewport.Height, ImageBufferFormats.BufferRGB888A8);
_cleanupList.Add(screenShadows);
screenShadows.UseDepthBuffer = false;
shadowIntermediate = new RenderImage("shadowIntermediate", CluwneLib.CurrentClippingViewport.Width,
CluwneLib.CurrentClippingViewport.Height,
ImageBufferFormats.BufferRGB888A8);
_cleanupList.Add(shadowIntermediate);
shadowIntermediate.UseDepthBuffer = false;
shadowBlendIntermediate = new RenderImage("shadowBlendIntermediate", CluwneLib.CurrentClippingViewport.Width,
CluwneLib.CurrentClippingViewport.Height,
ImageBufferFormats.BufferRGB888A8);
_cleanupList.Add(shadowBlendIntermediate);
shadowBlendIntermediate.UseDepthBuffer = false;
playerOcclusionTarget = new RenderImage("playerOcclusionTarget", CluwneLib.CurrentClippingViewport.Width,
CluwneLib.CurrentClippingViewport.Height,
ImageBufferFormats.BufferRGB888A8);
_cleanupList.Add(playerOcclusionTarget);
playerOcclusionTarget.UseDepthBuffer = false;
LightblendTechnique = IoCManager.Resolve<IResourceManager>().GetTechnique("lightblend");
Lightmap = IoCManager.Resolve<IResourceManager>().GetShader("lightmap");
playerVision = IoCManager.Resolve<ILightManager>().CreateLight();
playerVision.SetColor(Color.Transparent);
playerVision.SetRadius(1024);
playerVision.Move(Vector2.Zero);
_occluderDebugTarget = new RenderImage("debug", 1920, 1080);
}
public void Update(FrameEventArgs e)
{
LastUpdate = Now;
Now = DateTime.Now;
IoCManager.Resolve<IGameTimer>().UpdateTime(e.FrameDeltaTime);
_entityManager.ComponentManager.Update(e.FrameDeltaTime);
_entityManager.Update(e.FrameDeltaTime);
PlacementManager.Update(MousePosScreen, MapManager);
PlayerManager.Update(e.FrameDeltaTime);
if (PlayerManager != null && PlayerManager.ControlledEntity != null)
ClientWindowData.Singleton.WorldCenter =
PlayerManager.ControlledEntity.GetComponent<TransformComponent>(ComponentFamily.Transform).Position;
MousePosWorld = ClientWindowData.Singleton.ScreenToWorld(MousePosScreen);
if (PlayerManager != null && PlayerManager.ControlledEntity != null)
{
CluwneLib.WorldCenter = PlayerManager.ControlledEntity.GetComponent<TransformComponent>(ComponentFamily.Transform).Position;
}
MousePosWorld = CluwneLib.ScreenToWorld(MousePosScreen);
}
bool onetime = true;
public void Render(FrameEventArgs e)
{
CluwneLib.CurrentRenderTarget = _baseTarget;
_baseTarget.Clear(Color.Black);
CluwneLib.Screen.Clear(Color.Black.ToSFMLColor());
CluwneLib.Screen.Clear(Color.Black);
CluwneLib.Screen.DefaultView.Reset(new FloatRect(new Vector2(0,0), new Vector2(400, 400)));
// CluwneLib.Screen.DefaultView.Reset(new FloatRect(new Vector2(0,0), new Vector2(400, 400)));
ClientWindowData.Singleton.TileSize = MapManager.TileSize;
CluwneLib.TileSize = MapManager.TileSize;
CalculateAllLights();
// CalculateAllLights();
if (PlayerManager.ControlledEntity != null)
{
ClientWindowData.Singleton.WorldCenter =
ClientWindowData.Singleton.GetNearestPixel( // Snapping view to pixels to prevent the blurring of tiles.
PlayerManager.ControlledEntity.GetComponent<TransformComponent>(ComponentFamily.Transform).Position);
ClientWindowData.Singleton.ScreenViewportSize =
new SizeF(CluwneLib.Screen.Size.X, CluwneLib.Screen.Size.Y);
CluwneLib.WorldCenter = CluwneLib.GetNearestPixel(PlayerManager.ControlledEntity.GetComponent<TransformComponent>(ComponentFamily.Transform).Position);
CluwneLib.ScreenViewportSize = new SizeF(CluwneLib.Screen.Size.X, CluwneLib.Screen.Size.Y);
var vp = ClientWindowData.Singleton.WorldViewport;
var vp = CluwneLib.WorldViewport;
// Get nearby lights
ILight[] lights =
IoCManager.Resolve<ILightManager>().LightsIntersectingRect(vp);
ILight[] lights = IoCManager.Resolve<ILightManager>().LightsIntersectingRect(vp);
// Render the lightmap
RenderLightMap(lights);
RenderLightsIntoMap(lights);
CalculateSceneBatches(vp);
if (_redrawTiles)
{
//Set rendertarget to draw the rest of the scene
CluwneLib.CurrentRenderTarget = _tilesTarget;
CluwneLib.CurrentRenderTarget.Clear(Color.Black.ToSFMLColor());
if (_floorBatch.Count > 0)
{
CluwneLib.CurrentRenderTarget.Draw(_floorBatch);
}
if (_wallBatch.Count > 0)
CluwneLib.CurrentRenderTarget.Draw(_wallBatch);
_redrawTiles = false;
}
CluwneLib.CurrentRenderTarget = _sceneTarget;
//Draw all rendertargets to the scenetarget
_sceneTarget.BeginDrawing();
_sceneTarget.Clear(Color.Black);
//PreOcclusion
RenderTiles();
_tilesTarget.Blit(0, 0, _tilesTarget.Width, _tilesTarget.Height, Color.White, BlitterSizeMode.Crop);
//ComponentManager.Singleton.Render(0, CluwneLib.ScreenViewport);
RenderComponents(e.FrameDeltaTime, vp);
//ComponentManager.Singleton.Render(0, ClientWindowData.Singleton.ScreenViewport);
RenderComponents(e.FrameDeltaTime, vp);
RenderOverlay();
if (_redrawOverlay)
{
CluwneLib.CurrentRenderTarget = _overlayTarget;
_overlayTarget.Clear(Color.Transparent);
_sceneTarget.EndDrawing();
_sceneTarget.ResetCurrentRenderTarget();
_sceneTarget.Blit(0,0,CluwneLib.Screen.Size.X,CluwneLib.Screen.Size.Y);
if (onetime)
{
_sceneTarget.Texture.CopyToImage().SaveToFile("..\\scenetarget.png");
_overlayTarget.Texture.CopyToImage().SaveToFile("..\\overlaytarget.png");
_tilesTarget.Texture.CopyToImage().SaveToFile("..\\tilesTarget.png");
onetime = false;
}
// LightScene();
//RenderDebug(vp);
//Render the placement manager shit
PlacementManager.Render();
}
}
private void RenderTiles()
{
if (_redrawTiles)
{
//Set rendertarget to draw the rest of the scene
_tilesTarget.BeginDrawing();
_tilesTarget.Clear(Color.Black);
if (_floorBatch.Count > 0)
{
_tilesTarget.Draw(_floorBatch);
}
if (_wallBatch.Count > 0)
_tilesTarget.Draw(_wallBatch);
if (_wallTopsBatch.Count > 0)
_overlayTarget.Draw(_wallTopsBatch);
_tilesTarget.EndDrawing();
_redrawTiles = false;
}
_tilesTarget.Blit(0, 0, _tilesTarget.Width, _tilesTarget.Height, Color.White, BlitterSizeMode.Scale);
}
private void RenderOverlay()
{
if (_redrawOverlay)
{
_overlayTarget.BeginDrawing();
_overlayTarget.Clear(Color.Transparent);
// Render decal batch
if (_decalBatch.Count > 0)
CluwneLib.CurrentRenderTarget.Draw(_decalBatch);
_overlayTarget.Draw(_decalBatch);
if (_wallTopsBatch.Count > 0)
CluwneLib.CurrentRenderTarget.Draw(_wallTopsBatch);
if (_gasBatch.Count > 0)
CluwneLib.CurrentRenderTarget.Draw(_gasBatch);
CluwneLib.CurrentRenderTarget = _sceneTarget;
_overlayTarget.Draw(_gasBatch);
_redrawOverlay = false;
}
_overlayTarget.EndDrawing();
}
_overlayTarget.Blit(0, 0, _tilesTarget.Width, _tilesTarget.Height, Color.White, BlitterSizeMode.Crop);
LightScene();
RenderDebug(vp);
//Render the placement manager shit
PlacementManager.Render();
}
}
private void RenderDebug(RectangleF viewport)
@@ -465,7 +527,7 @@ namespace SS14.Client.Services.State.States
if(debugWallOccluders)
_occluderDebugTarget.Blit(0,0,_occluderDebugTarget.Width, _occluderDebugTarget.Height, Color.White, BlitterSizeMode.Crop);
if (debugHitboxes)
if (CluwneLib.Debug.DebugColliders)
{
var colliders =
_entityManager.ComponentManager.GetComponents(ComponentFamily.Collider)
@@ -481,7 +543,7 @@ namespace SS14.Client.Services.State.States
foreach (var hitbox in colliders.Concat(collidables))
{
var box = ClientWindowData.Singleton.WorldToScreen(hitbox.AABB);
var box = CluwneLib.WorldToScreen(hitbox.AABB);
CluwneLib.drawRectangle((int)box.Left, (int)box.Top, (int)box.Width, (int)box.Height,
System.Drawing.Color.FromArgb(64, hitbox.Color));
CluwneLib.drawHollowRectangle((int)box.Left, (int)box.Top, (int)box.Width, (int)box.Height, 1f,
@@ -504,7 +566,7 @@ namespace SS14.Client.Services.State.States
shadowMapResolver.Dispose();
_gaussianBlur.Dispose();
_entityManager.Shutdown();
UserInterfaceManager.DisposeAllComponents(); //HerpDerp. This is probably bad. Should not remove them ALL.
// UserInterfaceManager.DisposeAllComponents(); //HerpDerp. This is probably bad. Should not remove them ALL.
NetworkManager.MessageArrived -= NetworkManagerMessageArrived;
//RenderTargetCache.DestroyAll();
_decalBatch.Dispose();
@@ -539,6 +601,7 @@ namespace SS14.Client.Services.State.States
if (e.Code == Keyboard.Key.F2)
{
_showDebug = !_showDebug;
CluwneLib.Debug.ToggleWallDebug();
}
if (e.Code == Keyboard.Key.F3)
{
@@ -606,7 +669,7 @@ namespace SS14.Client.Services.State.States
}
#endregion
#region Mouze
#region Mouse
public void MouseUp(MouseButtonEventArgs e)
{
UserInterfaceManager.MouseUp(e);
@@ -756,7 +819,7 @@ namespace SS14.Client.Services.State.States
{
float distanceToPrev = (MousePosScreen - new Vector2(e.X, e.Y)).Length;
MousePosScreen = new Vector2(e.X, e.Y);
MousePosWorld = ClientWindowData.Singleton.ScreenToWorld(MousePosScreen);
MousePosWorld = CluwneLib.ScreenToWorld(MousePosScreen);
UserInterfaceManager.MouseMove(e);
}
@@ -1066,7 +1129,7 @@ namespace SS14.Client.Services.State.States
public void FormResize()
{
ClientWindowData.Singleton.ScreenViewportSize =
CluwneLib.ScreenViewportSize =
new SizeF(CluwneLib.Screen.Size.X, CluwneLib.Screen.Size.Y);
UserInterfaceManager.ResizeComponents();
@@ -1094,6 +1157,14 @@ namespace SS14.Client.Services.State.States
#region Lighting in order of call
/**
* Calculate lights In player view
* Render Lights in view to lightmap > Screenshadows
*
*
**/
private void CalculateAllLights()
{
foreach
@@ -1108,11 +1179,10 @@ namespace SS14.Client.Services.State.States
/// If a light hasn't been prerendered yet, it renders that light.
/// </summary>
/// <param name="lights">Array of lights</param>
private void RenderLightMap(IEnumerable<ILight> lights)
private void RenderLightsIntoMap(IEnumerable<ILight> lights)
{
//Step 1 - Calculate lights that haven't been calculated yet or need refreshing
foreach (ILight l in lights.Where(l => l.LightArea.Calculated == false))
{
if (l.LightState != LightState.On)
@@ -1121,41 +1191,34 @@ namespace SS14.Client.Services.State.States
CalculateLightArea(l);
}
//Step 2 - Set up the render targets for the composite lighting.
RenderImage source = screenShadows;
source.Clear(Color.FromArgb(0, 0, 0, 0));
RenderImage destination = shadowIntermediate;
CluwneLib.CurrentRenderTarget = destination;
//Step 2 - Set up the render targets for the composite lighting.
RenderImage copy;
//Reset the shader and render target
CluwneLib.CurrentShader = Lightmap;
screenShadows.Clear(Color.Black);
var lightTextures = new List<Texture>();
var colors = new List<Vector4>();
var positions = new List<Vector4>();
//Step 3 - Blend all the lights!
foreach (ILight l in lights)
foreach (ILight Light in lights)
{
//Skip off or broken lights (TODO code broken light states)
if (l.LightState != LightState.On)
if (Light.LightState != LightState.On)
continue;
// LIGHT BLEND STAGE 1 - SIZING -- copys the light texture to a full screen rendertarget
var area = (LightArea)l.LightArea;
Vector2 blitPos;
var area = (LightArea)Light.LightArea;
//Set the drawing position.
blitPos = ClientWindowData.Singleton.WorldToScreen(area.LightPosition) - area.LightAreaSize * 0.5f;
Vector2 blitPos = CluwneLib.WorldToScreen(area.LightPosition) - area.LightAreaSize * 0.5f;
//Set shader parameters
var LightPositionData = new Vector4(blitPos.X / source.Width,
blitPos.Y / source.Height,
(float)source.Width / area.renderTarget.Width,
(float)source.Height / area.renderTarget.Height);
lightTextures.Add(area.renderTarget.Texture);
colors.Add(l.GetColorVec());
var LightPositionData = new Vector4(blitPos.X / screenShadows.Width,
blitPos.Y / screenShadows.Height,
(float)screenShadows.Width / area.RenderTarget.Width,
(float)screenShadows.Height / area.RenderTarget.Height);
lightTextures.Add(area.RenderTarget.Texture);
colors.Add(Light.GetColorVec());
positions.Add(LightPositionData);
}
int i = 0;
@@ -1170,12 +1233,12 @@ namespace SS14.Client.Services.State.States
{
if (fill)
{
for (int j = i; j < num_lights; j++)
for (int j = i; j < num_lights ; j++)
{
r_img[j] = black;
r_col[j] = Vector4.Zero;
r_pos[j] = new Vector4(0, 0, 1, 1);
}
i = num_lights;
draw = true;
@@ -1183,25 +1246,27 @@ namespace SS14.Client.Services.State.States
}
if (draw)
{
CluwneLib.CurrentRenderTarget = destination;
shadowIntermediate.BeginDrawing();
Lightmap.SetParameter("LightPosData", r_pos);
Lightmap.SetParameter("Colors", r_col);
Lightmap.SetParameter("light1", r_img[0]);
Lightmap.SetParameter("light2", r_img[1]);
Lightmap.SetParameter("light3", r_img[2]);
Lightmap.SetParameter("light4", r_img[3]);
Lightmap.SetParameter("light5", r_img[4]);
Lightmap.SetParameter("light6", r_img[5]);
Lightmap.SetParameter("SceneTexture", source.Texture);
Lightmap.setAsCurrentShader();
Lightmap.SetParameter("LightPosData", r_pos);
Lightmap.SetParameter("Colors", r_col);
Lightmap.SetParameter("light1", r_img[0]);
Lightmap.SetParameter("light2", r_img[1]);
Lightmap.SetParameter("light3", r_img[2]);
Lightmap.SetParameter("light4", r_img[3]);
Lightmap.SetParameter("light5", r_img[4]);
Lightmap.SetParameter("light6", r_img[5]);
Lightmap.SetParameter("SceneTexture", GLSLShader.CurrentTexture);
screenShadows.Blit(0, 0, screenShadows.Width, screenShadows.Height, Color.White, BlitterSizeMode.Crop);
source.Blit(0, 0, screenShadows.Width, screenShadows.Height, Color.White, BlitterSizeMode.Crop);
shadowIntermediate.EndDrawing();
// Blit the shadow image on top of the screen
//Swap rendertargets to set up for the next light
copy = source;
source = destination;
destination = copy;
copy = screenShadows;
screenShadows = shadowIntermediate;
shadowIntermediate = copy;
i = 0;
draw = false;
r_img = new Texture[num_lights];
@@ -1213,25 +1278,25 @@ namespace SS14.Client.Services.State.States
Texture l = lightTextures[0];
lightTextures.RemoveAt(0);
r_img[i] = l;
r_col[i] = colors[0];
colors.RemoveAt(0);
r_pos[i] = positions[0];
positions.RemoveAt(0);
i++;
}
if (i == num_lights)
draw = true;
if (i > 0 && i < num_lights && lightTextures.Count == 0)
//if I is equal to 6 draw
draw = true;
if (i > 0 && i < num_lights && lightTextures.Count == 0)
// If all light textures in lightTextures have been processed, fill = true
fill = true;
} while (lightTextures.Count > 0 || draw || fill);
CluwneLib.CurrentShader = null;
if (source != screenShadows)
{
CluwneLib.CurrentRenderTarget = screenShadows;
source.Blit(0, 0, source.Width, source.Height, Color.White, BlitterSizeMode.Crop);
}
CluwneLib.CurrentRenderTarget = null;
Lightmap.ResetCurrentShader();
shadowIntermediate.ResetCurrentRenderTarget(); // back to screen
}
private void CalculateSceneBatches(RectangleF vision)
@@ -1245,18 +1310,20 @@ namespace SS14.Client.Services.State.States
//Blur the player vision map
BlurPlayerVision();
_decalBatch.Begin();
_wallTopsBatch.Begin();
_floorBatch.Begin();
_wallBatch.Begin();
_gasBatch.Begin();
_decalBatch.BeginDrawing();
_wallTopsBatch.BeginDrawing();
_floorBatch.BeginDrawing();
_wallBatch.BeginDrawing();
_gasBatch.BeginDrawing();
DrawTiles(vision);
_floorBatch.End();
_decalBatch.End();
_wallTopsBatch.End();
_gasBatch.End();
_wallBatch.End();
_floorBatch.EndDrawing();
_decalBatch.EndDrawing();
_wallTopsBatch.EndDrawing();
_gasBatch.EndDrawing();
_wallBatch.EndDrawing();
_recalculateScene = false;
_redrawTiles = true;
_redrawOverlay = true;
@@ -1264,8 +1331,8 @@ namespace SS14.Client.Services.State.States
private void RenderPlayerVisionMap()
{
Vector2 blitPos;
if (bFullVision)
{
playerOcclusionTarget.Clear(Color.LightGray);
@@ -1274,18 +1341,16 @@ namespace SS14.Client.Services.State.States
if (bPlayerVision)
{
playerOcclusionTarget.Clear(Color.Black);
playerVision.Move(
PlayerManager.ControlledEntity.GetComponent<TransformComponent>(ComponentFamily.Transform).Position);
playerVision.Move(PlayerManager.ControlledEntity.GetComponent<TransformComponent>(ComponentFamily.Transform).Position);
LightArea area = GetLightArea(RadiusToShadowMapSize(playerVision.Radius));
area.LightPosition = playerVision.Position; // Set the light position
TileRef t = MapManager.GetTileRef(playerVision.Position);
TileRef TileReference = MapManager.GetTileRef(playerVision.Position);
if (t.Tile.TileDef.IsOpaque)
if (TileReference.Tile.TileDef.IsOpaque)
{
area.LightPosition = new Vector2(area.LightPosition.X,
t.Y +
MapManager.TileSize + 1);
area.LightPosition = new Vector2(area.LightPosition.X, TileReference.Y + MapManager.TileSize + 1);
}
@@ -1293,31 +1358,34 @@ namespace SS14.Client.Services.State.States
DrawWallsRelativeToLight(area); // Draw all shadowcasting stuff here in black
area.EndDrawingShadowCasters(); // End drawing to the light rendertarget
blitPos = ClientWindowData.Singleton.WorldToScreen(area.LightPosition) - area.LightAreaSize * 0.5f;
Vector2 blitPos = CluwneLib.WorldToScreen(area.LightPosition) - area.LightAreaSize * 0.5f;
if (debugWallOccluders)
{
RenderTarget previous = CluwneLib.CurrentRenderTarget;
CluwneLib.CurrentRenderTarget = _occluderDebugTarget;
_occluderDebugTarget.BeginDrawing();
_occluderDebugTarget.Clear(Color.White);
area.renderTarget.Blit(blitPos.X, blitPos.Y, area.renderTarget.Width, area.renderTarget.Height, Color.White,
BlitterSizeMode.Crop);
CluwneLib.CurrentRenderTarget = previous;
area.RenderTarget.Blit(blitPos.X, blitPos.Y, area.RenderTarget.Width, area.RenderTarget.Height, Color.White, BlitterSizeMode.Crop);
_occluderDebugTarget.EndDrawing();
}
shadowMapResolver.ResolveShadows(area.renderTarget.Texture, area.renderTarget, area.LightPosition, false,
IoCManager.Resolve<IResourceManager>().GetSprite("whitemask").Texture,
Vector4.Zero, new Vector4(1, 1, 1, 1)); // Calc shadows
CluwneLib.CurrentRenderTarget = playerOcclusionTarget; // Set to shadow rendertarget
shadowMapResolver.ResolveShadows(area, false, IoCManager.Resolve<IResourceManager>().GetSprite("whitemask").Texture); // Calc shadows
// area.renderTarget.SourceBlend = AlphaBlendOperation.One; //Additive blending
// area.renderTarget.DestinationBlend = AlphaBlendOperation.Zero; //Additive blending
area.renderTarget.Blit(blitPos.X, blitPos.Y, area.renderTarget.Width,
area.renderTarget.Height, Color.White, BlitterSizeMode.Crop);
// Draw the lights effects
// area.renderTarget.SourceBlend = AlphaBlendOperation.SourceAlpha; //reset blend mode
// area.renderTarget.DestinationBlend = AlphaBlendOperation.InverseSourceAlpha; //reset blend mode
playerOcclusionTarget.BeginDrawing(); // Set to shadow rendertarget
//area.renderTarget.SourceBlend = AlphaBlendOperation.One;
//area.renderTarget.DestinationBlend = AlphaBlendOperation.Zero;
area.RenderTarget.BlendSettings.ColorSrcFactor = BlendMode.Factor.One;
area.RenderTarget.BlendSettings.ColorDstFactor = BlendMode.Factor.Zero;
area.RenderTarget.Blit(blitPos.X, blitPos.Y, area.RenderTarget.Width,area.RenderTarget.Height, Color.White, BlitterSizeMode.Crop);
//area.renderTarget.SourceBlend = AlphaBlendOperation.SourceAlpha; //reset blend mode
//area.renderTarget.DestinationBlend = AlphaBlendOperation.InverseSourceAlpha; //reset blend mode
area.RenderTarget.BlendSettings.ColorDstFactor = BlendMode.Factor.SrcAlpha;
area.RenderTarget.BlendSettings.ColorDstFactor = BlendMode.Factor.OneMinusSrcAlpha;
playerOcclusionTarget.EndDrawing();
}
else
{
@@ -1328,8 +1396,7 @@ namespace SS14.Client.Services.State.States
// Draws all walls in the area around the light relative to it, and in black (test code, not pretty)
private void DrawWallsRelativeToLight(ILightArea area)
{
RectangleF lightArea = new RectangleF(area.LightPosition - (area.LightAreaSize / 2),
area.LightAreaSize);
RectangleF lightArea = new RectangleF(area.LightPosition , area.LightAreaSize);
var tiles = MapManager.GetWallsIntersecting(lightArea);
@@ -1356,19 +1423,19 @@ namespace SS14.Client.Services.State.States
var tiles = MapManager.GetTilesIntersecting(vision, false);
var walls = new List<TileRef>();
foreach (TileRef tr in tiles)
foreach (TileRef TileReference in tiles)
{
var t = tr.Tile;
var td = t.TileDef;
var Tile = TileReference.Tile;
var TileType = Tile.TileDef;
//t.RenderGas(WindowOrigin.X, WindowOrigin.Y, tilespacing, _gasBatch);
if (td.IsWall)
walls.Add(tr);
if (TileType.IsWall)
walls.Add(TileReference);
else
{
var point = ClientWindowData.Singleton.WorldToScreen(new PointF(tr.X, tr.Y));
td.Render(point.X, point.Y, _floorBatch);
td.RenderGas(point.X, point.Y, MapManager.TileSize, _gasBatch);
var point = CluwneLib.WorldToScreen(new PointF(TileReference.X, TileReference.Y));
TileType.Render(point.X, point.Y, _floorBatch);
TileType.RenderGas(point.X, point.Y, MapManager.TileSize, _gasBatch);
}
}
@@ -1380,7 +1447,7 @@ namespace SS14.Client.Services.State.States
var t = tr.Tile;
var td = t.TileDef;
var point = ClientWindowData.Singleton.WorldToScreen(new PointF(tr.X, tr.Y));
var point = CluwneLib.WorldToScreen(new PointF(tr.X, tr.Y));
td.Render(point.X, point.Y, _wallBatch);
td.RenderTop(point.X, point.Y, _wallTopsBatch);
}
@@ -1425,39 +1492,47 @@ namespace SS14.Client.Services.State.States
{
//Blur the light/shadow map
// BlurShadowMap();
BlurShadowMap();
//Render the scene and lights together to compose the lit scene
CluwneLib.CurrentRenderTarget = _composedSceneTarget;
CluwneLib.CurrentRenderTarget.Clear(Color.Black.ToSFMLColor());
CluwneLib.CurrentShader = LightblendTechnique["FinalLightBlend"];
Sprite outofview = IoCManager.Resolve<IResourceManager>().GetSprite("outofview");
float texratiox = CluwneLib.CurrentClippingViewport.Width / outofview.Texture.Size.X;
float texratioy = CluwneLib.CurrentClippingViewport.Height / outofview.Texture.Size.Y;
var maskProps = new Vector4(texratiox, texratioy, 0, 0);
_composedSceneTarget.BeginDrawing();
_composedSceneTarget.Clear(Color.Black);
LightblendTechnique["FinalLightBlend"].setAsCurrentShader();
Sprite outofview = IoCManager.Resolve<IResourceManager>().GetSprite("outofview");
float texratiox = CluwneLib.CurrentClippingViewport.Width / outofview.Texture.Size.X;
float texratioy = CluwneLib.CurrentClippingViewport.Height / outofview.Texture.Size.Y;
var maskProps = new Vector4(texratiox, texratioy, 0, 0);
LightblendTechnique["FinalLightBlend"].SetParameter("PlayerViewTexture", playerOcclusionTarget);
LightblendTechnique["FinalLightBlend"].SetParameter("OutOfViewTexture", outofview.Texture);
LightblendTechnique["FinalLightBlend"].SetParameter("MaskProps", maskProps);
LightblendTechnique["FinalLightBlend"].SetParameter("LightTexture", screenShadows);
LightblendTechnique["FinalLightBlend"].SetParameter("SceneTexture", _sceneTarget);
LightblendTechnique["FinalLightBlend"].SetParameter("AmbientLight", new Vector4(.05f, .05f, 0.05f, 1));
LightblendTechnique["FinalLightBlend"].SetParameter("PlayerViewTexture", playerOcclusionTarget);
LightblendTechnique["FinalLightBlend"].SetParameter("OutOfViewTexture", outofview.Texture);
LightblendTechnique["FinalLightBlend"].SetParameter("MaskProps", maskProps);
LightblendTechnique["FinalLightBlend"].SetParameter("LightTexture", GLSLShader.CurrentTexture);
LightblendTechnique["FinalLightBlend"].SetParameter("SceneTexture", _sceneTarget);
LightblendTechnique["FinalLightBlend"].SetParameter("AmbientLight", new Vector4(.05f, .05f, 0.05f, 1));
// Blit the shadow image on top of the screen
screenShadows.Blit(0, 0, screenShadows.Width, screenShadows.Height, Color.White, BlitterSizeMode.Crop);
LightblendTechnique["FinalLightBlend"].ResetCurrentShader();
_composedSceneTarget.EndDrawing();
screenShadows.Blit(0, 0, screenShadows.Width, screenShadows.Height, Color.White, BlitterSizeMode.Crop);
// Blit the shadow image on top of the screen
CluwneLib.CurrentShader = null;
CluwneLib.CurrentRenderTarget = null;
playerOcclusionTarget.Blit(0, 0, screenShadows.Width, screenShadows.Height, Color.White, BlitterSizeMode.Crop);
playerOcclusionTarget.ResetCurrentRenderTarget(); // set the rendertarget back to screen
playerOcclusionTarget.Blit(0, 0, screenShadows.Width, screenShadows.Height, Color.White, BlitterSizeMode.Crop); //draw playervision again
PlayerPostProcess();
//redraw composed scene
// _composedSceneTarget.Blit(0, 0, (uint)CluwneLib.CurrentClippingViewport.Width, (uint)CluwneLib.CurrentClippingViewport.Height, Color.White, BlitterSizeMode.Crop);
_composedSceneTarget.Blit(0, 0, (uint)CluwneLib.CurrentClippingViewport.Width, (uint)CluwneLib.CurrentClippingViewport.Height, Color.White, BlitterSizeMode.Crop);
screenShadows.Blit(0, 0, _tilesTarget.Width, _tilesTarget.Height, Color.White, BlitterSizeMode.Crop);
playerOcclusionTarget.Blit(0, 0, _tilesTarget.Width, _tilesTarget.Height, Color.White, BlitterSizeMode.Crop);
//old
// screenShadows.Blit(0, 0, _tilesTarget.Width, _tilesTarget.Height, Color.White, BlitterSizeMode.Crop);
// playerOcclusionTarget.Blit(0, 0, _tilesTarget.Width, _tilesTarget.Height, Color.White, BlitterSizeMode.Crop);
}
private void BlurShadowMap()
@@ -1492,14 +1567,14 @@ namespace SS14.Client.Services.State.States
}
}
private void CalculateLightArea(ILight l)
private void CalculateLightArea(ILight light)
{
ILightArea area = l.LightArea;
ILightArea area = light.LightArea;
if (area.Calculated)
return;
area.LightPosition = l.Position; //mousePosWorld; // Set the light position
TileRef t = MapManager.GetTileRef(l.Position);
area.LightPosition = light.Position; //mousePosWorld; // Set the light position
TileRef t = MapManager.GetTileRef(light.Position);
if (t.Tile.IsSpace)
return;
if (t.Tile.TileDef.IsOpaque)
@@ -1509,10 +1584,9 @@ namespace SS14.Client.Services.State.States
MapManager.TileSize + 1);
}
area.BeginDrawingShadowCasters(); // Start drawing to the light rendertarget
DrawWallsRelativeToLight(area); // Draw all shadowcasting stuff here in black
DrawWallsRelativeToLight(area); // Draw all shadowcasting stuff here in black
area.EndDrawingShadowCasters(); // End drawing to the light rendertarget
shadowMapResolver.ResolveShadows(area.renderTarget.Texture, area.renderTarget, area.LightPosition, true,
area.Mask.Texture, area.MaskProps, Vector4.One); // Calc shadows
shadowMapResolver.ResolveShadows((LightArea)area, true); // Calc shadows
area.Calculated = true;
}
@@ -99,14 +99,10 @@ namespace SS14.Client.Services.State.States
public void Render(FrameEventArgs e)
{
//public Vertex(Vector2f position, Color color, Vector2f texCoords);
RectangleShape test = new RectangleShape(new Vector2f(200, 200));
CluwneLib.CurrentRenderTarget.Clear();
CluwneLib.CurrentRenderTarget.Draw(test);
// CluwneLib.CurrentRenderTarget.Draw(625 , 5 , CluwneLib.CurrentRenderTarget.Size.X - 625 - 5 , CluwneLib.CurrentRenderTarget.Size.Y- 5 - 6, Color.SlateGray);
// CluwneLib.CurrentRenderTarget.FilledRectangle(5, 220, 600, _lobbyChat.Position.Y - 250 - 5, Color.SlateGray);
_lobbyText.Position = new Vector2(10, 10);
_lobbyText.Text = "Server: " + _serverName;
_lobbyText.Draw();
@@ -74,6 +74,7 @@ namespace SS14.Client.Services.State.States
_btnExit.Clicked += _buttExit_Clicked;
_txtConnect = new Textbox(100, ResourceManager) {Text = ConfigurationManager.GetServerAddress()};
_txtConnect.Position = new Point(_Width / 3, _Height / 2);
_txtConnect.OnSubmit += ConnectTextboxOnSubmit;
Assembly assembly = Assembly.GetExecutingAssembly();
+21 -9
View File
@@ -22,9 +22,12 @@ namespace SS14.Client.Services.State.States
private SpriteBatch _testBatch;
private CluwneSprite _floorTile;
private List<TextSprite> _text;
private uint updatecount=0;
private uint updatecount=10;
private GaussianBlur blur;
private RenderImage test;
private RenderImage test;
private TextSprite FPS;
public TestState (IDictionary<Type, object> managers) : base(managers)
{
@@ -48,6 +51,12 @@ namespace SS14.Client.Services.State.States
VersionText.Text = "( Running SFML v2.0 ) " ;
_text.Add(VersionText);
FPS = new TextSprite("FPSTEST", "X", ResourceManager.GetFont("CALIBRI"));
FPS.Position = new Vector2(600, 600);
FPS.Color = Color.White;
_text.Add(FPS);
TextSprite ProjNotDeadText = new TextSprite("TEST", "ProjNoDed", ResourceManager.GetFont("CALIBRI"));
ProjNotDeadText.Position = new Shared.Maths.Vector2(512, 700);
ProjNotDeadText.Color = Color.Gold;
@@ -116,24 +125,27 @@ namespace SS14.Client.Services.State.States
if (++updatecount % 10==0) {
// but only every 10 frames, to test batch-reuse.
// The first 9 frames won't have it drawn, to test empty batches.
_testBatch.Begin();
for(int y=0;y<5; y++)
for (int x = 0; x < 5; x++)
_testBatch.BeginDrawing();
for(int y = 0; y < 50; y++)
for (int x = 0; x < 50; x++)
{
_floorTile.SetPosition(x * _floorTile.Width, y * _floorTile.Height);
_testBatch.Draw(_floorTile);
}
_testBatch.End();
_testBatch.EndDrawing();
}
}
public void Render(FrameEventArgs e)
{
IntRect rect = new IntRect(0, 0, 1280,768 );
test.BeginDrawing();
if (_testBatch.Count > 0)
CluwneLib.CurrentRenderTarget.Draw(_testBatch);
test.Draw(_testBatch);
foreach (CluwneSprite d in _sprites)
{
d.Draw();
@@ -146,7 +158,7 @@ namespace SS14.Client.Services.State.States
{
g.Render();
}
test.EndDrawing();
test.Blit(0, 0, test.Width, test.Height ,Color.White, BlitterSizeMode.Crop);
@@ -75,6 +75,7 @@ namespace SS14.Client.Services.UserInterface.Components
public override void Update(float frameTime)
{
_clientAreaLeft = new Rectangle(Position, new Size((int) _textboxLeft.Width, (int) _textboxLeft.Height));
_clientAreaMain = new Rectangle(new Point(_clientAreaLeft.Right, Position.Y),
new Size(Width, (int) _textboxMain.Height));
_clientAreaRight = new Rectangle(new Point(_clientAreaMain.Right, Position.Y),
@@ -86,6 +87,8 @@ namespace SS14.Client.Services.UserInterface.Components
Label.Position = new Point(_clientAreaLeft.Right,
Position.Y + (int) (ClientArea.Height/2f) - (int) (Label.Height/2f));
_caretPos = Label.Text.Length;
if (Focus)
{
blinkCount += 1*frameTime;
@@ -107,9 +110,9 @@ namespace SS14.Client.Services.UserInterface.Components
_textboxRight.Draw(_clientAreaRight);
if (Focus && blinkCount <= 0.25f)
//Draw Textbox
CluwneLib.drawRectangle(Label.Position.X+ _caretPos - _caretWidth, Label.Position.Y + (Label.Height/2f) - (_caretHeight/2f),_caretWidth, _caretHeight, Color.FromArgb(255,255,250));
// CluwneLib.CurrentRenderTarget.Draw(_caretPos - _caretWidth, Label.Position.Y + (Label.Height/2f) - (_caretHeight/2f),_caretWidth, _caretHeight, new Color(255,255,250));
if (drawColor != Color.White)
{