@Override
 public void updatedComponentState(int entityId, int componentIndex, Object[] values) {
   for (int i = 0, n = _listeners.size(); i < n; ++i) {
     EntityTrackerCommunicator communicator = _listeners.get(i);
     communicator.updatedComponentState(entityId, componentIndex, values);
   }
 }
Пример #2
0
 @Override
 protected void inserted(Entity e) {
   super.inserted(e);
   if (tm.get(e).getParent() != null) {
     tm.get(tm.get(e).getParent()).addChild(e);
   } else if (!roots.contains(e)) roots.add(e);
 }
Пример #3
0
  private void transform(Entity entity) {
    Bag<Entity> children = tm.get(entity).getChildren();
    SkeletonComponent skl = sm.get(entity);
    for (int i = 0, s = children.size(); s > i; i++) {
      TransformComponent childTC = tm.get(children.get(i));

      childTC.getWorldTransform().set(childTC.getLocalTransform());

      if (childTC.getJoint() != -1 && skl != null) {
        TempVars tempVars = TempVars.get();

        skl.getCurrentPosesMatrices()[childTC.getJoint()].mult(
            skl.getBaseSkeleton().getJoints().get(childTC.getJoint()).base, tempVars.tempMat4);

        tempVars.tempMat4.toTranslationVector(tempVars.vect1);
        tempVars.tempMat4.toRotationQuat(tempVars.quat1);
        tempVars.tempMat4.toScaleVector(tempVars.vect2);
        tempVars.tempTF.set(tempVars.vect1, tempVars.quat1, tempVars.vect2);
        childTC.getWorldTransform().combineFromParent(tempVars.tempTF);

        tempVars.release();
      } else {
      }
      childTC.getWorldTransform().combineFromParent(tm.get(entity).getWorldTransform());
      transform(children.get(i));
    }
  }
Пример #4
0
  private static Bag<Class<? extends Component>> toClasses(
      Bag<Component> source, Bag<Class<? extends Component>> target) {
    for (int i = 0; i < source.size(); i++) {
      target.add(source.get(i).getClass());
    }

    return target;
  }
 @Override
 public void addedEntity(int entityId, BitSet components) {
   for (int i = 0, n = _listeners.size(); i < n; ++i) {
     EntityTrackerCommunicator communicator = _listeners.get(i);
     communicator.addedEntity(entityId, components);
   }
   _entities.put(entityId, components);
 }
 @Override
 public void addedComponentType(int index, ComponentTypeInfo info) {
   for (int i = 0, n = _listeners.size(); i < n; ++i) {
     EntityTrackerCommunicator communicator = _listeners.get(i);
     communicator.addedComponentType(index, info);
   }
   _componentTypes.set(index, info);
 }
 @Override
 public void addedManager(String name) {
   for (int i = 0, n = _listeners.size(); i < n; ++i) {
     EntityTrackerCommunicator communicator = _listeners.get(i);
     communicator.addedManager(name);
   }
   _managers.add(name);
 }
Пример #8
0
 @Override
 protected void processEntities() {
   for (int i = 0, s = roots.size(); s > i; i++) {
     TransformComponent rootTC = tm.get(roots.get(i));
     rootTC.getWorldTransform().set(rootTC.getLocalTransform());
     transform(roots.get(i));
   }
 }
 @Override
 public void deletedEntity(int entityId) {
   for (int i = 0, n = _listeners.size(); i < n; ++i) {
     EntityTrackerCommunicator communicator = _listeners.get(i);
     communicator.deletedEntity(entityId);
   }
   _entities.remove(entityId);
 }
Пример #10
0
 /** Fetch unique identity for passed composition. */
 int getIdentity(BitSet components) {
   Object[] bitsets = composition.getData();
   int size = composition.size();
   for (int i = NO_COMPONENTS; size > i; i++) { // want to start from 1 so that 0 can mean null
     if (components.equals(bitsets[i])) return i;
   }
   composition.add((BitSet) components.clone());
   return size;
 }
 @Override
 public void updatedEntitySystem(int systemIndex, int entitiesCount, int maxEntitiesCount) {
   for (int i = 0, n = _listeners.size(); i < n; ++i) {
     EntityTrackerCommunicator communicator = _listeners.get(i);
     communicator.updatedEntitySystem(systemIndex, entitiesCount, maxEntitiesCount);
   }
   _entitySystemsEntitiesCount.set(systemIndex, entitiesCount);
   _entitySystemsMaxEntitiesCount.set(systemIndex, maxEntitiesCount);
 }
