-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor deferredRemovals to not rely on entity indexes
- Loading branch information
1 parent
82eb047
commit 68251c8
Showing
6 changed files
with
97 additions
and
66 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,38 @@ | ||
import removeItems from 'remove-array-items' | ||
|
||
|
||
/** | ||
* Track an entity, component tuple as a unique key in a set. | ||
*/ | ||
|
||
export function create () { | ||
return [ ] | ||
} | ||
|
||
|
||
export function includes (set, entity, componentName) { | ||
for (const entry of set) { | ||
if (entry[0] === entity && entry[1] === componentName) { | ||
return true | ||
} | ||
} | ||
|
||
return false | ||
} | ||
|
||
|
||
export function add (set, entity, componentName) { | ||
set.push([ entity, componentName ]) | ||
} | ||
|
||
|
||
export function remove (set, entity, componentName) { | ||
for (let i=set.length-1; i >= 0; i--) { | ||
const entry = set[i] | ||
if (entry[0] === entity && entry[1] === componentName) { | ||
removeItems(set, i, 1) | ||
return | ||
} | ||
} | ||
} | ||
|
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,19 @@ | ||
import * as ComponentSet from '../component-set.js' | ||
import tap from 'tap' | ||
|
||
|
||
{ | ||
const s = ComponentSet.create() | ||
|
||
const a = { } | ||
//const b = { } | ||
|
||
ComponentSet.add(s, a, 'comp-1') | ||
//ComponentSet.add(s, a, 'comp-2') | ||
//ComponentSet.add(s, b, 'comp-1') | ||
|
||
tap.equal(ComponentSet.includes(s, a, 'comp-1'), true) | ||
|
||
ComponentSet.remove(s, a, 'comp-1') | ||
tap.equal(ComponentSet.includes(s, a, 'comp-1'), false) | ||
} |
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