sturdykeep / backbone

Strong & flexible game library for Flutter, that drinks milk 🥛
Other
37 stars 1 forks source link

Large archetypeBuckets[archetype] list makes frame too low #83

Closed gtgalone closed 1 year ago

gtgalone commented 1 year ago

In this code if (bucket.contains(entity) == false) { This line is not working. It makes large list and frame too low.


/// Push an entity into an existing archetype
  void putIntoBucket(Entity entity) {
    // Add the trait to the new archetype storage
    final archetype = entity.archetype;
    if (archetype.length > 0) {
      if (archetypeBuckets.containsKey(archetype) == false) {
        throw Exception('Archetype $archetype is not registered');
      }

      // Add only if it's not already in the bucket
      final bucket = archetypeBuckets[archetype]!;
      if (bucket.contains(entity) == false) {
        bucket.add(entity);
      }

      // if necessary add to the non-empty bucket cache
      final index = nonEmptyBucketKeys.indexOf(archetype);
      if (index == -1) {
        nonEmptyBucketKeys.add(archetype);
        nonEmptyBucketValues.add(bucket);
      }
    }
  }
gtgalone commented 1 year ago

Sorry. I called registerEntity(this) again in my side.

I didn't know that in Entity constructor there is registerEntity(this).