Пример #12
0
 Entity obtain() {
   if (recycled.isEmpty()) {
     return new Entity(world, nextId++);
   } else {
     Entity e = recycled.removeLast();
     entityToIdentity.set(e.getId(), 0);
     return e;
   }
 }
Пример #13
0
 public void removeFromTeam(String player) {
   String team = teamByPlayer.remove(player);
   if (team != null) {
     Bag<String> players = playersByTeam.get(team);
     if (players != null) {
       players.remove(player);
     }
   }
 }
Пример #14
0
 public void setParent(Entity parent, Entity child, String bone) {
   if (tm.get(child).getParent() != null) tm.get(tm.get(child).getParent()).removeChild(child);
   else if (parent != null) roots.remove(child);
   tm.get(child).setParent(parent, bone);
   if (parent != null) {
     tm.get(parent).addChild(child);
   } else {
     if (!roots.contains(child)) roots.add(child);
   }
 }
 @Override
 public void addedSystem(
     int index, String name, BitSet allTypes, BitSet oneTypes, BitSet notTypes) {
   for (int i = 0, n = _listeners.size(); i < n; ++i) {
     EntityTrackerCommunicator communicator = _listeners.get(i);
     communicator.addedSystem(index, name, allTypes, oneTypes, notTypes);
   }
   _systems.add(Tuple3.create(index, name, new AspectInfo(allTypes, oneTypes, notTypes)));
   _entitySystemsEntitiesCount.set(index, 0);
   _entitySystemsMaxEntitiesCount.set(index, 0);
 }
Пример #16
0
  public void setTeam(String player, String team) {
    removeFromTeam(player);

    teamByPlayer.put(player, team);

    Bag<String> players = playersByTeam.get(team);
    if (players == null) {
      players = new Bag<String>();
      playersByTeam.put(team, players);
    }
    players.add(player);
  }
Пример #17
0
  void synchronize(EntitySubscription es) {
    for (int i = 1; highestSeenIdentity >= i; i++) {
      BitSet componentBits = identityResolver.composition.get(i);
      es.processComponentIdentity(i, componentBits);
    }

    for (int i = 0; i < entities.size(); i++) {
      Entity e = entities.get(i);
      if (e != null && !disabled.get(e.id)) es.check(e.id);
    }

    es.informEntityChanges();
    es.rebuildCompressedActives();
  }
Пример #18
0
 @Override
 protected void removed(Entity e) {
   super.removed(e);
   if (tm.get(e).getParent() != null) {
     tm.get(tm.get(e).getParent()).removeChild(e);
   } else roots.remove(e);
 }
Пример #19
0
  public ArchetypeMapper(World world, IntBag toSave) {
    int[] ids = toSave.getData();
    Bag<Component> components = new Bag<Component>();
    Bag<Class<? extends Component>> types = new Bag<Class<? extends Component>>();

    for (int i = 0, s = toSave.size(); s > i; i++) {
      int compositionId = world.getEntity(ids[i]).getCompositionId();
      if (!compositionIdMapper.containsKey(compositionId)) {
        components.clear();
        types.clear();

        world.getComponentManager().getComponentsFor(ids[i], components);
        compositionIdMapper.put(compositionId, new TransmuterEntry(toClasses(components, types)));
      }
    }
  }
Пример #20
0
  /**
   * Removes the entity from the manager, freeing it's id for new entities.
   *
   * @param entityId the entity to remove
   */
  @Override
  public void deleted(int entityId) {
    Entity entity = entities.get(entityId);
    if (entity == null) return;

    entities.set(entityId, null);

    // usually never happens but:
    // this happens when an entity is deleted before
    // it is added to the world, ie; created and deleted
    // before World#process has been called
    newlyCreatedEntityIds.set(entityId, false);

    recyclingEntityFactory.free(entity);

    disabled.clear(entityId);
  }
