Merge pull request #190 from yankejustin/Performance

Performance
This commit is contained in:
Drew DeVault 2015-08-07 15:05:04 -04:00
commit 003f6e60f5
4 changed files with 45 additions and 23 deletions

View File

@ -252,11 +252,14 @@ namespace TrueCraft.API
{
if (Empty)
return "(Empty)";
string result = "ID: " + ID;
if (Count != 1) result += "; Count: " + Count;
if (Metadata != 0) result += "; Metadata: " + Metadata;
if (Nbt != null) result += Environment.NewLine + Nbt.ToString();
return "(" + result + ")";
StringBuilder resultBuilder = new StringBuilder("ID: " + ID);
if (Count != 1) resultBuilder.Append("; Count: " + Count);
if (Metadata != 0) resultBuilder.Append("; Metadata: " + Metadata);
if (Nbt != null) resultBuilder.Append(Environment.NewLine + Nbt.ToString());
return "(" + resultBuilder.ToString() + ")";
}
/// <summary>

View File

@ -94,18 +94,29 @@ namespace TrueCraft.API
Vector3 maxT = new Vector3(-1.0f);
//Vector3 minT = new Vector3(-1.0f);
//calcul intersection with each faces
if (Position.X < box.Min.X && Direction.X != 0.0f)
maxT.X = (box.Min.X - Position.X) / Direction.X;
else if (Position.X > box.Max.X && Direction.X != 0.0f)
maxT.X = (box.Max.X - Position.X) / Direction.X;
if (Position.Y < box.Min.Y && Direction.Y != 0.0f)
maxT.Y = (box.Min.Y - Position.Y) / Direction.Y;
else if (Position.Y > box.Max.Y && Direction.Y != 0.0f)
maxT.Y = (box.Max.Y - Position.Y) / Direction.Y;
if (Position.Z < box.Min.Z && Direction.Z != 0.0f)
maxT.Z = (box.Min.Z - Position.Z) / Direction.Z;
else if (Position.Z > box.Max.Z && Direction.Z != 0.0f)
maxT.Z = (box.Max.Z - Position.Z) / Direction.Z;
if (Direction.X != 0.0f)
{
if (Position.X < box.Min.X)
maxT.X = (box.Min.X - Position.X) / Direction.X;
else if (Position.X > box.Max.X)
maxT.X = (box.Max.X - Position.X) / Direction.X;
}
if (Direction.Y != 0.0f)
{
if (Position.Y < box.Min.Y)
maxT.Y = (box.Min.Y - Position.Y) / Direction.Y;
else if (Position.Y > box.Max.Y)
maxT.Y = (box.Max.Y - Position.Y) / Direction.Y;
}
if (Direction.Z != 0.0f)
{
if (Position.Z < box.Min.Z)
maxT.Z = (box.Min.Z - Position.Z) / Direction.Z;
else if (Position.Z > box.Max.Z)
maxT.Z = (box.Max.Z - Position.Z) / Direction.Z;
}
//get the maximum maxT
if (maxT.X > maxT.Y && maxT.X > maxT.Z)

View File

@ -73,6 +73,14 @@ namespace TrueCraft.Client.Rendering
using (var contents = File.OpenRead(Path.Combine(contentManager.RootDirectory, definitionPath)))
_definition = FontLoader.Load(contents);
if (_textures != null)
{
for (int i = 0; i < _textures.Length; i++)
{
_textures[i].Dispose();
}
}
// We need to support multiple texture pages for more than plain ASCII text.
_textures = new Texture2D[_definition.Pages.Count];
for (int i = 0; i < _definition.Pages.Count; i++)

View File

@ -101,11 +101,12 @@ namespace TrueCraft.Client.Rendering
{
try
{
var ms = new MemoryStream();
CopyStream(stream, ms);
ms.Seek(0, SeekOrigin.Begin);
AddTexture(key, new PngReader().Read(ms, Device));
ms.Dispose();
using (var ms = new MemoryStream())
{
CopyStream(stream, ms);
ms.Seek(0, SeekOrigin.Begin);
AddTexture(key, new PngReader().Read(ms, Device));
}
}
catch (Exception ex) { Console.WriteLine("Exception occured while loading {0} from texture pack:\n\n{1}", key, ex); }
}
@ -184,7 +185,6 @@ namespace TrueCraft.Client.Rendering
foreach (var pair in Customs)
pair.Value.Dispose();
Customs.Clear();
Customs = null;
Device = null;
IsDisposed = true;