-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ECS - optimize: add TypeCache for Entity.AddComponent<>() / RemoveCom…
…ponent<>()
- Loading branch information
Showing
5 changed files
with
100 additions
and
4 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
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,42 @@ | ||
// Copyright (c) Ullrich Praetz - https://github.com/friflo. All rights reserved. | ||
// See LICENSE file in the project root for full license information. | ||
|
||
// ReSharper disable once CheckNamespace | ||
namespace Friflo.Engine.ECS; | ||
|
||
internal struct TypeCache | ||
{ | ||
private byte type0; // 1 | ||
private byte type1; // 1 | ||
private byte type2; // 1 | ||
private byte type3; // 1 | ||
|
||
private int index0; // 4 | ||
private int index1; // 4 | ||
private int index2; // 4 | ||
private int index3; // 4 | ||
|
||
private int next; // 4 | ||
|
||
internal int FindType(int type) | ||
{ | ||
if (type == type0) return index0; | ||
if (type == type1) return index1; | ||
if (type == type2) return index2; | ||
if (type == type3) return index3; | ||
return -1; | ||
} | ||
|
||
internal Archetype Cache(byte type, Archetype archetype) | ||
{ | ||
var index = archetype.archIndex; | ||
var at = next++ % 4; | ||
switch (at) { | ||
case 0: type0 = type; index0 = index; break; | ||
case 1: type1 = type; index1 = index; break; | ||
case 2: type2 = type; index2 = index; break; | ||
case 3: type3 = type; index3 = index; break; | ||
} | ||
return archetype; | ||
} | ||
} |
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