Skip to content

Commit 3088bcb

Browse files
committed
Update to support latest SDK, NuGet support
1 parent d970fcd commit 3088bcb

File tree

8 files changed

+548
-521
lines changed

8 files changed

+548
-521
lines changed

src/Box2D/Box2D.csproj

+38-22
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,38 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
2-
3-
<PropertyGroup>
4-
<TargetFramework>netstandard2.0</TargetFramework>
5-
<Nullable>enable</Nullable>
6-
<LangVersion>10.0</LangVersion>
7-
</PropertyGroup>
8-
9-
<PropertyGroup Condition="'$(Configuration)'=='Debug'">
10-
<DefineConstants>BOX2D_OBJECT_TRACKING;BOX2D_VALID_ACCESS_CHECKING;BOX2D_NO_POOLING</DefineConstants>
11-
</PropertyGroup>
12-
13-
<PropertyGroup Condition="'$(Configuration)'=='Release'">
14-
</PropertyGroup>
15-
16-
<ItemGroup>
17-
<PackageReference Include="Microsoft.Bcl.HashCode" Version="1.1.1" />
18-
<PackageReference Include="Microsoft.Extensions.ObjectPool" Version="6.0.1" />
19-
<PackageReference Include="System.Memory" Version="4.5.4" />
20-
</ItemGroup>
21-
22-
</Project>
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<LangVersion>12.0</LangVersion>
7+
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
8+
<PackageId>Box2D.CSharp</PackageId>
9+
<Version>0.1.0-preview.1</Version>
10+
<RepositoryUrl>https://github.com/MackinnonBuck/Box2D.CSharp.git</RepositoryUrl>
11+
<PackageReadmeFile>README.md</PackageReadmeFile>
12+
<PublishRepositoryUrl>true</PublishRepositoryUrl>
13+
<EmbedUntrackedSources>true</EmbedUntrackedSources>
14+
<DebugType>embedded</DebugType>
15+
</PropertyGroup>
16+
17+
<PropertyGroup Condition="'$(Configuration)'=='Debug'">
18+
<DefineConstants>BOX2D_OBJECT_TRACKING;BOX2D_VALID_ACCESS_CHECKING;BOX2D_NO_POOLING</DefineConstants>
19+
</PropertyGroup>
20+
21+
<PropertyGroup Condition="'$(Configuration)'=='Release'">
22+
</PropertyGroup>
23+
24+
<ItemGroup>
25+
<None Include="..\..\README.md" Pack="true" PackagePath="\" />
26+
</ItemGroup>
27+
28+
<ItemGroup>
29+
<None Include="..\..\lib\$(PlatformTarget)\$(Configuration)\box2dwrapper.dll" Pack="true" PackagePath="runtimes/win-x64/native/" />
30+
</ItemGroup>
31+
32+
<ItemGroup>
33+
<PackageReference Include="Microsoft.Bcl.HashCode" Version="1.1.1" />
34+
<PackageReference Include="Microsoft.Extensions.ObjectPool" Version="6.0.1" />
35+
<PackageReference Include="System.Memory" Version="4.5.4" />
36+
</ItemGroup>
37+
38+
</Project>

src/Box2D/Collections/ArrayRef.cs

