diff --git a/TrueCraft.API/TrueCraft.API.csproj b/TrueCraft.API/TrueCraft.API.csproj
index 8588179..85a1f40 100644
--- a/TrueCraft.API/TrueCraft.API.csproj
+++ b/TrueCraft.API/TrueCraft.API.csproj
@@ -20,6 +20,8 @@
prompt
4
false
+ v4.5
+ true
none
@@ -28,6 +30,16 @@
prompt
4
false
+ v4.5
+ true
+
+
+ true
+ bin\Optimized Debug
+ 4
+ DEBUG;
+ true
+ true
diff --git a/TrueCraft.Client/TrueCraft.Client.csproj b/TrueCraft.Client/TrueCraft.Client.csproj
index aab8588..e41111a 100644
--- a/TrueCraft.Client/TrueCraft.Client.csproj
+++ b/TrueCraft.Client/TrueCraft.Client.csproj
@@ -10,7 +10,6 @@
WinExe
TrueCraft.Client
TrueCraft.Client
- v4.5
False
False
False
@@ -22,6 +21,7 @@
Full
obj\$(Configuration)\
4
+ v4.5
$(DefineConstants);WINDOWS
@@ -47,6 +47,26 @@
localhost TestUser
+ v4.5
+
+
+
+
+ v4.5
+
+
+ v4.5
+
+
+ v4.5
+
+
+
+
+ true
+ bin\Optimized Debug
+ DEBUG;
+ true
diff --git a/TrueCraft.Core.Test/TrueCraft.Core.Test.csproj b/TrueCraft.Core.Test/TrueCraft.Core.Test.csproj
index 6b4c459..6847fc7 100644
--- a/TrueCraft.Core.Test/TrueCraft.Core.Test.csproj
+++ b/TrueCraft.Core.Test/TrueCraft.Core.Test.csproj
@@ -20,6 +20,7 @@
prompt
4
false
+ v4.5
full
@@ -28,6 +29,12 @@
prompt
4
false
+ v4.5
+
+
+ false
+ bin\Optimized Debug
+ 4
diff --git a/TrueCraft.Core/Lighting/WorldLighting.cs b/TrueCraft.Core/Lighting/WorldLighting.cs
index 627c461..fa246ac 100644
--- a/TrueCraft.Core/Lighting/WorldLighting.cs
+++ b/TrueCraft.Core/Lighting/WorldLighting.cs
@@ -5,6 +5,7 @@ using TrueCraft.API.Logic;
using TrueCraft.API;
using System.Collections.Generic;
using System.Diagnostics;
+using TrueCraft.Profiling;
namespace TrueCraft.Core.Lighting
{
@@ -113,12 +114,14 @@ namespace TrueCraft.Core.Lighting
var chunk = World.FindChunk((Coordinates3D)op.Box.Center, generate: false);
if (chunk == null || !chunk.TerrainPopulated)
return;
+ Profiler.Start("lighting.box");
for (int x = (int)op.Box.Min.X; x < (int)op.Box.Max.X; x++)
for (int z = (int)op.Box.Min.Z; z < (int)op.Box.Max.Z; z++)
for (int y = (int)op.Box.Max.Y - 1; y >= (int)op.Box.Min.Y; y--)
{
LightVoxel(x, y, z, op);
}
+ Profiler.Done();
}
///
@@ -161,6 +164,8 @@ namespace TrueCraft.Core.Lighting
if (chunk == null || !chunk.TerrainPopulated) // Move on if this chunk is empty
return;
+ Profiler.Start("lighting.voxel");
+
var id = World.GetBlockID(coords);
var provider = BlockRepository.GetBlockProvider(id);
@@ -235,6 +240,7 @@ namespace TrueCraft.Core.Lighting
if (z + 1 >= op.Box.Max.Z)
PropegateLightEvent(x, y, z + 1, propegated, op);
}
+ Profiler.Done();
}
public bool TryLightNext()
diff --git a/TrueCraft.Core/Logic/Blocks/GrassBlock.cs b/TrueCraft.Core/Logic/Blocks/GrassBlock.cs
index fe0b194..42db617 100644
--- a/TrueCraft.Core/Logic/Blocks/GrassBlock.cs
+++ b/TrueCraft.Core/Logic/Blocks/GrassBlock.cs
@@ -104,9 +104,10 @@ namespace TrueCraft.Core.Logic.Blocks
var _block = world.GetBlockLight(candidate + Coordinates3D.Up);
if (_sky < 4 && _block < 4)
continue;
- IChunk chunk = world.FindChunk(candidate);
+ IChunk chunk;
+ var _candidate = world.FindBlockPosition(candidate, out chunk);
bool grow = true;
- for (int y = candidate.Y; y < chunk.GetHeight((byte)candidate.X, (byte)candidate.Z); y++)
+ for (int y = candidate.Y; y < chunk.GetHeight((byte)_candidate.X, (byte)_candidate.Z); y++)
{
var b = world.GetBlockID(new Coordinates3D(candidate.X, y, candidate.Z));
var p = world.BlockRepository.GetBlockProvider(b);
@@ -116,10 +117,13 @@ namespace TrueCraft.Core.Logic.Blocks
break;
}
}
- world.SetBlockID(candidate, GrassBlock.BlockID);
- server.Scheduler.ScheduleEvent("grass", chunk,
- TimeSpan.FromSeconds(MathHelper.Random.Next(MinGrowthTime, MaxGrowthTime)),
- s => TrySpread(candidate, world, server));
+ if (grow)
+ {
+ world.SetBlockID(candidate, GrassBlock.BlockID);
+ server.Scheduler.ScheduleEvent("grass", chunk,
+ TimeSpan.FromSeconds(MathHelper.Random.Next(MinGrowthTime, MaxGrowthTime)),
+ s => TrySpread(candidate, world, server));
+ }
break;
}
}
diff --git a/TrueCraft.Core/TrueCraft.Core.csproj b/TrueCraft.Core/TrueCraft.Core.csproj
index 92ee33f..83ef5d1 100644
--- a/TrueCraft.Core/TrueCraft.Core.csproj
+++ b/TrueCraft.Core/TrueCraft.Core.csproj
@@ -30,6 +30,13 @@
4
false
+
+ true
+ bin\Optimized Debug
+ 4
+ DEBUG;
+ true
+
@@ -358,6 +365,10 @@
{4488498D-976D-4DA3-BF72-109531AF0488}
fNbt
+
+ {BCA0E139-CF47-43B3-9DC9-D4611C0A2AAD}
+ TrueCraft.Profiling
+
diff --git a/TrueCraft.Launcher/Singleplayer/SingleplayerServer.cs b/TrueCraft.Launcher/Singleplayer/SingleplayerServer.cs
index aeb16fd..9cbb6e7 100644
--- a/TrueCraft.Launcher/Singleplayer/SingleplayerServer.cs
+++ b/TrueCraft.Launcher/Singleplayer/SingleplayerServer.cs
@@ -5,6 +5,7 @@ using TrueCraft.API.Logging;
using TrueCraft.API;
using System.Net;
using TrueCraft.Core.Logging;
+using TrueCraft;
namespace TrueCraft.Launcher.Singleplayer
{
diff --git a/TrueCraft.Launcher/TrueCraft.Launcher.csproj b/TrueCraft.Launcher/TrueCraft.Launcher.csproj
index fe94b94..64d758c 100644
--- a/TrueCraft.Launcher/TrueCraft.Launcher.csproj
+++ b/TrueCraft.Launcher/TrueCraft.Launcher.csproj
@@ -20,6 +20,8 @@
prompt
4
false
+ v4.5
+ true
none
@@ -28,6 +30,8 @@
prompt
4
false
+ v4.5
+ true
@@ -115,4 +119,12 @@ copy $(SolutionDir)packages\MonoGame.Framework.Linux.3.4.0.459\lib\net40\MonoGam
copy $(SolutionDir)packages\MonoGame.Framework.WindowsGL.3.4.0.459\lib\net40\MonoGame.Framework.dll $(TargetDir)MonoGame.Framework.Windows.dll
copy $(SolutionDir)packages\MonoGame.Framework.MacOS.3.4.0.459\lib\net40\MonoGame.Framework.dll $(TargetDir)MonoGame.Framework.MacOS.dll
+
+ true
+ bin\Optimized Debug
+ 4
+ DEBUG;
+ true
+ true
+
diff --git a/TrueCraft.Profiling/Profiler.cs b/TrueCraft.Profiling/Profiler.cs
index bc1bbec..2616b3f 100644
--- a/TrueCraft.Profiling/Profiler.cs
+++ b/TrueCraft.Profiling/Profiler.cs
@@ -12,6 +12,7 @@ namespace TrueCraft.Profiling
Stopwatch = new Stopwatch();
EnabledBuckets = new List();
ActiveTimers = new Stack();
+ LogLag = false;
Stopwatch.Start();
}
@@ -19,6 +20,8 @@ namespace TrueCraft.Profiling
private static List EnabledBuckets { get; set; }
private static Stack ActiveTimers { get; set; }
+ public static bool LogLag { get; set; }
+
private struct ActiveTimer
{
public long Started, Finished;
@@ -49,21 +52,23 @@ namespace TrueCraft.Profiling
}
[Conditional("DEBUG")]
- public static void Done()
+ public static void Done(long lag = -1)
{
if (ActiveTimers.Count > 0)
{
var timer = ActiveTimers.Pop();
timer.Finished = Stopwatch.ElapsedTicks;
+ double elapsed = (timer.Finished - timer.Started) / 10000.0;
for (int i = 0; i < EnabledBuckets.Count; i++)
{
if (Match(EnabledBuckets[i], timer.Bucket))
{
- Console.WriteLine("{0} took {1}ms", timer.Bucket,
- (timer.Finished - timer.Started) / 10000.0);
+ Console.WriteLine("{0} took {1}ms", timer.Bucket, elapsed);
break;
}
}
+ if (LogLag && lag != -1 && elapsed > lag)
+ Console.WriteLine("{0} is lagging by {1}ms", timer.Bucket, elapsed);
}
}
diff --git a/TrueCraft.Profiling/TrueCraft.Profiling.csproj b/TrueCraft.Profiling/TrueCraft.Profiling.csproj
index 88436ea..15d4329 100644
--- a/TrueCraft.Profiling/TrueCraft.Profiling.csproj
+++ b/TrueCraft.Profiling/TrueCraft.Profiling.csproj
@@ -20,6 +20,7 @@
prompt
4
false
+ true
true
@@ -27,6 +28,15 @@
prompt
4
false
+ true
+
+
+ true
+ bin\Optimized Debug
+ 4
+ DEBUG;
+ true
+ true
diff --git a/TrueCraft.sln b/TrueCraft.sln
index 6fb1a8e..231ceac 100644
--- a/TrueCraft.sln
+++ b/TrueCraft.sln
@@ -23,38 +23,55 @@ Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
+ Optimized Debug|Any CPU = Optimized Debug|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4488498D-976D-4DA3-BF72-109531AF0488}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4488498D-976D-4DA3-BF72-109531AF0488}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {4488498D-976D-4DA3-BF72-109531AF0488}.Optimized Debug|Any CPU.ActiveCfg = Optimized Debug|Any CPU
+ {4488498D-976D-4DA3-BF72-109531AF0488}.Optimized Debug|Any CPU.Build.0 = Optimized Debug|Any CPU
{4488498D-976D-4DA3-BF72-109531AF0488}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4488498D-976D-4DA3-BF72-109531AF0488}.Release|Any CPU.Build.0 = Release|Any CPU
{6604F17A-552E-405D-B327-37C8B1648C86}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6604F17A-552E-405D-B327-37C8B1648C86}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {6604F17A-552E-405D-B327-37C8B1648C86}.Optimized Debug|Any CPU.ActiveCfg = Optimized Debug|Any CPU
+ {6604F17A-552E-405D-B327-37C8B1648C86}.Optimized Debug|Any CPU.Build.0 = Optimized Debug|Any CPU
{6604F17A-552E-405D-B327-37C8B1648C86}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6604F17A-552E-405D-B327-37C8B1648C86}.Release|Any CPU.Build.0 = Release|Any CPU
{A6516869-A2FB-4E31-85C8-2285490CB32C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A6516869-A2FB-4E31-85C8-2285490CB32C}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {A6516869-A2FB-4E31-85C8-2285490CB32C}.Optimized Debug|Any CPU.ActiveCfg = Optimized Debug|Any CPU
+ {A6516869-A2FB-4E31-85C8-2285490CB32C}.Optimized Debug|Any CPU.Build.0 = Optimized Debug|Any CPU
{A6516869-A2FB-4E31-85C8-2285490CB32C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A6516869-A2FB-4E31-85C8-2285490CB32C}.Release|Any CPU.Build.0 = Release|Any CPU
{BCA0E139-CF47-43B3-9DC9-D4611C0A2AAD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BCA0E139-CF47-43B3-9DC9-D4611C0A2AAD}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {BCA0E139-CF47-43B3-9DC9-D4611C0A2AAD}.Optimized Debug|Any CPU.ActiveCfg = Optimized Debug|Any CPU
+ {BCA0E139-CF47-43B3-9DC9-D4611C0A2AAD}.Optimized Debug|Any CPU.Build.0 = Optimized Debug|Any CPU
{BCA0E139-CF47-43B3-9DC9-D4611C0A2AAD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BCA0E139-CF47-43B3-9DC9-D4611C0A2AAD}.Release|Any CPU.Build.0 = Release|Any CPU
{BCFDCD93-C23E-49E6-9767-A887B3C2A709}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BCFDCD93-C23E-49E6-9767-A887B3C2A709}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {BCFDCD93-C23E-49E6-9767-A887B3C2A709}.Optimized Debug|Any CPU.ActiveCfg = Optimized Debug|Any CPU
+ {BCFDCD93-C23E-49E6-9767-A887B3C2A709}.Optimized Debug|Any CPU.Build.0 = Optimized Debug|Any CPU
{BCFDCD93-C23E-49E6-9767-A887B3C2A709}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BCFDCD93-C23E-49E6-9767-A887B3C2A709}.Release|Any CPU.Build.0 = Release|Any CPU
{C1C47EF5-2D8A-4231-AAA8-F651F52F480E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C1C47EF5-2D8A-4231-AAA8-F651F52F480E}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {C1C47EF5-2D8A-4231-AAA8-F651F52F480E}.Optimized Debug|Any CPU.ActiveCfg = Optimized Debug|Any CPU
+ {C1C47EF5-2D8A-4231-AAA8-F651F52F480E}.Optimized Debug|Any CPU.Build.0 = Optimized Debug|Any CPU
{C1C47EF5-2D8A-4231-AAA8-F651F52F480E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C1C47EF5-2D8A-4231-AAA8-F651F52F480E}.Release|Any CPU.Build.0 = Release|Any CPU
{FA4BE9A3-DBF0-4380-BA2B-FFAA71C4706D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FA4BE9A3-DBF0-4380-BA2B-FFAA71C4706D}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {FA4BE9A3-DBF0-4380-BA2B-FFAA71C4706D}.Optimized Debug|Any CPU.ActiveCfg = Optimized Debug|Any CPU
+ {FA4BE9A3-DBF0-4380-BA2B-FFAA71C4706D}.Optimized Debug|Any CPU.Build.0 = Optimized Debug|Any CPU
{FA4BE9A3-DBF0-4380-BA2B-FFAA71C4706D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FA4BE9A3-DBF0-4380-BA2B-FFAA71C4706D}.Release|Any CPU.Build.0 = Release|Any CPU
{FEE55B54-91B0-4325-A2C3-D576C0B7A81F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FEE55B54-91B0-4325-A2C3-D576C0B7A81F}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {FEE55B54-91B0-4325-A2C3-D576C0B7A81F}.Optimized Debug|Any CPU.ActiveCfg = Optimized Debug|Any CPU
+ {FEE55B54-91B0-4325-A2C3-D576C0B7A81F}.Optimized Debug|Any CPU.Build.0 = Optimized Debug|Any CPU
{FEE55B54-91B0-4325-A2C3-D576C0B7A81F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FEE55B54-91B0-4325-A2C3-D576C0B7A81F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
diff --git a/TrueCraft/EventScheduler.cs b/TrueCraft/EventScheduler.cs
index 4b92366..5833b1f 100644
--- a/TrueCraft/EventScheduler.cs
+++ b/TrueCraft/EventScheduler.cs
@@ -86,9 +86,11 @@ namespace TrueCraft
}
if (e.When > start)
break; // List is sorted, we can exit early
+ if (start > Stopwatch.ElapsedTicks + 200000)
+ break; // We're falling behind
}
}
- Profiler.Done();
+ Profiler.Done(20);
}
private struct ScheduledEvent
diff --git a/TrueCraft/MultiplayerServer.cs b/TrueCraft/MultiplayerServer.cs
index 4af7dce..7159d06 100644
--- a/TrueCraft/MultiplayerServer.cs
+++ b/TrueCraft/MultiplayerServer.cs
@@ -221,16 +221,18 @@ namespace TrueCraft
{
int _x = chunk.Coordinates.X * Chunk.Width;
int _z = chunk.Coordinates.Z * Chunk.Depth;
+ Coordinates3D coords, _coords;
for (byte x = 0; x < Chunk.Width; x++)
{
for (byte z = 0; z < Chunk.Depth; z++)
{
for (int y = 0; y < chunk.GetHeight(x, z); y++)
{
- var coords = new Coordinates3D(_x + x, y, _z + z);
- var id = world.GetBlockID(coords);
+ _coords.X = x; _coords.Y = y; _coords.Z = z;
+ var id = chunk.GetBlockID(_coords);
if (id == 0)
continue;
+ coords.X = _x + x; coords.Y = y; coords.Z = _z + z;
var provider = BlockRepository.GetBlockProvider(id);
provider.BlockLoadedFromChunk(coords, this, world);
}
@@ -398,7 +400,7 @@ namespace TrueCraft
ScheduleUpdatesForChunk(t.Item1, t.Item2);
Profiler.Done();
- Profiler.Done();
+ Profiler.Done(MillisecondsPerTick);
EnvironmentWorker.Change(MillisecondsPerTick, 0);
}
diff --git a/TrueCraft/ServerConfiguration.cs b/TrueCraft/ServerConfiguration.cs
index d2160e8..3df8b54 100644
--- a/TrueCraft/ServerConfiguration.cs
+++ b/TrueCraft/ServerConfiguration.cs
@@ -16,6 +16,9 @@ namespace TrueCraft
[YamlMember(Alias = "buckets")]
public string Buckets { get; set; }
+
+ [YamlMember(Alias = "lag")]
+ public bool Lag { get; set; }
}
public DebugConfiguration()
diff --git a/TrueCraft/TrueCraft.csproj b/TrueCraft/TrueCraft.csproj
index 6199a9b..a242e00 100644
--- a/TrueCraft/TrueCraft.csproj
+++ b/TrueCraft/TrueCraft.csproj
@@ -18,11 +18,23 @@
true
false
DEBUG;
+ v4.5
+ true
true
bin\Release
4
+ v4.5
+ true
+
+
+ true
+ bin\Optimized Debug
+ 4
+ DEBUG;
+ true
+ true