-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update to support latest SDK, NuGet support
- Loading branch information
1 parent
d970fcd
commit 3088bcb
Showing
8 changed files
with
548 additions
and
521 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,38 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<LangVersion>10.0</LangVersion> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)'=='Debug'"> | ||
<DefineConstants>BOX2D_OBJECT_TRACKING;BOX2D_VALID_ACCESS_CHECKING;BOX2D_NO_POOLING</DefineConstants> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)'=='Release'"> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Bcl.HashCode" Version="1.1.1" /> | ||
<PackageReference Include="Microsoft.Extensions.ObjectPool" Version="6.0.1" /> | ||
<PackageReference Include="System.Memory" Version="4.5.4" /> | ||
</ItemGroup> | ||
|
||
</Project> | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<LangVersion>12.0</LangVersion> | ||
<RuntimeIdentifier>win-x64</RuntimeIdentifier> | ||
<PackageId>Box2D.CSharp</PackageId> | ||
<Version>0.1.0-preview.1</Version> | ||
<RepositoryUrl>https://github.com/MackinnonBuck/Box2D.CSharp.git</RepositoryUrl> | ||
<PackageReadmeFile>README.md</PackageReadmeFile> | ||
<PublishRepositoryUrl>true</PublishRepositoryUrl> | ||
<EmbedUntrackedSources>true</EmbedUntrackedSources> | ||
<DebugType>embedded</DebugType> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)'=='Debug'"> | ||
<DefineConstants>BOX2D_OBJECT_TRACKING;BOX2D_VALID_ACCESS_CHECKING;BOX2D_NO_POOLING</DefineConstants> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)'=='Release'"> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<None Include="..\..\README.md" Pack="true" PackagePath="\" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Include="..\..\lib\$(PlatformTarget)\$(Configuration)\box2dwrapper.dll" Pack="true" PackagePath="runtimes/win-x64/native/" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Bcl.HashCode" Version="1.1.1" /> | ||
<PackageReference Include="Microsoft.Extensions.ObjectPool" Version="6.0.1" /> | ||
<PackageReference Include="System.Memory" Version="4.5.4" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,97 +1,97 @@ | ||
using Box2D.Core; | ||
using System; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace Box2D.Collections; | ||
|
||
/// <summary> | ||
/// Represents a managed reference to an unmanaged Box2D array. | ||
/// </summary> | ||
/// <typeparam name="T">The array item type.</typeparam> | ||
public readonly ref struct ArrayRef<T> where T : struct | ||
{ | ||
private static readonly int _elementSize = Marshal.SizeOf<T>(); | ||
|
||
private readonly IntPtr _native; | ||
|
||
/// <summary> | ||
/// Gets the length of the array. | ||
/// </summary> | ||
public int Length { get; } | ||
|
||
/// <summary> | ||
/// Gets whether the <see cref="ArrayRef{T}"/> points to a null | ||
/// unmanaged array. | ||
/// </summary> | ||
public bool IsNull => _native == IntPtr.Zero; | ||
|
||
/// <summary> | ||
/// Gets or sets the value of an item in the array. | ||
/// </summary> | ||
/// <param name="index">The index of the item in the array.</param> | ||
public T this[int index] | ||
{ | ||
get | ||
{ | ||
ThrowIfInvalidIndex(index); | ||
return Marshal.PtrToStructure<T>(_native + _elementSize * index); | ||
} | ||
set | ||
{ | ||
ThrowIfInvalidIndex(index); | ||
Marshal.StructureToPtr(value, _native + _elementSize * index, false); | ||
} | ||
} | ||
|
||
internal ArrayRef(IntPtr native, int length) | ||
{ | ||
_native = native; | ||
Length = length; | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
private void ThrowIfInvalidIndex(int index) | ||
{ | ||
Errors.ThrowIfNull(_native, nameof(ArrayRef<T>)); | ||
|
||
if (index < 0 || index >= Length) | ||
{ | ||
throw new IndexOutOfRangeException(); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Gets an <see cref="Enumerator"/> for the current <see cref="ArrayRef{T}"/> instance. | ||
/// </summary> | ||
public Enumerator GetEnumerator() | ||
=> new(in this); | ||
|
||
/// <summary> | ||
/// An enumerator for <see cref="ArrayRef{T}"/> instances. | ||
/// </summary> | ||
public ref struct Enumerator | ||
{ | ||
private readonly ArrayRef<T> _source; | ||
private int _index = -1; | ||
|
||
/// <summary> | ||
/// Gets the current element. | ||
/// </summary> | ||
public T Current => _source[_index]; | ||
|
||
/// <summary> | ||
/// Constructs a new <see cref="Enumerator"/> instance. | ||
/// </summary> | ||
public Enumerator(in ArrayRef<T> source) | ||
{ | ||
_source = source; | ||
} | ||
|
||
/// <summary> | ||
/// Moves to the next element. | ||
/// </summary> | ||
public bool MoveNext() | ||
=> ++_index < _source.Length; | ||
} | ||
} | ||
using Box2D.Core; | ||
using System; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace Box2D.Collections; | ||
|
||
/// <summary> | ||
/// Represents a managed reference to an unmanaged Box2D array. | ||
/// </summary> | ||
/// <typeparam name="T">The array item type.</typeparam> | ||
public readonly ref struct ArrayRef<T> where T : struct | ||
{ | ||
private static readonly int _elementSize = Marshal.SizeOf<T>(); | ||
|
||
private readonly IntPtr _native; | ||
|
||
/// <summary> | ||
/// Gets the length of the array. | ||
/// </summary> | ||
public int Length { get; } | ||
|
||
/// <summary> | ||
/// Gets whether the <see cref="ArrayRef{T}"/> points to a null | ||
/// unmanaged array. | ||
/// </summary> | ||
public bool IsNull => _native == IntPtr.Zero; | ||
|
||
/// <summary> | ||
/// Gets or sets the value of an item in the array. | ||
/// </summary> | ||
/// <param name="index">The index of the item in the array.</param> | ||
public T this[int index] | ||
{ | ||
get | ||
{ | ||
ThrowIfInvalidIndex(index); | ||
return Marshal.PtrToStructure<T>(_native + _elementSize * index); | ||
} | ||
set | ||
{ | ||
ThrowIfInvalidIndex(index); | ||
Marshal.StructureToPtr(value, _native + _elementSize * index, false); | ||
} | ||
} | ||
|
||
internal ArrayRef(IntPtr native, int length) | ||
{ | ||
_native = native; | ||
Length = length; | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
private void ThrowIfInvalidIndex(int index) | ||
{ | ||
Errors.ThrowIfNull(_native, nameof(ArrayRef<T>)); | ||
|
||
if (index < 0 || index >= Length) | ||
{ | ||
throw new IndexOutOfRangeException(); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Gets an <see cref="Enumerator"/> for the current <see cref="ArrayRef{T}"/> instance. | ||
/// </summary> | ||
public Enumerator GetEnumerator() | ||
=> new(in this); | ||
|
||
/// <summary> | ||
/// An enumerator for <see cref="ArrayRef{T}"/> instances. | ||
/// </summary> | ||
public ref struct Enumerator | ||
{ | ||
private readonly ArrayRef<T> _source; | ||
private int _index = -1; | ||
|
||
/// <summary> | ||
/// Gets the current element. | ||
/// </summary> | ||
public T Current => _source[_index]; | ||
|
||
/// <summary> | ||
/// Constructs a new <see cref="Enumerator"/> instance. | ||
/// </summary> | ||
public Enumerator(scoped in ArrayRef<T> source) | ||
{ | ||
_source = source; | ||
} | ||
|
||
/// <summary> | ||
/// Moves to the next element. | ||
/// </summary> | ||
public bool MoveNext() | ||
=> ++_index < _source.Length; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,49 @@ | ||
using Box2D.Collections; | ||
using System; | ||
|
||
namespace Box2D.Collision; | ||
|
||
using static Interop.NativeMethods; | ||
|
||
/// <summary> | ||
/// Contact impulses for reporting. Impulses are used instead of forces because | ||
/// sub-step forces may approach infinity for rigid body collisions. These | ||
/// match up one-to-one with the contact points in <see cref="Manifold"/>. | ||
/// </summary> | ||
public readonly ref struct ContactImpulse | ||
{ | ||
private readonly IntPtr _native; | ||
|
||
/// <summary> | ||
/// Gets whether this <see cref="ContactImpulse"/> points to a null unmanaged contact impulse. | ||
/// </summary> | ||
public bool IsNull => _native == IntPtr.Zero; | ||
|
||
/// <summary> | ||
/// Gets the normal impulses array. | ||
/// </summary> | ||
public ArrayRef<float> NormalImpulses { get; } | ||
|
||
/// <summary> | ||
/// Gets the tangent impulses array. | ||
/// </summary> | ||
public ArrayRef<float> TangentImpulses { get; } | ||
|
||
internal static ContactImpulse Create(IntPtr native) | ||
{ | ||
if (native == IntPtr.Zero) | ||
{ | ||
return default; | ||
} | ||
|
||
b2ContactImpulse_get_impulses(native, out IntPtr normalImpulses, out IntPtr tangentImpulses, out int count); | ||
return new(native, new(normalImpulses, count), new(tangentImpulses, count)); | ||
} | ||
|
||
private ContactImpulse(IntPtr native, in ArrayRef<float> normalImpulses, in ArrayRef<float> tangentImpulses) | ||
{ | ||
_native = native; | ||
NormalImpulses = normalImpulses; | ||
TangentImpulses = tangentImpulses; | ||
} | ||
} | ||
using Box2D.Collections; | ||
using System; | ||
|
||
namespace Box2D.Collision; | ||
|
||
using static Interop.NativeMethods; | ||
|
||
/// <summary> | ||
/// Contact impulses for reporting. Impulses are used instead of forces because | ||
/// sub-step forces may approach infinity for rigid body collisions. These | ||
/// match up one-to-one with the contact points in <see cref="Manifold"/>. | ||
/// </summary> | ||
public readonly ref struct ContactImpulse | ||
{ | ||
private readonly IntPtr _native; | ||
|
||
/// <summary> | ||
/// Gets whether this <see cref="ContactImpulse"/> points to a null unmanaged contact impulse. | ||
/// </summary> | ||
public bool IsNull => _native == IntPtr.Zero; | ||
|
||
/// <summary> | ||
/// Gets the normal impulses array. | ||
/// </summary> | ||
public ArrayRef<float> NormalImpulses { get; } | ||
|
||
/// <summary> | ||
/// Gets the tangent impulses array. | ||
/// </summary> | ||
public ArrayRef<float> TangentImpulses { get; } | ||
|
||
internal static ContactImpulse Create(IntPtr native) | ||
{ | ||
if (native == IntPtr.Zero) | ||
{ | ||
return default; | ||
} | ||
|
||
b2ContactImpulse_get_impulses(native, out IntPtr normalImpulses, out IntPtr tangentImpulses, out int count); | ||
return new(native, new(normalImpulses, count), new(tangentImpulses, count)); | ||
} | ||
|
||
private ContactImpulse(IntPtr native, scoped in ArrayRef<float> normalImpulses, scoped in ArrayRef<float> tangentImpulses) | ||
{ | ||
_native = native; | ||
NormalImpulses = normalImpulses; | ||
TangentImpulses = tangentImpulses; | ||
} | ||
} |
Oops, something went wrong.