/** * Prepare a list of modified entities on this frame. * * @return List<SpriteEntity> */ private List<SpriteEntity> getModifiedEntities() { List<SpriteEntity> returned = new ArrayList<SpriteEntity>(); for (SpriteEntity entity : spriteEntities) { int id = entity.getId(); SpriteEntity backedUp = backupEntities.get(id); if (backedUp == null) { // If this entity hasn't been backed up, it's a new one ==> we // send it returned.add(entity); } else { // If this entity has been backed up, we must check whether it // has changed if (!backedUp.isSame(entity)) { returned.add(entity); } backupEntities.remove(id); } } // Send the entity which has been removed this frame for (SpriteEntity entity : backupEntities.values()) { entity.dying = true; entity.clientSpecific = false; // Send to all clients returned.add(entity); } backupEntities.clear(); return returned; }
/** * Do sprite's stuff * * <ul> * <li>animate sprites & persos * <li> * <li>delete if need (the only place to do this) * </ul> * * @param p_blockMoves TRUE=don't animate perso except Zildo */ public void updateSprites(boolean p_blockMoves) { spriteUpdating = true; spriteEntitiesToAdd.clear(); // Backup current entities, if backup buffer is empty if (EngineZildo.game.multiPlayer && backupEntities.size() == 0) { for (SpriteEntity entity : spriteEntities) { SpriteEntity cloned = entity.clone(); backupEntities.put(cloned.getId(), cloned); } } sprColli.initFrame(spriteEntities); persoColli.initFrame(EngineZildo.persoManagement.tab_perso); boolean blockNPC = p_blockMoves || temporaryBlocked; // Do perso animations // Mandatory to do that first, because one perso can be connected to // other sprites int compt = EngineZildo.compteur_animation; // % (3 * 20); for (SpriteEntity entity : spriteEntities) { if (entity.getEntityType().isPerso()) { Perso perso = (Perso) entity; boolean allowedToMoveAndCollide = !blockNPC || /*perso.getInfo() == PersoInfo.ZILDO ||*/ perso.getFollowing() != null; if (allowedToMoveAndCollide) { // Animate persos perso.animate(compt); } perso.finaliseComportement(compt); updateSprModel(perso); SpriteModel spr = perso.getSprModel(); if (allowedToMoveAndCollide) { perso.manageCollision(); } if (!perso.isZildo()) { // Non-zildo sprite haven't same way to display correctly (bad...) perso.setAjustedX(perso.getAjustedX() - (spr.getTaille_x() / 2)); perso.setAjustedY(perso.getAjustedY() - (spr.getTaille_y() - 3)); } } } List<SpriteEntity> toDelete = new ArrayList<SpriteEntity>(); for (Iterator<SpriteEntity> it = spriteEntities.iterator(); it.hasNext(); ) { SpriteEntity entity = it.next(); if (toDelete.contains(entity)) { continue; // It's a dead one } Element element = null; // Calcul physique du sprite if (entity.dying) { toDelete.add(entity); } else if (entity.getEntityType().isEntity()) { entity.animate(); } else if (entity.getEntityType().isElement()) { // X, vX, aX, ... element = (Element) entity; if (!blockNPC || element.isLinkedToZildo()) { element.animate(); if (element.dying) { SpriteEntity linkedOne = element.getLinkedPerso(); // L'élément est arrivé au terme de son existence : on le supprime de la liste if (linkedOne != null && EntityType.ELEMENT == linkedOne.getEntityType()) { toDelete.add(linkedOne); } toDelete.add(element); } else { if (element.isVisible()) { updateSprModel(element); } } } } } // Remove what need to for (SpriteEntity entity : toDelete) { deleteSprite(entity); if (entity.getEntityType().isPerso()) { persoColli.notifyDeletion((Perso) entity); } else { sprColli.notifyDeletion(entity); } } spriteUpdating = false; spriteEntities.addAll(spriteEntitiesToAdd); }