Skip to content

Commit 9fd931c

Browse files
authored
Merge pull request #10 from LambdaSix/Feature_CoordinateRewrite
Feature coordinate rewrite
2 parents 90f4aa7 + e03e1e0 commit 9fd931c

19 files changed

+871
-434
lines changed

InfiniMap.Test/InfiniMap.Test.csproj

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<PropertyGroup>
44
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
55
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@@ -10,8 +10,9 @@
1010
<AppDesignerFolder>Properties</AppDesignerFolder>
1111
<RootNamespace>InfiniMap.Test</RootNamespace>
1212
<AssemblyName>InfiniMap.Test</AssemblyName>
13-
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
13+
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
1414
<FileAlignment>512</FileAlignment>
15+
<TargetFrameworkProfile />
1516
</PropertyGroup>
1617
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1718
<DebugSymbols>true</DebugSymbols>
@@ -21,6 +22,7 @@
2122
<DefineConstants>DEBUG;TRACE</DefineConstants>
2223
<ErrorReport>prompt</ErrorReport>
2324
<WarningLevel>4</WarningLevel>
25+
<Prefer32Bit>false</Prefer32Bit>
2426
</PropertyGroup>
2527
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
2628
<DebugType>pdbonly</DebugType>
@@ -29,6 +31,7 @@
2931
<DefineConstants>TRACE</DefineConstants>
3032
<ErrorReport>prompt</ErrorReport>
3133
<WarningLevel>4</WarningLevel>
34+
<Prefer32Bit>false</Prefer32Bit>
3235
</PropertyGroup>
3336
<ItemGroup>
3437
<Reference Include="nunit.framework, Version=3.4.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
@@ -37,13 +40,18 @@
3740
</Reference>
3841
<Reference Include="System" />
3942
<Reference Include="System.Core" />
43+
<Reference Include="System.ValueTuple, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
44+
<HintPath>..\packages\System.ValueTuple.4.3.0\lib\netstandard1.0\System.ValueTuple.dll</HintPath>
45+
<Private>True</Private>
46+
</Reference>
4047
<Reference Include="System.Xml.Linq" />
4148
<Reference Include="System.Data.DataSetExtensions" />
4249
<Reference Include="Microsoft.CSharp" />
4350
<Reference Include="System.Data" />
4451
<Reference Include="System.Xml" />
4552
</ItemGroup>
4653
<ItemGroup>
54+
<Compile Include="SpaceTests.cs" />
4755
<Compile Include="TestHelpers.cs" />
4856
<Compile Include="MapTests2D.cs" />
4957
<Compile Include="MapTests3D.cs" />
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
2+
<s:String x:Key="/Default/CodeInspection/CSharpLanguageProject/LanguageLevel/@EntryValue">CSharp70</s:String></wpf:ResourceDictionary>

InfiniMap.Test/MapTests2D.cs

Lines changed: 49 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,26 @@ public void MapSerializer()
1717
map[16, 16] = 2.0f; // Chunk: (1,1,1)
1818
map[32, 32] = 4.0f; // Chunk: (2,2,2)
1919

20-
var list = new List<Tuple<long, long, long>>();
20+
var list = new List<ChunkSpace>();
2121

22-
map.RegisterWriter((xyz, tuple) =>
22+
map.RegisterWriter((xyz, items) =>
2323
{
24-
Console.WriteLine("Writing: ({0},{1},{2})", tuple.Item1, tuple.Item2, tuple.Item3);
25-
list.Add(tuple);
24+
Console.WriteLine("Writing: ({0},{1},{2})", xyz.X, xyz.Y, xyz.Z);
25+
list.Add(xyz);
2626
});
2727

28-
map.UnloadArea(0, 0, 32, 32);
28+
map.UnloadArea(new WorldSpace2D(0, 0), new WorldSpace2D(32, 32));
2929

3030
Assert.AreEqual(3, list.Count);
3131

32-
Assert.That(list.Contains(Tuple.Create(0L, 0L, 0L)));
33-
Assert.That(list.Contains(Tuple.Create(1L, 1L, 0L)));
34-
Assert.That(list.Contains(Tuple.Create(2L, 2L, 0L)));
32+
Assert.That(list.Contains(new ChunkSpace(0L, 0L, 0L)));
33+
Assert.That(list.Contains(new ChunkSpace(1L, 1L, 0L)));
34+
Assert.That(list.Contains(new ChunkSpace(2L, 2L, 0L)));
3535

3636
map.UnregisterWriter();
3737
map[48, 48] = 4.0f;
3838

39-
map.UnloadArea(0, 0, 48, 48);
39+
map.UnloadArea((0, 0), (48, 48));
4040
Assert.AreEqual(3, list.Count);
4141
}
4242