+97-97
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,97 @@
1-
using Box2D.Core;
2-
using System;
3-
using System.Runtime.CompilerServices;
4-
using System.Runtime.InteropServices;
5-
6-
namespace Box2D.Collections;
7-
8-
/// <summary>
9-
/// Represents a managed reference to an unmanaged Box2D array.
10-
/// </summary>
11-
/// <typeparam name="T">The array item type.</typeparam>
12-
public readonly ref struct ArrayRef<T> where T : struct
13-
{
14-
private static readonly int _elementSize = Marshal.SizeOf<T>();
15-
16-
private readonly IntPtr _native;
17-
18-
/// <summary>
19-
/// Gets the length of the array.
20-
/// </summary>
21-
public int Length { get; }
22-
23-
/// <summary>
24-
/// Gets whether the <see cref="ArrayRef{T}"/> points to a null
25-
/// unmanaged array.
26-
/// </summary>
27-
public bool IsNull => _native == IntPtr.Zero;
28-
29-
/// <summary>
30-
/// Gets or sets the value of an item in the array.
31-
/// </summary>
32-
/// <param name="index">The index of the item in the array.</param>
33-
public T this[int index]
34-
{
35-
get
36-
{
37-
ThrowIfInvalidIndex(index);
38-
return Marshal.PtrToStructure<T>(_native + _elementSize * index);
39-
}
40-
set
41-
{
42-
ThrowIfInvalidIndex(index);
43-
Marshal.StructureToPtr(value, _native + _elementSize * index, false);
44-
}
45-
}
46-
47-
internal ArrayRef(IntPtr native, int length)
48-
{
49-
_native = native;
50-
Length = length;
51-
}
52-
53-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
54-
private void ThrowIfInvalidIndex(int index)
55-
{
56-
Errors.ThrowIfNull(_native, nameof(ArrayRef<T>));
57-
58-
if (index < 0 || index >= Length)
59-
{
60-
throw new IndexOutOfRangeException();
61-
}
62-
}
63-
64-
/// <summary>
65-
/// Gets an <see cref="Enumerator"/> for the current <see cref="ArrayRef{T}"/> instance.
66-
/// </summary>
67-
public Enumerator GetEnumerator()
68-
=> new(in this);
69-
70-
/// <summary>
71-
/// An enumerator for <see cref="ArrayRef{T}"/> instances.
72-
/// </summary>
73-
public ref struct Enumerator
74-
{
75-
private readonly ArrayRef<T> _source;
76-
private int _index = -1;
77-
78-
/// <summary>
79-
/// Gets the current element.
80-
/// </summary>
81-
public T Current => _source[_index];
82-
83-
/// <summary>
84-
/// Constructs a new <see cref="Enumerator"/> instance.
85-
/// </summary>
86-
public Enumerator(in ArrayRef<T> source)
87-
{
88-
_source = source;
89-
}
90-
91-
/// <summary>
92-
/// Moves to the next element.
93-
/// </summary>
94-
public bool MoveNext()
95-
=> ++_index < _source.Length;
96-
}
97-
}
1+
using Box2D.Core;
2+
using System;
3+
using System.Runtime.CompilerServices;
4+
using System.Runtime.InteropServices;
5+
6+
namespace Box2D.Collections;
7+
8+
/// <summary>
9+
/// Represents a managed reference to an unmanaged Box2D array.
10+
/// </summary>
11+
/// <typeparam name="T">The array item type.</typeparam>
12+
public readonly ref struct ArrayRef<T> where T : struct
13+
{
14+
private static readonly int _elementSize = Marshal.SizeOf<T>();
15+
16+
private readonly IntPtr _native;
17+
18+
/// <summary>
19+
/// Gets the length of the array.
20+
/// </summary>
21+
public int Length { get; }
22+
23+
/// <summary>
24+
/// Gets whether the <see cref="ArrayRef{T}"/> points to a null
25+
/// unmanaged array.
26+
/// </summary>
27+
public bool IsNull => _native == IntPtr.Zero;
28+
29+
/// <summary>
30+
/// Gets or sets the value of an item in the array.
31+
/// </summary>
32+
/// <param name="index">The index of the item in the array.</param>
33+
public T this[int index]
34+
{
35+
get
36+
{
37+
ThrowIfInvalidIndex(index);
38+
return Marshal.PtrToStructure<T>(_native + _elementSize * index);
39+
}
40+
set
41+
{
42+
ThrowIfInvalidIndex(index);
43+
Marshal.StructureToPtr(value, _native + _elementSize * index, false);
44+
}
45+
}
46+
47+
internal ArrayRef(IntPtr native, int length)
48+
{
49+
_native = native;
50+
Length = length;
51+
}
52+
53+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
54+
private void ThrowIfInvalidIndex(int index)
55+
{
56+
Errors.ThrowIfNull(_native, nameof(ArrayRef<T>));
57+
58+
if (index < 0 || index >= Length)
59+
{
60+
throw new IndexOutOfRangeException();
61+
}
62+
}
63+
64+
/// <summary>
65+
/// Gets an <see cref="Enumerator"/> for the current <see cref="ArrayRef{T}"/> instance.
66+
/// </summary>
67+
public Enumerator GetEnumerator()
68+
=> new(in this);
69+
70+
/// <summary>
71+
/// An enumerator for <see cref="ArrayRef{T}"/> instances.
72+
/// </summary>
73+
public ref struct Enumerator
74+
{
75+
private readonly ArrayRef<T> _source;
76+
private int _index = -1;
77+
78+
/// <summary>
79+
/// Gets the current element.
80+
/// </summary>
81+
public T Current => _source[_index];
82+
83+
/// <summary>
84+
/// Constructs a new <see cref="Enumerator"/> instance.
85+
/// </summary>
86+
public Enumerator(scoped in ArrayRef<T> source)
87+
{
88+
_source = source;
89+
}
90+
91+
/// <summary>
92+
/// Moves to the next element.
93+
/// </summary>
94+
public bool MoveNext()
95+
=> ++_index < _source.Length;
96+
}
97+
}

