forked from lunditoph-siago/Sia.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reduce error message from Roslyn analyser (lunditoph-siago#5)
- Loading branch information
Showing
5 changed files
with
126 additions
and
7 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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"$schema": "http://json.schemastore.org/launchsettings.json", | ||
"profiles": { | ||
"DebugRoslynSourceGenerator": { | ||
"commandName": "DebugRoslynComponent", | ||
"targetProject": "../Sia.Examples/Sia.Examples.csproj" | ||
} | ||
} | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,106 @@ | ||
using System.Diagnostics; | ||
using Sia; | ||
|
||
namespace Sia_Examples; | ||
|
||
public partial record struct Component1(int Value); | ||
|
||
public partial record struct Component2(int Value); | ||
|
||
public partial record struct Padding1(); | ||
|
||
public partial record struct Padding2(); | ||
|
||
public partial record struct Padding3(); | ||
|
||
public partial record struct Padding4(); | ||
|
||
public class Fail | ||
{ | ||
private static TimeSpan _monoThreadElapsed; | ||
private static TimeSpan _multiThreadElapsed; | ||
|
||
[AfterSystem<MultiThreadUpdateSystem>] | ||
public class DebugLogSystem() | ||
: SystemBase(matcher: Matchers.Of<Component1, Component2>()) | ||
{ | ||
public override void Execute(World world, Scheduler scheduler, IEntityQuery query) | ||
{ | ||
foreach (var entity in query) { | ||
Console.WriteLine("Result: " + entity.Get<Component1>().Value); | ||
} | ||
} | ||
} | ||
|
||
public sealed class MonoThreadUpdateSystem() | ||
: SystemBase(matcher: Matchers.Of<Component1, Component2>()) | ||
{ | ||
public override void Execute(World world, Scheduler scheduler, IEntityQuery query) | ||
{ | ||
var watch = new Stopwatch(); | ||
watch.Start(); | ||
|
||
query.ForSlice((ref Component1 c1, ref Component2 c2) => { | ||
c1.Value += c2.Value; | ||
}); | ||
|
||
watch.Stop(); | ||
_monoThreadElapsed = watch.Elapsed; | ||
} | ||
} | ||
|
||
public sealed class MultiThreadUpdateSystem() | ||
: SystemBase(matcher: Matchers.Of<Component1, Component2>()) | ||
{ | ||
public override void Execute(World world, Scheduler scheduler, IEntityQuery query) | ||
{ | ||
var watch = new Stopwatch(); | ||
watch.Start(); | ||
|
||
Console.WriteLine("taskCount: " + query.Count + ", Processor: " + Environment.ProcessorCount); | ||
|
||
query.ForSliceOnParallel((ref Component1 c1, ref Component2 c2) => { | ||
c1.Value += c2.Value; | ||
}); | ||
|
||
watch.Stop(); | ||
_multiThreadElapsed = watch.Elapsed; | ||
} | ||
} | ||
|
||
public static void Run(World world) | ||
{ | ||
int entityCount = 100; | ||
for (int i = 0; i < entityCount; ++i) { | ||
switch (i % 4) | ||
{ | ||
case 0: | ||
world.CreateInArrayHost(Bundle.Create(new Component1(), new Component2 { Value = 1 }, new Padding1())); | ||
break; | ||
|
||
case 1: | ||
world.CreateInArrayHost(Bundle.Create(new Component1(), new Component2 { Value = 1 }, new Padding2())); | ||
break; | ||
|
||
case 2: | ||
world.CreateInArrayHost(Bundle.Create(new Component1(), new Component2 { Value = 1 }, new Padding3())); | ||
break; | ||
|
||
case 3: | ||
world.CreateInArrayHost(Bundle.Create(new Component1(), new Component2 { Value = 1 }, new Padding4())); | ||
break; | ||
} | ||
} | ||
|
||
var schduler = new Scheduler(); | ||
|
||
SystemChain.Empty | ||
.Add<MultiThreadUpdateSystem>() | ||
.Add<DebugLogSystem>() | ||
.RegisterTo(world, schduler); | ||
|
||
schduler.Tick(); | ||
|
||
Console.WriteLine("MultiThread: " + _multiThreadElapsed); | ||
} | ||
} |
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
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