Skip to content

Commit c27d3fa

Browse files
committed
Updated readme and sample.
1 parent 169e4c9 commit c27d3fa

File tree

2 files changed

+58
-5
lines changed

2 files changed

+58
-5
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ A high-performance C# based Archetype & Chunks [Entity Component System](https:/
1212
- 🤏 **_BARE MINIMUM_** > Not bloated, it's small and only provides the essentials for you!
1313
- ☕️ **_SIMPLE_** > Promotes a clean, minimal, and self-explanatory API that is simple by design. Check out the [Wiki](https://github.com/genaray/Arch/wiki)!
1414
- 💪 _**MAINTAINED**_ > It's actively being worked on, maintained, and comes along several [Extensions](https://github.com/genaray/Arch.Extended)!
15-
- 🚢 _**SUPPORT**_ > Supports .NetStandard 2.1, .Net Core 6 and 7, and therefore you may use it with Unity or Godot!
15+
- 🚢 _**SUPPORT**_ > Supports .NetStandard 2.1, .Net Core 6 and 8, and therefore you may use it with Unity or Godot!
1616

1717
Download the [package](https://github.com/genaray/Arch/packages/1697222), get started today and join the [Discord](https://discord.gg/htc8tX3NxZ)!
1818
```console
19-
dotnet add PROJECT package Arch --version 1.3.3-alpha
19+
dotnet add PROJECT package Arch --version 2.0.0-beta
2020
```
2121

2222
# ⏩ Quickstart
@@ -62,7 +62,7 @@ There's more to explore, for example...
6262
- [x] Grateful for every contribution
6363

6464
## 🚀 Features
65-
- [x] Archetypes with 64KB large chunks for your massive worlds
65+
- [x] Archetypes with 16KB large chunks for your massive worlds
6666
- [x] Incredibly small Entity size
6767
- [x] Optional `Pure-ECS` for maximum performance and efficiency
6868
- [x] Bulk/Batch Entity operations

src/Arch.Samples/Game.cs

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using Arch.Core;
22
using Arch.Core.Extensions;
3+
using Arch.Core.Extensions.Dangerous;
34
using Arch.Core.Utils;
5+
using CommunityToolkit.HighPerformance;
46
using Microsoft.Xna.Framework;
57
using Microsoft.Xna.Framework.Graphics;
68
using Microsoft.Xna.Framework.Input;
@@ -81,7 +83,6 @@ protected override void BeginRun()
8183
_drawSystem = new DrawSystem(_world, _spriteBatch);
8284

8385
// Spawn in entities with position, velocity and sprite
84-
_world.EnsureCapacity<Position, Velocity, Sprite>(150_000); // Optional but makes creation faster
8586
for (var index = 0; index < 150_000; index++)
8687
{
8788
_world.Create(
@@ -99,13 +100,64 @@ protected override void Update(GameTime gameTime)
99100
Exit();
100101
}
101102

102-
if (Keyboard.GetState().IsKeyDown(Keys.Delete))
103+
// Continue entity movement by adding velocity to all
104+
if (Keyboard.GetState().IsKeyDown(Keys.I))
105+
{
106+
// Query for velocity entities and remove their velocity to make them stop moving.
107+
var queryDesc = new QueryDescription().WithNone<Velocity>();
108+
_world.Add(in queryDesc, new Velocity { Vec2 = _random.NextVector2(-0.25f, 0.25f) });
109+
}
110+
111+
// Pause entity movement by removing velocity from all
112+
if (Keyboard.GetState().IsKeyDown(Keys.O))
103113
{
104114
// Query for velocity entities and remove their velocity to make them stop moving.
105115
var queryDesc = new QueryDescription().WithAll<Velocity>();
106116
_world.Remove<Velocity>(in queryDesc);
107117
}
108118

119+
// Add a random amount of new entities
120+
if (Keyboard.GetState().IsKeyDown(Keys.K))
121+
{
122+
// Bulk create entities
123+
var amount = Random.Shared.Next(0, 500);
124+
Span<Entity> entities = stackalloc Entity[amount];
125+
_world.Create(entities,[typeof(Position), typeof(Velocity), typeof(Sprite)], amount);
126+
127+
// Set variables
128+
foreach (var entity in entities)
129+
{
130+
entity.Set(
131+
new Position { Vec2 = _random.NextVector2(GraphicsDevice.Viewport.Bounds) },
132+
new Velocity { Vec2 = _random.NextVector2(-0.25f, 0.25f) },
133+
new Sprite { Texture2D = _texture2D, Color = _random.NextColor() }
134+
);
135+
}
136+
}
137+
138+
// Remove a random amount of new entities
139+
if (Keyboard.GetState().IsKeyDown(Keys.L))
140+
{
141+
// Find all entities
142+
var entities = new Entity[_world.Size];
143+
_world.GetEntities(new QueryDescription(), entities.AsSpan());
144+
145+
// Delete random entities
146+
var amount = Random.Shared.Next(0, Math.Min(500, entities.Length));
147+
for (var index = 0; index < amount; index++)
148+
{
149+
var randomIndex = _random.Next(0, entities.Length);
150+
var randomEntity = entities[randomIndex];
151+
152+
if(randomEntity.IsAlive())
153+
{
154+
_world.Destroy(randomEntity);
155+
}
156+
157+
entities[randomIndex] = Entity.Null;
158+
}
159+
}
160+
109161
_movementSystem.Update(in gameTime);
110162
_colorSystem.Update(in gameTime);
111163
base.Update(gameTime);
@@ -116,6 +168,7 @@ protected override void Draw(GameTime gameTime)
116168
_graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
117169
_drawSystem.Update(in gameTime);
118170
Console.WriteLine($"FPS : {1 / gameTime.ElapsedGameTime.TotalSeconds}");
171+
Console.WriteLine($"WORLD: {_world.Size}/{_world.Capacity}");
119172
base.Draw(gameTime);
120173
}
121174

0 commit comments

Comments
 (0)