src/Box2D/Collision/ContactImpulse.cs

+49-49
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,49 @@
1-
using Box2D.Collections;
2-
using System;
3-
4-
namespace Box2D.Collision;
5-
6-
using static Interop.NativeMethods;
7-
8-
/// <summary>
9-
/// Contact impulses for reporting. Impulses are used instead of forces because
10-
/// sub-step forces may approach infinity for rigid body collisions. These
11-
/// match up one-to-one with the contact points in <see cref="Manifold"/>.
12-
/// </summary>
13-
public readonly ref struct ContactImpulse
14-
{
15-
private readonly IntPtr _native;
16-
17-
/// <summary>
18-
/// Gets whether this <see cref="ContactImpulse"/> points to a null unmanaged contact impulse.
19-
/// </summary>
20-
public bool IsNull => _native == IntPtr.Zero;
21-
22-
/// <summary>
23-
/// Gets the normal impulses array.
24-
/// </summary>
25-
public ArrayRef<float> NormalImpulses { get; }
26-
27-
/// <summary>
28-
/// Gets the tangent impulses array.
29-
/// </summary>
30-
public ArrayRef<float> TangentImpulses { get; }
31-
32-
internal static ContactImpulse Create(IntPtr native)
33-
{
34-
if (native == IntPtr.Zero)
35-
{
36-
return default;
37-
}
38-
39-
b2ContactImpulse_get_impulses(native, out IntPtr normalImpulses, out IntPtr tangentImpulses, out int count);
40-
return new(native, new(normalImpulses, count), new(tangentImpulses, count));
41-
}
42-
43-
private ContactImpulse(IntPtr native, in ArrayRef<float> normalImpulses, in ArrayRef<float> tangentImpulses)
44-
{
45-
_native = native;
46-
NormalImpulses = normalImpulses;
47-
TangentImpulses = tangentImpulses;
48-
}
49-
}
1+
using Box2D.Collections;
2+
using System;
3+
4+
namespace Box2D.Collision;
5+
6+
using static Interop.NativeMethods;
7+
8+
/// <summary>
9+
/// Contact impulses for reporting. Impulses are used instead of forces because
10+
/// sub-step forces may approach infinity for rigid body collisions. These
11+
/// match up one-to-one with the contact points in <see cref="Manifold"/>.
12+
/// </summary>
13+
public readonly ref struct ContactImpulse
14+
{
15+
private readonly IntPtr _native;
16+
17+
/// <summary>
18+
/// Gets whether this <see cref="ContactImpulse"/> points to a null unmanaged contact impulse.
19+
/// </summary>
20+
public bool IsNull => _native == IntPtr.Zero;
21+
22+
/// <summary>
23+
/// Gets the normal impulses array.
24+
/// </summary>
25+
public ArrayRef<float> NormalImpulses { get; }
26+
27+
/// <summary>
28+
/// Gets the tangent impulses array.
29+
/// </summary>
30+
public ArrayRef<float> TangentImpulses { get; }
31+
32+
internal static ContactImpulse Create(IntPtr native)
33+
{
34+
if (native == IntPtr.Zero)
35+
{
36+
return default;
37+
}
38+
39+
b2ContactImpulse_get_impulses(native, out IntPtr normalImpulses, out IntPtr tangentImpulses, out int count);
40+
return new(native, new(normalImpulses, count), new(tangentImpulses, count));
41+
}
42+
43+
private ContactImpulse(IntPtr native, scoped in ArrayRef<float> normalImpulses, scoped in ArrayRef<float> tangentImpulses)
44+
{
45+
_native = native;
46+
NormalImpulses = normalImpulses;
47+
TangentImpulses = tangentImpulses;
48+
}
49+
}

0 commit comments

Comments
 (0)