mirror of
https://github.com/AlexMacocian/MonoGame.Extended.git
synced 2026-07-21 01:39:32 +00:00
Merge branch 'develop' into mutabletiled
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace MonoGame.Extended.Particles
|
||||
@@ -18,9 +18,8 @@ namespace MonoGame.Extended.Particles
|
||||
public unsafe ParticleBuffer(int size)
|
||||
{
|
||||
Size = size;
|
||||
// add one extra spot in memory for margin between head and tail
|
||||
// so the iterator can see that it's at the end
|
||||
_nativePointer = Marshal.AllocHGlobal(SizeInBytes);
|
||||
|
||||
BufferEnd = (Particle*) (_nativePointer + SizeInBytes);
|
||||
Head = (Particle*) _nativePointer;
|
||||
Tail = (Particle*) _nativePointer;
|
||||
@@ -40,7 +39,7 @@ namespace MonoGame.Extended.Particles
|
||||
public int Available => Size - Count;
|
||||
// current number of particles
|
||||
public int Count { get; private set; }
|
||||
// total size of the buffer
|
||||
// total size of the buffer (add one extra spot in memory for margin between head and tail so the iterator can see that it's at the end)
|
||||
public int SizeInBytes => Particle.SizeInBytes*(Size + 1);
|
||||
// total size of active particles
|
||||
public int ActiveSizeInBytes => Particle.SizeInBytes*Count;
|
||||
@@ -51,8 +50,7 @@ namespace MonoGame.Extended.Particles
|
||||
{
|
||||
Marshal.FreeHGlobal(_nativePointer);
|
||||
_disposed = true;
|
||||
|
||||
GC.RemoveMemoryPressure(Particle.SizeInBytes*Size);
|
||||
GC.RemoveMemoryPressure(SizeInBytes);
|
||||
}
|
||||
|
||||
GC.SuppressFinalize(this);
|
||||
@@ -151,4 +149,4 @@ namespace MonoGame.Extended.Particles
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,17 +20,20 @@ namespace MonoGame.Extended.Content
|
||||
var assetDirectory = Path.GetDirectoryName(contentReader.AssetName);
|
||||
var assetName = Path.Combine(assetDirectory, relativeName).Replace('\\', '/');
|
||||
|
||||
var ellipseIndex = assetName.IndexOf("/../", StringComparison.Ordinal);
|
||||
return ShortenRelativePath(assetName);
|
||||
}
|
||||
|
||||
public static string ShortenRelativePath(string relativePath)
|
||||
{
|
||||
var ellipseIndex = relativePath.IndexOf("/../", StringComparison.Ordinal);
|
||||
while (ellipseIndex != -1)
|
||||
{
|
||||
var lastDirectoryIndex = assetName.LastIndexOf('/', ellipseIndex - 1);
|
||||
if (lastDirectoryIndex == -1)
|
||||
lastDirectoryIndex = 0;
|
||||
assetName = assetName.Remove(lastDirectoryIndex, ellipseIndex + 4);
|
||||
ellipseIndex = assetName.IndexOf("/../", StringComparison.Ordinal);
|
||||
var lastDirectoryIndex = relativePath.LastIndexOf('/', ellipseIndex - 1) + 1;
|
||||
relativePath = relativePath.Remove(lastDirectoryIndex, ellipseIndex + 4 - lastDirectoryIndex);
|
||||
ellipseIndex = relativePath.IndexOf("/../", StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
return assetName;
|
||||
return relativePath;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using MonoGame.Extended.Collections;
|
||||
using MonoGame.Extended.Content;
|
||||
using Xunit;
|
||||
|
||||
namespace MonoGame.Extended.Tests.Content
|
||||
{
|
||||
public class ContentReaderExtensionsTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData("testsuperdir/testsubdir1/testsubdir2/resource", "testsuperdir/testsubdir1/testsubdir2/resource")]
|
||||
[InlineData("testsuperdir/testsubdir1/../testsubdir2/resource","testsuperdir/testsubdir2/resource")]
|
||||
[InlineData("testsuperdir/../resource","resource")]
|
||||
[InlineData("../testsuperdir/testsubdir1/../testsubdir2/resource","../testsuperdir/testsubdir2/resource")]
|
||||
[InlineData("testsuperdir/testsubdir1/testsubdir2/../../testsubdir3/resource","testsuperdir/testsubdir3/resource")]
|
||||
[InlineData("testsuperdir/testsubdir1/../testsubdir2/../testsubdir3/resource", "testsuperdir/testsubdir3/resource")]
|
||||
public void ContentReaderExtensions_ShortenRelativePath(string input, string expectedoutput)
|
||||
{
|
||||
Assert.True(ContentReaderExtensions.ShortenRelativePath(input) == expectedoutput);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||
<IsPackable>false</IsPackable>
|
||||
@@ -17,4 +17,7 @@
|
||||
<ProjectReference Include="..\..\MonoGame.Extended\MonoGame.Extended.csproj" />
|
||||
<ProjectReference Include="..\..\MonoGame.Extended.Particles\MonoGame.Extended.Particles.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Content\" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user