Пример #21
0
  /**
   * Create a new entity.
   *
   * @return a new entity
   */
  protected Entity createEntityInstance() {
    Entity e = recyclingEntityFactory.obtain();
    entityToIdentity.set(e.getId(), 0);

    // growing backing array just in case
    entities.set(e.getId(), e);
    newlyCreatedEntityIds.set(e.id);
    return e;
  }
Пример #22
0
  /**
   * Gets the component type for the given component class.
   *
   * <p>If no component type exists yet, a new one will be created and stored for later retrieval.
   *
   * @param c the component's class to get the type for
   * @return the component's {@link ComponentType}
   */
  public ComponentType getTypeFor(Class<? extends Component> c) {
    ComponentType type = componentTypes.get(c);

    if (type == null) {
      int index = componentTypeCount++;
      type = new ComponentType(c, index);
      componentTypes.put(c, type);
      types.set(index, type);
    }

    return type;
  }
Пример #23
0
    void recycle() {
      int s = limbo.size();
      if (s == 0) return;

      Object[] data = limbo.getData();
      for (int i = 0; s > i; i++) {
        Entity e = (Entity) data[i];
        recycled.add(e);
        data[i] = null;
      }
      limbo.setSize(0);
    }
  /** Let framework take care of internal business. */
  public void loopStart() {
    if (!refreshed.isEmpty()) {
      for (int i = 0; refreshed.size() > i; i++) {
        entityManager.refresh(refreshed.get(i));
      }
      refreshed.clear();
    }

    if (!deleted.isEmpty()) {
      for (int i = 0; deleted.size() > i; i++) {
        Entity e = deleted.get(i);
        groupManager.remove(e);
        entityManager.remove(e);
      }
      deleted.clear();
    }
  }
        @Override
        public RawConnectionCommunicator getListener(String remoteName) {
          // Server requests communicator for given remote.

          EntityTrackerCommunicator newCommunicator =
              new EntityTrackerCommunicator() {
                @Override
                public void connected(
                    SocketAddress remoteAddress, RawConnectionOutputListener output) {
                  super.connected(remoteAddress, output);
                  injectWorldController(_worldController);

                  for (int i = 0, n = _systems.size(); i < n; ++i) {
                    final Tuple3<Integer, String, AspectInfo> system = _systems.get(i);
                    final AspectInfo aspects = system.item3;
                    addedSystem(
                        system.item1,
                        system.item2,
                        aspects.allTypes,
                        aspects.oneTypes,
                        aspects.exclusionTypes);
                  }

                  for (int i = 0, n = _managers.size(); i < n; ++i) {
                    addedManager(_managers.get(i));
                  }

                  for (int i = 0, n = _componentTypes.size(); i < n; ++i) {
                    addedComponentType(i, _componentTypes.get(i));
                  }

                  for (int i = 0, n = _systems.size(); i < n; ++i) {
                    if (_entitySystemsEntitiesCount.get(i) != null) {
                      int entitiesCount = _entitySystemsEntitiesCount.get(i);
                      int maxEntitiesCount = _entitySystemsMaxEntitiesCount.get(i);
                      updatedEntitySystem(i, entitiesCount, maxEntitiesCount);
                    }
                  }

                  for (Entry<Integer, BitSet> entity : _entities.entrySet()) {
                    addedEntity(entity.getKey(), entity.getValue());
                  }
                }
              };
          _listeners.add(newCommunicator);

          return newCommunicator;
        }
 /**
  * Ensure all systems are notified of changes to this entity.
  *
  * @param e entity
  */
 public void refreshEntity(Entity e) {
   refreshed.add(e);
 }
 private void insertToSystem(Entity e) {
   actives.add(e);
   e.getSystemBits().set(this.getSystemIndex());
   inserted(e);
 }
 private void removeFromSystem(Entity e) {
   actives.remove(e);
   e.getSystemBits().clear(this.getSystemIndex());
   removed(e);
 }
Пример #29
0
 protected boolean isPackedComponent(int index) {
   return types.get(index).isPackedComponent();
 }
 /**
  * Delete the provided entity from the world.
  *
  * @param e entity
  */
 public void deleteEntity(Entity e) {
   if (!deleted.contains(e)) deleted.add(e);
 }