koota 0.1.9 → 0.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -558,10 +558,10 @@ Number.prototype.get = function(trait2) {
558
558
  const worldCtx = world[$internal];
559
559
  const data = worldCtx.traitData.get(trait2);
560
560
  if (!data) return void 0;
561
- const mask = worldCtx.entityMasks[data.generationId][this];
561
+ const index = this & ENTITY_ID_MASK;
562
+ const mask = worldCtx.entityMasks[data.generationId][index];
562
563
  if ((mask & data.bitflag) !== data.bitflag) return void 0;
563
564
  const traitCtx = trait2[$internal];
564
- const index = this & ENTITY_ID_MASK;
565
565
  const store = traitCtx.stores[worldId];
566
566
  return traitCtx.get(index, store);
567
567
  };
@@ -613,6 +613,7 @@ function destroyEntity(world, entity) {
613
613
  const processedEntities = cachedSet;
614
614
  entityQueue.length = 0;
615
615
  entityQueue.push(entity);
616
+ processedEntities.clear();
616
617
  while (entityQueue.length > 0) {
617
618
  const currentEntity = entityQueue.pop();
618
619
  if (processedEntities.has(currentEntity)) continue;
@@ -1097,16 +1098,14 @@ function createQueryResult(query, world, params) {
1097
1098
  if (options.changeDetection === "auto") {
1098
1099
  const changedPairs = [];
1099
1100
  const atomicSnapshots = [];
1100
- const trackedTraits = [];
1101
- const untrackedTraits = [];
1102
- for (const trait2 of traits) {
1103
- if (world[$internal].trackedTraits.has(trait2)) {
1104
- trackedTraits.push(trait2);
1105
- } else if (query.hasChangedModifiers && query.changedTraits.has(trait2)) {
1106
- trackedTraits.push(trait2);
1107
- } else {
1108
- untrackedTraits.push(trait2);
1109
- }
1101
+ const trackedIndices = [];
1102
+ const untrackedIndices = [];
1103
+ for (let i = 0; i < traits.length; i++) {
1104
+ const trait2 = traits[i];
1105
+ const hasTracked = world[$internal].trackedTraits.has(trait2);
1106
+ const hasChanged = query.hasChangedModifiers && query.changedTraits.has(trait2);
1107
+ if (hasTracked || hasChanged) trackedIndices.push(i);
1108
+ else untrackedIndices.push(i);
1110
1109
  }
1111
1110
  for (let i = 0; i < entities.length; i++) {
1112
1111
  const entity = entities[i];
@@ -1120,10 +1119,11 @@ function createQueryResult(query, world, params) {
1120
1119
  }
1121
1120
  callback(state, entity, i);
1122
1121
  if (!world.has(entity)) continue;
1123
- for (let j = 0; j < trackedTraits.length; j++) {
1124
- const trait2 = trackedTraits[j];
1122
+ for (let j = 0; j < trackedIndices.length; j++) {
1123
+ const index = trackedIndices[j];
1124
+ const trait2 = traits[index];
1125
1125
  const ctx = trait2[$internal];
1126
- const newValue = state[j];
1126
+ const newValue = state[index];
1127
1127
  let changed = false;
1128
1128
  if (ctx.type === "aos") {
1129
1129
  changed = ctx.fastSetWithChangeDetection(eid, stores[j], newValue);
@@ -1135,10 +1135,11 @@ function createQueryResult(query, world, params) {
1135
1135
  }
1136
1136
  if (changed) changedPairs.push([entity, trait2]);
1137
1137
  }
1138
- for (let j = 0; j < untrackedTraits.length; j++) {
1139
- const trait2 = untrackedTraits[j];
1138
+ for (let j = 0; j < untrackedIndices.length; j++) {
1139
+ const index = untrackedIndices[j];
1140
+ const trait2 = traits[index];
1140
1141
  const ctx = trait2[$internal];
1141
- ctx.fastSet(eid, stores[j], state[j]);
1142
+ ctx.fastSet(eid, stores[index], state[index]);
1142
1143
  }
1143
1144
  }
1144
1145
  for (let i = 0; i < changedPairs.length; i++) {
@@ -1302,13 +1303,13 @@ var World = class {
1302
1303
  this[$internal].worldEntity.set(trait2, value);
1303
1304
  }
1304
1305
  destroy() {
1306
+ destroyEntity(this, this[$internal].worldEntity);
1307
+ this[$internal].worldEntity = null;
1305
1308
  this.entities.forEach((entity) => destroyEntity(this, entity));
1306
1309
  this.reset();
1307
1310
  __privateSet(this, _isInitialized, false);
1308
1311
  releaseWorldId(universe.worldIndex, __privateGet(this, _id));
1309
1312
  universe.worlds.splice(universe.worlds.indexOf(this), 1);
1310
- destroyEntity(this, this[$internal].worldEntity);
1311
- this[$internal].worldEntity = null;
1312
1313
  }
1313
1314
  reset() {
1314
1315
  const ctx = this[$internal];
@@ -1317,7 +1318,6 @@ var World = class {
1317
1318
  ctx.notQueries.clear();
1318
1319
  ctx.entityMasks = [[]];
1319
1320
  ctx.bitflag = 1;
1320
- if (this.entities) this.entities.forEach((entity) => entity.destroy());
1321
1321
  ctx.traitData.clear();
1322
1322
  this.traits.clear();
1323
1323
  ctx.queries.clear();
package/dist/index.cjs CHANGED
@@ -595,10 +595,10 @@ Number.prototype.get = function(trait2) {
595
595
  const worldCtx = world[$internal];
596
596
  const data = worldCtx.traitData.get(trait2);
597
597
  if (!data) return void 0;
598
- const mask = worldCtx.entityMasks[data.generationId][this];
598
+ const index = this & ENTITY_ID_MASK;
599
+ const mask = worldCtx.entityMasks[data.generationId][index];
599
600
  if ((mask & data.bitflag) !== data.bitflag) return void 0;
600
601
  const traitCtx = trait2[$internal];
601
- const index = this & ENTITY_ID_MASK;
602
602
  const store = traitCtx.stores[worldId];
603
603
  return traitCtx.get(index, store);
604
604
  };
@@ -650,6 +650,7 @@ function destroyEntity(world, entity) {
650
650
  const processedEntities = cachedSet;
651
651
  entityQueue.length = 0;
652
652
  entityQueue.push(entity);
653
+ processedEntities.clear();
653
654
  while (entityQueue.length > 0) {
654
655
  const currentEntity = entityQueue.pop();
655
656
  if (processedEntities.has(currentEntity)) continue;
@@ -1075,16 +1076,14 @@ function createQueryResult(query, world, params) {
1075
1076
  if (options.changeDetection === "auto") {
1076
1077
  const changedPairs = [];
1077
1078
  const atomicSnapshots = [];
1078
- const trackedTraits = [];
1079
- const untrackedTraits = [];
1080
- for (const trait2 of traits) {
1081
- if (world[$internal].trackedTraits.has(trait2)) {
1082
- trackedTraits.push(trait2);
1083
- } else if (query.hasChangedModifiers && query.changedTraits.has(trait2)) {
1084
- trackedTraits.push(trait2);
1085
- } else {
1086
- untrackedTraits.push(trait2);
1087
- }
1079
+ const trackedIndices = [];
1080
+ const untrackedIndices = [];
1081
+ for (let i = 0; i < traits.length; i++) {
1082
+ const trait2 = traits[i];
1083
+ const hasTracked = world[$internal].trackedTraits.has(trait2);
1084
+ const hasChanged = query.hasChangedModifiers && query.changedTraits.has(trait2);
1085
+ if (hasTracked || hasChanged) trackedIndices.push(i);
1086
+ else untrackedIndices.push(i);
1088
1087
  }
1089
1088
  for (let i = 0; i < entities.length; i++) {
1090
1089
  const entity = entities[i];
@@ -1098,10 +1097,11 @@ function createQueryResult(query, world, params) {
1098
1097
  }
1099
1098
  callback(state, entity, i);
1100
1099
  if (!world.has(entity)) continue;
1101
- for (let j = 0; j < trackedTraits.length; j++) {
1102
- const trait2 = trackedTraits[j];
1100
+ for (let j = 0; j < trackedIndices.length; j++) {
1101
+ const index = trackedIndices[j];
1102
+ const trait2 = traits[index];
1103
1103
  const ctx = trait2[$internal];
1104
- const newValue = state[j];
1104
+ const newValue = state[index];
1105
1105
  let changed = false;
1106
1106
  if (ctx.type === "aos") {
1107
1107
  changed = ctx.fastSetWithChangeDetection(eid, stores[j], newValue);
@@ -1113,10 +1113,11 @@ function createQueryResult(query, world, params) {
1113
1113
  }
1114
1114
  if (changed) changedPairs.push([entity, trait2]);
1115
1115
  }
1116
- for (let j = 0; j < untrackedTraits.length; j++) {
1117
- const trait2 = untrackedTraits[j];
1116
+ for (let j = 0; j < untrackedIndices.length; j++) {
1117
+ const index = untrackedIndices[j];
1118
+ const trait2 = traits[index];
1118
1119
  const ctx = trait2[$internal];
1119
- ctx.fastSet(eid, stores[j], state[j]);
1120
+ ctx.fastSet(eid, stores[index], state[index]);
1120
1121
  }
1121
1122
  }
1122
1123
  for (let i = 0; i < changedPairs.length; i++) {
@@ -1280,13 +1281,13 @@ var World = class {
1280
1281
  this[$internal].worldEntity.set(trait2, value);
1281
1282
  }
1282
1283
  destroy() {
1284
+ destroyEntity(this, this[$internal].worldEntity);
1285
+ this[$internal].worldEntity = null;
1283
1286
  this.entities.forEach((entity) => destroyEntity(this, entity));
1284
1287
  this.reset();
1285
1288
  __privateSet(this, _isInitialized, false);
1286
1289
  releaseWorldId(universe.worldIndex, __privateGet(this, _id));
1287
1290
  universe.worlds.splice(universe.worlds.indexOf(this), 1);
1288
- destroyEntity(this, this[$internal].worldEntity);
1289
- this[$internal].worldEntity = null;
1290
1291
  }
1291
1292
  reset() {
1292
1293
  const ctx = this[$internal];
@@ -1295,7 +1296,6 @@ var World = class {
1295
1296
  ctx.notQueries.clear();
1296
1297
  ctx.entityMasks = [[]];
1297
1298
  ctx.bitflag = 1;
1298
- if (this.entities) this.entities.forEach((entity) => entity.destroy());
1299
1299
  ctx.traitData.clear();
1300
1300
  this.traits.clear();
1301
1301
  ctx.queries.clear();
package/dist/index.js CHANGED
@@ -13,7 +13,7 @@ import {
13
13
  relation,
14
14
  trait,
15
15
  universe
16
- } from "./chunk-L2TCLFSQ.js";
16
+ } from "./chunk-WPSZAQ4Y.js";
17
17
  export {
18
18
  $internal,
19
19
  Not,
package/dist/react.cjs CHANGED
@@ -587,10 +587,10 @@ Number.prototype.get = function(trait2) {
587
587
  const worldCtx = world[$internal];
588
588
  const data = worldCtx.traitData.get(trait2);
589
589
  if (!data) return void 0;
590
- const mask = worldCtx.entityMasks[data.generationId][this];
590
+ const index = this & ENTITY_ID_MASK;
591
+ const mask = worldCtx.entityMasks[data.generationId][index];
591
592
  if ((mask & data.bitflag) !== data.bitflag) return void 0;
592
593
  const traitCtx = trait2[$internal];
593
- const index = this & ENTITY_ID_MASK;
594
594
  const store = traitCtx.stores[worldId];
595
595
  return traitCtx.get(index, store);
596
596
  };
@@ -642,6 +642,7 @@ function destroyEntity(world, entity) {
642
642
  const processedEntities = cachedSet;
643
643
  entityQueue.length = 0;
644
644
  entityQueue.push(entity);
645
+ processedEntities.clear();
645
646
  while (entityQueue.length > 0) {
646
647
  const currentEntity = entityQueue.pop();
647
648
  if (processedEntities.has(currentEntity)) continue;
@@ -1067,16 +1068,14 @@ function createQueryResult(query, world, params) {
1067
1068
  if (options.changeDetection === "auto") {
1068
1069
  const changedPairs = [];
1069
1070
  const atomicSnapshots = [];
1070
- const trackedTraits = [];
1071
- const untrackedTraits = [];
1072
- for (const trait2 of traits) {
1073
- if (world[$internal].trackedTraits.has(trait2)) {
1074
- trackedTraits.push(trait2);
1075
- } else if (query.hasChangedModifiers && query.changedTraits.has(trait2)) {
1076
- trackedTraits.push(trait2);
1077
- } else {
1078
- untrackedTraits.push(trait2);
1079
- }
1071
+ const trackedIndices = [];
1072
+ const untrackedIndices = [];
1073
+ for (let i = 0; i < traits.length; i++) {
1074
+ const trait2 = traits[i];
1075
+ const hasTracked = world[$internal].trackedTraits.has(trait2);
1076
+ const hasChanged = query.hasChangedModifiers && query.changedTraits.has(trait2);
1077
+ if (hasTracked || hasChanged) trackedIndices.push(i);
1078
+ else untrackedIndices.push(i);
1080
1079
  }
1081
1080
  for (let i = 0; i < entities.length; i++) {
1082
1081
  const entity = entities[i];
@@ -1090,10 +1089,11 @@ function createQueryResult(query, world, params) {
1090
1089
  }
1091
1090
  callback(state, entity, i);
1092
1091
  if (!world.has(entity)) continue;
1093
- for (let j = 0; j < trackedTraits.length; j++) {
1094
- const trait2 = trackedTraits[j];
1092
+ for (let j = 0; j < trackedIndices.length; j++) {
1093
+ const index = trackedIndices[j];
1094
+ const trait2 = traits[index];
1095
1095
  const ctx = trait2[$internal];
1096
- const newValue = state[j];
1096
+ const newValue = state[index];
1097
1097
  let changed = false;
1098
1098
  if (ctx.type === "aos") {
1099
1099
  changed = ctx.fastSetWithChangeDetection(eid, stores[j], newValue);
@@ -1105,10 +1105,11 @@ function createQueryResult(query, world, params) {
1105
1105
  }
1106
1106
  if (changed) changedPairs.push([entity, trait2]);
1107
1107
  }
1108
- for (let j = 0; j < untrackedTraits.length; j++) {
1109
- const trait2 = untrackedTraits[j];
1108
+ for (let j = 0; j < untrackedIndices.length; j++) {
1109
+ const index = untrackedIndices[j];
1110
+ const trait2 = traits[index];
1110
1111
  const ctx = trait2[$internal];
1111
- ctx.fastSet(eid, stores[j], state[j]);
1112
+ ctx.fastSet(eid, stores[index], state[index]);
1112
1113
  }
1113
1114
  }
1114
1115
  for (let i = 0; i < changedPairs.length; i++) {
@@ -1272,13 +1273,13 @@ var World = class {
1272
1273
  this[$internal].worldEntity.set(trait2, value);
1273
1274
  }
1274
1275
  destroy() {
1276
+ destroyEntity(this, this[$internal].worldEntity);
1277
+ this[$internal].worldEntity = null;
1275
1278
  this.entities.forEach((entity) => destroyEntity(this, entity));
1276
1279
  this.reset();
1277
1280
  __privateSet(this, _isInitialized, false);
1278
1281
  releaseWorldId(universe.worldIndex, __privateGet(this, _id));
1279
1282
  universe.worlds.splice(universe.worlds.indexOf(this), 1);
1280
- destroyEntity(this, this[$internal].worldEntity);
1281
- this[$internal].worldEntity = null;
1282
1283
  }
1283
1284
  reset() {
1284
1285
  const ctx = this[$internal];
@@ -1287,7 +1288,6 @@ var World = class {
1287
1288
  ctx.notQueries.clear();
1288
1289
  ctx.entityMasks = [[]];
1289
1290
  ctx.bitflag = 1;
1290
- if (this.entities) this.entities.forEach((entity) => entity.destroy());
1291
1291
  ctx.traitData.clear();
1292
1292
  this.traits.clear();
1293
1293
  ctx.queries.clear();
package/dist/react.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  $internal,
3
3
  createWorld
4
- } from "./chunk-L2TCLFSQ.js";
4
+ } from "./chunk-WPSZAQ4Y.js";
5
5
 
6
6
  // ../react/src/hooks/use-query.ts
7
7
  import { useEffect, useMemo, useReducer } from "react";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koota",
3
- "version": "0.1.9",
3
+ "version": "0.1.11",
4
4
  "description": "🌎 Performant real-time state management for React and TypeScript",
5
5
  "license": "ISC",
6
6
  "type": "module",
@@ -37,10 +37,11 @@
37
37
  "@types/three": "^0.162.0",
38
38
  "react": "^18.3.1",
39
39
  "react-dom": "^18.3.1",
40
+ "rimraf": "^6.0.1",
40
41
  "tsup": "^8.3.0",
41
42
  "@koota/core": "0.0.1",
42
- "@koota/react": "0.0.1",
43
- "tsconfig": "0.1.0"
43
+ "tsconfig": "0.1.0",
44
+ "@koota/react": "0.0.1"
44
45
  },
45
46
  "peerDependencies": {
46
47
  "@react-three/fiber": "^8.17.10",
@@ -60,7 +61,7 @@
60
61
  }
61
62
  },
62
63
  "scripts": {
63
- "build": "tsup src/index.ts src/react.ts --format esm,cjs --dts --dts-resolve && tsx scripts/copy-readme.ts && tsx scripts/copy-react-files.ts",
64
+ "build": "rimraf dist react && tsup src/index.ts src/react.ts --format esm,cjs --dts --dts-resolve && tsx scripts/copy-readme.ts && tsx scripts/copy-react-files.ts",
64
65
  "test": "vitest --environment=jsdom"
65
66
  }
66
67
  }
package/react/index.cjs CHANGED
@@ -587,10 +587,10 @@ Number.prototype.get = function(trait2) {
587
587
  const worldCtx = world[$internal];
588
588
  const data = worldCtx.traitData.get(trait2);
589
589
  if (!data) return void 0;
590
- const mask = worldCtx.entityMasks[data.generationId][this];
590
+ const index = this & ENTITY_ID_MASK;
591
+ const mask = worldCtx.entityMasks[data.generationId][index];
591
592
  if ((mask & data.bitflag) !== data.bitflag) return void 0;
592
593
  const traitCtx = trait2[$internal];
593
- const index = this & ENTITY_ID_MASK;
594
594
  const store = traitCtx.stores[worldId];
595
595
  return traitCtx.get(index, store);
596
596
  };
@@ -642,6 +642,7 @@ function destroyEntity(world, entity) {
642
642
  const processedEntities = cachedSet;
643
643
  entityQueue.length = 0;
644
644
  entityQueue.push(entity);
645
+ processedEntities.clear();
645
646
  while (entityQueue.length > 0) {
646
647
  const currentEntity = entityQueue.pop();
647
648
  if (processedEntities.has(currentEntity)) continue;
@@ -1067,16 +1068,14 @@ function createQueryResult(query, world, params) {
1067
1068
  if (options.changeDetection === "auto") {
1068
1069
  const changedPairs = [];
1069
1070
  const atomicSnapshots = [];
1070
- const trackedTraits = [];
1071
- const untrackedTraits = [];
1072
- for (const trait2 of traits) {
1073
- if (world[$internal].trackedTraits.has(trait2)) {
1074
- trackedTraits.push(trait2);
1075
- } else if (query.hasChangedModifiers && query.changedTraits.has(trait2)) {
1076
- trackedTraits.push(trait2);
1077
- } else {
1078
- untrackedTraits.push(trait2);
1079
- }
1071
+ const trackedIndices = [];
1072
+ const untrackedIndices = [];
1073
+ for (let i = 0; i < traits.length; i++) {
1074
+ const trait2 = traits[i];
1075
+ const hasTracked = world[$internal].trackedTraits.has(trait2);
1076
+ const hasChanged = query.hasChangedModifiers && query.changedTraits.has(trait2);
1077
+ if (hasTracked || hasChanged) trackedIndices.push(i);
1078
+ else untrackedIndices.push(i);
1080
1079
  }
1081
1080
  for (let i = 0; i < entities.length; i++) {
1082
1081
  const entity = entities[i];
@@ -1090,10 +1089,11 @@ function createQueryResult(query, world, params) {
1090
1089
  }
1091
1090
  callback(state, entity, i);
1092
1091
  if (!world.has(entity)) continue;
1093
- for (let j = 0; j < trackedTraits.length; j++) {
1094
- const trait2 = trackedTraits[j];
1092
+ for (let j = 0; j < trackedIndices.length; j++) {
1093
+ const index = trackedIndices[j];
1094
+ const trait2 = traits[index];
1095
1095
  const ctx = trait2[$internal];
1096
- const newValue = state[j];
1096
+ const newValue = state[index];
1097
1097
  let changed = false;
1098
1098
  if (ctx.type === "aos") {
1099
1099
  changed = ctx.fastSetWithChangeDetection(eid, stores[j], newValue);
@@ -1105,10 +1105,11 @@ function createQueryResult(query, world, params) {
1105
1105
  }
1106
1106
  if (changed) changedPairs.push([entity, trait2]);
1107
1107
  }
1108
- for (let j = 0; j < untrackedTraits.length; j++) {
1109
- const trait2 = untrackedTraits[j];
1108
+ for (let j = 0; j < untrackedIndices.length; j++) {
1109
+ const index = untrackedIndices[j];
1110
+ const trait2 = traits[index];
1110
1111
  const ctx = trait2[$internal];
1111
- ctx.fastSet(eid, stores[j], state[j]);
1112
+ ctx.fastSet(eid, stores[index], state[index]);
1112
1113
  }
1113
1114
  }
1114
1115
  for (let i = 0; i < changedPairs.length; i++) {
@@ -1272,13 +1273,13 @@ var World = class {
1272
1273
  this[$internal].worldEntity.set(trait2, value);
1273
1274
  }
1274
1275
  destroy() {
1276
+ destroyEntity(this, this[$internal].worldEntity);
1277
+ this[$internal].worldEntity = null;
1275
1278
  this.entities.forEach((entity) => destroyEntity(this, entity));
1276
1279
  this.reset();
1277
1280
  __privateSet(this, _isInitialized, false);
1278
1281
  releaseWorldId(universe.worldIndex, __privateGet(this, _id));
1279
1282
  universe.worlds.splice(universe.worlds.indexOf(this), 1);
1280
- destroyEntity(this, this[$internal].worldEntity);
1281
- this[$internal].worldEntity = null;
1282
1283
  }
1283
1284
  reset() {
1284
1285
  const ctx = this[$internal];
@@ -1287,7 +1288,6 @@ var World = class {
1287
1288
  ctx.notQueries.clear();
1288
1289
  ctx.entityMasks = [[]];
1289
1290
  ctx.bitflag = 1;
1290
- if (this.entities) this.entities.forEach((entity) => entity.destroy());
1291
1291
  ctx.traitData.clear();
1292
1292
  this.traits.clear();
1293
1293
  ctx.queries.clear();
package/react/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  $internal,
3
3
  createWorld
4
- } from "../dist/chunk-L2TCLFSQ.js";
4
+ } from "../dist/chunk-WPSZAQ4Y.js";
5
5
 
6
6
  // ../react/src/hooks/use-query.ts
7
7
  import { useEffect, useMemo, useReducer } from "react";