@@ -103,8 +103,11 @@ public void CanEnumerateRanges()
103103
var map = new Map2D<float>();
104104
map[1, 2] = 4.0f;
105105

106-
Assert.That(map.Within(0, 0, 4, 4).Any());
107-
Assert.That(map.Within(0, 0, 4, 4).Any(i => Math.Abs(i - 4.0f) < 0.001));
106+
var begin = new WorldSpace2D(0, 0);
107+
var end = new WorldSpace2D(4, 4);
108+
109+
Assert.That(map.Within(begin,end).Any());
110+
Assert.That(map.Within(begin, end).Any(i => Math.Abs(i - 4.0f) < 0.001));
108111
}
109112

110113
[Test]
@@ -149,31 +152,30 @@ public void ChunkGathering()
149152
var map = new Map2D<float>(16, 16);
150153

151154
map[1, 1] = 2.0f;
152-
map[63, 63] = 4.0f;
153-
map[1, 127] = 8.0f;
155+
map[31, 31] = 4.0f;
154156

155-
// Assert we have 3 chunks in memory.
156-
Assert.AreEqual((16 * 16) * 3, map.Count);
157+
// Assert we have 2 chunks in memory.
158+
Assert.AreEqual((16 * 16) * 2, map.Count);
157159

158160
// A single chunk
159161
{
160162
var chunksFound = map.ChunksWithin(0, 0, 15, 15, createIfNull: false).ToList();
161163
Assert.AreEqual(1, chunksFound.Count());
162-
Assert.AreEqual(0, chunksFound.Select(s => s.Item1).First());
164+
Assert.AreEqual(0, chunksFound.Select(s => s.Item1.X).First());
163165

164166
// Assert that it is the correct chunk
165-
Assert.That(chunksFound.ElementAt(0).Item3.Contains(2.0f));
167+
Assert.That(chunksFound.ElementAt(0).Item2.Contains(2.0f));
166168
}
167169

168170
// Two chunks
169171
{
170-
var chunksFound = map.ChunksWithin(0, 0, 63, 63, createIfNull: false).ToList();
172+
var chunksFound = map.ChunksWithin(0, 0, 31, 31, createIfNull: false).ToList();
171173
Assert.AreEqual(2, chunksFound.Count);
172-
Assert.AreEqual(3, chunksFound.Select(s => s.Item1).ElementAt(1));
174+
Assert.AreEqual(1, chunksFound.Select(s => s.Item1.X).ElementAt(1));
173175

174176
// Assert that these are the correct chunks.
175-
Assert.That(chunksFound.ElementAt(0).Item3.Contains(2.0f));
176-
Assert.That(chunksFound.ElementAt(1).Item3.Contains(4.0f));
177+
Assert.That(chunksFound.ElementAt(0).Item2.Contains(2.0f));
178+
Assert.That(chunksFound.ElementAt(1).Item2.Contains(4.0f));
177179
}
178180
}
179181

@@ -188,11 +190,36 @@ public void SupportsUnloading()
188190

189191
Assert.AreEqual((16 * 16) * 3, map.Count);
190192

191-
map.UnloadArea(0, 0, 33, 33);
193+
var begin = new WorldSpace2D(0, 0);
194+
var end = new WorldSpace2D(33, 33);
195+
196+
map.UnloadArea(begin, end);
192197

193198
Assert.AreEqual(0, map.Count);
194199
}
195200

201+
[Test]
202+
public void SupportsUnloadingWithPersistance()
203+
{
204+
var map = new Map2D<float>();
205+
206+
map[0, 0] = 2.0f;
207+
map[16, 16] = 2.0f;
208+
map[33, 33] = 4.0f;
209+
210+
Assert.AreEqual((16 * 16) * 3, map.Count);
211+
212+
map.MakePersistant((1, 1));
213+
214+
var begin = new WorldSpace2D(0, 0);
215+
var end = new WorldSpace2D(33, 33);
216+
217+
map.UnloadArea(begin, end);
218+
219+
// One chunk left
220+
Assert.AreEqual((16*16), map.Count);
221+
}
222+
196223
[Test]
197224
public void SupportsUnloadingOutsideArea()
198225
{

0 commit comments

Comments
 (0)