Improve performance, fix grass issue

This commit is contained in:
Drew DeVault 2015-09-07 17:25:14 -04:00
parent 988d2077a2
commit 79e95e2083
15 changed files with 138 additions and 14 deletions

View File

@ -20,6 +20,8 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
@ -28,6 +30,16 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Optimized Debug|AnyCPU' ">
<Optimize>true</Optimize>
<OutputPath>bin\Optimized Debug</OutputPath>
<WarningLevel>4</WarningLevel>
<DefineConstants>DEBUG;</DefineConstants>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />

View File

@ -10,7 +10,6 @@
<OutputType>WinExe</OutputType>
<RootNamespace>TrueCraft.Client</RootNamespace>
<AssemblyName>TrueCraft.Client</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<NoWin32Manifest>False</NoWin32Manifest>
<SignAssembly>False</SignAssembly>
<DelaySign>False</DelaySign>
@ -22,6 +21,7 @@
<DebugType>Full</DebugType>
<IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
<WarningLevel>4</WarningLevel>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DefineConstants>$(DefineConstants);WINDOWS</DefineConstants>
@ -47,6 +47,26 @@
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<Commandlineparameters>localhost TestUser</Commandlineparameters>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<DebugType>
</DebugType>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Optimized Debug|AnyCPU' ">
<DebugType>
</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Optimized Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
<ItemGroup>
<Reference Include="Ionic.Zip.Reduced">

View File

@ -20,6 +20,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>full</DebugType>
@ -28,6 +29,12 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Optimized Debug|AnyCPU' ">
<Optimize>false</Optimize>
<OutputPath>bin\Optimized Debug</OutputPath>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />

View File

@ -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();
}
/// <summary>
@ -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()

View File

@ -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;
}
}

View File

@ -30,6 +30,13 @@
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Optimized Debug|AnyCPU' ">
<Optimize>true</Optimize>
<OutputPath>bin\Optimized Debug</OutputPath>
<WarningLevel>4</WarningLevel>
<DefineConstants>DEBUG;</DefineConstants>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="Ionic.Zip.Reduced">
@ -358,6 +365,10 @@
<Project>{4488498D-976D-4DA3-BF72-109531AF0488}</Project>
<Name>fNbt</Name>
</ProjectReference>
<ProjectReference Include="..\TrueCraft.Profiling\TrueCraft.Profiling.csproj">
<Project>{BCA0E139-CF47-43B3-9DC9-D4611C0A2AAD}</Project>
<Name>TrueCraft.Profiling</Name>
</ProjectReference>
</ItemGroup>
<ProjectExtensions>
<MonoDevelop>

View File

@ -5,6 +5,7 @@ using TrueCraft.API.Logging;
using TrueCraft.API;
using System.Net;
using TrueCraft.Core.Logging;
using TrueCraft;
namespace TrueCraft.Launcher.Singleplayer
{

View File

@ -20,6 +20,8 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
@ -28,6 +30,8 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
@ -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 </PostBuildEvent>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Optimized Debug|AnyCPU' ">
<Optimize>true</Optimize>
<OutputPath>bin\Optimized Debug</OutputPath>
<WarningLevel>4</WarningLevel>
<DefineConstants>DEBUG;</DefineConstants>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
</Project>

View File

@ -12,6 +12,7 @@ namespace TrueCraft.Profiling
Stopwatch = new Stopwatch();
EnabledBuckets = new List<string>();
ActiveTimers = new Stack<ActiveTimer>();
LogLag = false;
Stopwatch.Start();
}
@ -19,6 +20,8 @@ namespace TrueCraft.Profiling
private static List<string> EnabledBuckets { get; set; }
private static Stack<ActiveTimer> 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);
}
}

View File

@ -20,6 +20,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<Optimize>true</Optimize>
@ -27,6 +28,15 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Optimized Debug|AnyCPU' ">
<Optimize>true</Optimize>
<OutputPath>bin\Optimized Debug</OutputPath>
<WarningLevel>4</WarningLevel>
<DefineConstants>DEBUG;</DefineConstants>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />

View File

@ -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

View File

@ -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

View File

@ -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);
}

View File

@ -16,6 +16,9 @@ namespace TrueCraft
[YamlMember(Alias = "buckets")]
public string Buckets { get; set; }
[YamlMember(Alias = "lag")]
public bool Lag { get; set; }
}
public DebugConfiguration()

View File

@ -18,11 +18,23 @@
<DebugSymbols>true</DebugSymbols>
<ConsolePause>false</ConsolePause>
<DefineConstants>DEBUG;</DefineConstants>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<WarningLevel>4</WarningLevel>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Optimized Debug|AnyCPU' ">
<Optimize>true</Optimize>
<OutputPath>bin\Optimized Debug</OutputPath>
<WarningLevel>4</WarningLevel>
<DefineConstants>DEBUG;</DefineConstants>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />