Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to .Net 8.0 #2

Merged
merged 1 commit into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ jobs:
runs-on: windows-latest

steps:
- name: Setup dotnet
uses: actions/setup-dotnet@v3
with:
dotnet-version: '8.0.x'
- name: Checkout sources
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Extract version number
id: extract_version
shell: pwsh
Expand Down Expand Up @@ -42,4 +46,4 @@ jobs:
with:
name: cmodconvert-${{ steps.extract_version.outputs.version }}
path: Publish/

25 changes: 7 additions & 18 deletions CmodConvert.Test/CmodConvert.Test.csproj
Original file line number Diff line number Diff line change
@@ -1,31 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<TargetFramework>net8.0</TargetFramework>
<IsTestProject>true</IsTestProject>
<IsPackable>false</IsPackable>
<Authors>Andrew Tribick</Authors>
<Copyright>ⓒ 2021–2023 Andrew Tribick</Copyright>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<RepositoryUrl>https://github.com/ajtribick/cmodconvert</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<WarningsAsErrors>true</WarningsAsErrors>
<IsPublishable>false</IsPublishable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
<PackageReference Include="coverlet.collector" Version="6.0.0">
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="MSTest.TestAdapter" />
<PackageReference Include="MSTest.TestFramework" />
<PackageReference Include="coverlet.collector">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\CmodConvert\CmodConvert.csproj" />
</ItemGroup>

</Project>
</Project>
5 changes: 3 additions & 2 deletions CmodConvert.sln
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
Expand All @@ -9,6 +8,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
ProjectSection(SolutionItems) = preProject
.gitattributes = .gitattributes
.gitignore = .gitignore
Directory.Build.props = Directory.Build.props
Directory.Packages.props = Directory.Packages.props
LICENSE = LICENSE
README.md = README.md
EndProjectSection
Expand All @@ -18,7 +19,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "format", "format", "{0D856A
format\cmod-binary.md = format\cmod-binary.md
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CmodConvert.Test", "CmodConvert.Test\CmodConvert.Test.csproj", "{FCBD5246-03B8-4744-918E-E4C021A08B67}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CmodConvert.Test", "CmodConvert.Test\CmodConvert.Test.csproj", "{FCBD5246-03B8-4744-918E-E4C021A08B67}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
27 changes: 5 additions & 22 deletions CmodConvert/CmodConvert.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,48 +16,31 @@ You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-->

<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<InvariantGlobalization>true</InvariantGlobalization>
<SatelliteResourceLanguages>none</SatelliteResourceLanguages>
<Version>0.1.1</Version>
<Authors>Andrew Tribick</Authors>
<TargetFramework>net8.0</TargetFramework>
<Description>Convert Celestia CMOD format to Wavefront OBJ/MTL.</Description>
<Copyright>ⓒ 2021–2023 Andrew Tribick</Copyright>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<RepositoryUrl>https://github.com/ajtribick/cmodconvert</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<AssemblyVersion>0.1.1.0</AssemblyVersion>
<FileVersion>0.1.1.0</FileVersion>
<WarningsAsErrors>true</WarningsAsErrors>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<DebugType>none</DebugType>
<DebugSymbols>false</DebugSymbols>
</PropertyGroup>

<ItemGroup>
<None Include="..\LICENSE" Link="LICENSE">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="..\LICENSE">
<Pack>True</Pack>
<PackagePath></PackagePath>
<PackagePath>
</PackagePath>
</None>
<None Include="..\README.md" Link="README.md">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
<PackageReference Include="System.CommandLine" />
</ItemGroup>

</Project>
</Project>
12 changes: 3 additions & 9 deletions CmodConvert/CmodData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,8 @@

namespace CmodConvert;

public class CmodData
public class CmodData(IReadOnlyCollection<Material> materials, IReadOnlyCollection<Mesh> meshes)
{
public CmodData(IReadOnlyCollection<Material> materials, IReadOnlyCollection<Mesh> meshes)
{
Materials = materials;
Meshes = meshes;
}

public IReadOnlyCollection<Material> Materials { get; }
public IReadOnlyCollection<Mesh> Meshes { get; }
public IReadOnlyCollection<Material> Materials { get; } = materials;
public IReadOnlyCollection<Mesh> Meshes { get; } = meshes;
}
33 changes: 8 additions & 25 deletions CmodConvert/IO/CmodReader.Ascii.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,11 @@ namespace CmodConvert.IO;

public abstract partial class CmodReader
{
private class Ascii : CmodReader
private class Ascii(Stream stream) : CmodReader
{
private readonly Stream _stream;

public Ascii(Stream stream)
{
_stream = stream;
}

public override async Task<CmodData> Read()
{
using var reader = new TokenReader(_stream);
using var reader = new TokenReader(stream);
var materials = new List<Material>();
var meshes = new List<Mesh>();

Expand Down Expand Up @@ -87,23 +80,13 @@ private static async Task<Material> ReadMaterial(TokenReader reader)
break;

case "blend":
switch (await reader.NextToken().ConfigureAwait(false))
material.BlendMode = await reader.NextToken().ConfigureAwait(false) switch
{
case "normal":
material.BlendMode = BlendMode.Normal;
break;

case "add":
material.BlendMode = BlendMode.Additive;
break;

case "premultiplied":
material.BlendMode = BlendMode.PremultipliedAlpha;
break;

default:
throw new CmodException("Unknown blend mode");
}
"normal" => (BlendMode?)BlendMode.Normal,
"add" => (BlendMode?)BlendMode.Additive,
"premultiplied" => (BlendMode?)BlendMode.PremultipliedAlpha,
_ => throw new CmodException("Unknown blend mode"),
};
break;

case "texture0":
Expand Down
11 changes: 2 additions & 9 deletions CmodConvert/IO/CmodReader.Binary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,11 @@ namespace CmodConvert.IO;

public abstract partial class CmodReader
{
private class Binary : CmodReader
private class Binary(Stream stream) : CmodReader
{
private readonly Stream _stream;

public Binary(Stream stream)
{
_stream = stream;
}

public override async Task<CmodData> Read()
{
using var reader = new BufferedReader(_stream);
using var reader = new BufferedReader(stream);

var materials = new List<Material>();
var meshes = new List<Mesh>();
Expand Down
10 changes: 6 additions & 4 deletions CmodConvert/IO/TokenReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ namespace CmodConvert.IO;

internal sealed class TokenReader : IDataReader
{
private static readonly char[] s_endTokenChars = [' ', '\t'];

private readonly TextReader _reader;
private string? _line;
private int _position;
private bool _disposed;

public TokenReader(Stream stream, int capacity = 4096)
public TokenReader(Stream stream)
{
try
{
Expand Down Expand Up @@ -81,15 +83,15 @@ public TokenReader(Stream stream, int capacity = 4096)
break;

default:
var endToken = _line.IndexOfAny(new[] { ' ', '\t' }, _position + 1);
var endToken = _line.IndexOfAny(s_endTokenChars, _position + 1);
if (endToken > 0)
{
_position = endToken + 1;
return _line.Substring(current, endToken - current);
return _line[current..endToken];
}

_position = _line.Length;
return _line.Substring(current);
return _line[current..];
}
}
}
Expand Down
19 changes: 5 additions & 14 deletions CmodConvert/IO/WavefrontWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,13 @@

namespace CmodConvert.IO;

internal class WavefrontWriter
internal class WavefrontWriter(string objFile, string mtlFile)
{
private readonly string _objFile;
private readonly string _mtlFile;

public WavefrontWriter(string objFile, string mtlFile)
{
_objFile = objFile;
_mtlFile = mtlFile;
}

public Task Write(WavefrontMesh mesh) => Task.WhenAll(WriteMtl(mesh.Materials), WriteObj(mesh));

private async Task WriteMtl(IEnumerable<Material> materials)
{
using var stream = new FileStream(_mtlFile, FileMode.Create, FileAccess.Write, FileShare.None, 4096, true);
using var stream = new FileStream(mtlFile, FileMode.Create, FileAccess.Write, FileShare.None, 4096, true);
using var writer = new StreamWriter(stream, Encoding.ASCII);

var i = 0;
Expand Down Expand Up @@ -99,11 +90,11 @@ private async Task WriteMtl(IEnumerable<Material> materials)

private async Task WriteObj(WavefrontMesh mesh)
{
using var stream = new FileStream(_objFile, FileMode.Create, FileAccess.Write, FileShare.None, 4096, true);
using var stream = new FileStream(objFile, FileMode.Create, FileAccess.Write, FileShare.None, 4096, true);
using var writer = new StreamWriter(stream, Encoding.ASCII);

var objDirectory = Path.GetDirectoryName(_objFile);
var mtlRelative = objDirectory != null ? Path.GetRelativePath(objDirectory, _mtlFile) : _mtlFile;
var objDirectory = Path.GetDirectoryName(objFile);
var mtlRelative = objDirectory != null ? Path.GetRelativePath(objDirectory, mtlFile) : mtlFile;

await writer.WriteLineAsync($"mtllib {mtlRelative}").ConfigureAwait(false);

Expand Down
2 changes: 1 addition & 1 deletion CmodConvert/Material.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class Material
public float? SpecularPower { get; set; }
public float? Opacity { get; set; }
public BlendMode? BlendMode { get; set; }
public Dictionary<TextureSemantic, string> Textures { get; } = new();
public Dictionary<TextureSemantic, string> Textures { get; } = [];

public Material Clone()
{
Expand Down
18 changes: 6 additions & 12 deletions CmodConvert/Mesh.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,11 @@

namespace CmodConvert;

public class Mesh
public class Mesh(
IReadOnlyList<VertexAttribute> vertexAttributes,
IReadOnlyList<Primitive> primitives)
{
public Mesh(
IReadOnlyList<VertexAttribute> vertexAttributes,
IReadOnlyList<Primitive> primitives)
{
VertexAttributes = vertexAttributes;
Primitives = primitives;
}

public int VertexCount => VertexAttributes.First().Count;
public IReadOnlyList<VertexAttribute> VertexAttributes { get; }
public IReadOnlyList<Primitive> Primitives { get; }
public int VertexCount => VertexAttributes[0].Count;
public IReadOnlyList<VertexAttribute> VertexAttributes { get; } = vertexAttributes;
public IReadOnlyList<Primitive> Primitives { get; } = primitives;
}
15 changes: 4 additions & 11 deletions CmodConvert/Primitive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,9 @@

namespace CmodConvert;

public class Primitive
public class Primitive(PrimitiveType primitiveType, int materialIndex, int count)
{
public Primitive(PrimitiveType primitiveType, int materialIndex, int count)
{
PrimitiveType = primitiveType;
MaterialIndex = materialIndex;
Indices = new(count);
}

public PrimitiveType PrimitiveType { get; }
public int MaterialIndex { get; }
public List<int> Indices { get; }
public PrimitiveType PrimitiveType { get; } = primitiveType;
public int MaterialIndex { get; } = materialIndex;
public List<int> Indices { get; } = new(count);
}
6 changes: 2 additions & 4 deletions CmodConvert/VertexAttribute.Float1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@ namespace CmodConvert;

public abstract partial class VertexAttribute
{
private class Float1 : VertexAttribute
private class Float1(AttributeType attribute) : VertexAttribute(attribute)
{
private readonly List<float> _data = new();

public Float1(AttributeType attribute) : base(attribute) { }
private readonly List<float> _data = [];

public override int Count => _data.Count;

Expand Down
6 changes: 2 additions & 4 deletions CmodConvert/VertexAttribute.Float2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@ namespace CmodConvert;

public abstract partial class VertexAttribute
{
private class Float2 : VertexAttribute
private class Float2(AttributeType attribute) : VertexAttribute(attribute)
{
private readonly List<(float, float)> _data = new();

public Float2(AttributeType attribute) : base(attribute) { }
private readonly List<(float, float)> _data = [];

public override int Count => _data.Count;

Expand Down
6 changes: 2 additions & 4 deletions CmodConvert/VertexAttribute.Float3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@ namespace CmodConvert;

public abstract partial class VertexAttribute
{
private class Float3 : VertexAttribute
private class Float3(AttributeType attribute) : VertexAttribute(attribute)
{
private readonly List<(float, float, float)> _data = new();

public Float3(AttributeType attribute) : base(attribute) { }
private readonly List<(float, float, float)> _data = [];

public override int Count => _data.Count;

Expand Down
Loading