Created
May 4, 2020 15:05
-
-
Save guerro323/a12b7e15332406c03efb03b7050c0209 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
namespace PataponGameHost.Systems | |
{ | |
public struct Character | |
{ | |
} | |
[RestrictToApplication(typeof(GameSimulationThreadingHost))] | |
public class MoveCharacterSystem : AppSystem | |
{ | |
// Injected field | |
private readonly IManagedWorldTime worldTime; | |
public MoveCharacterSystem(IManagedWorldTime worldTime) | |
{ | |
this.worldTime = worldTime; | |
} | |
private EntitySet characterSet; | |
private Inputs.Axis2D moveAction; | |
protected override void OnInit() | |
{ | |
base.OnInit(); | |
moveAction = World.GetOrCreate<InputManager>().GetAction<MyInputMap, Inputs.Axis2D>("move"); | |
characterSet = World.Mgr.GetEntities() | |
.With<Character>() | |
.With<Vector3>() | |
.AsSet(); | |
for (var i = 0; i != 1_000_000; i++) | |
{ | |
var ch = World.Mgr.CreateEntity(); | |
ch.Set(new Character()); | |
ch.Set(new Vector3()); | |
} | |
} | |
protected override void OnUpdate() | |
{ | |
base.OnUpdate(); | |
var moveVector = moveAction.Value; | |
var dt = worldTime.Delta; | |
moveVector = Vector2.NormalizeSafe(moveVector) * dt; | |
foreach (int batch in characterSet.ToParallelBatch(batchCountTarget: 1 / 4)) | |
{ | |
foreach (ref readonly var entity in batch) | |
{ | |
entity.Get<Vector3>() += moveVector; | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment