diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/OtherPlayerCharactersModel.java b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/OtherPlayerCharactersModel.java index dc5ab96..80f6f6b 100644 --- a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/OtherPlayerCharactersModel.java +++ b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/OtherPlayerCharactersModel.java @@ -21,6 +21,7 @@ import java.math.BigDecimal; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -36,6 +37,7 @@ private CharactersConnection con = null; private int nextConnectRenaimdTime = 0; private int connectInterval = 300; + private Map visibleCharacters = new HashMap<>(); public OtherPlayerCharactersModel(RealTime3DFragment fragment, Universe universe) { this.fragment = fragment; @@ -63,16 +65,22 @@ @Override public void onResponse(String response) { + Map lastVisibleCharacters = new HashMap<>(visibleCharacters); + visibleCharacters.clear(); + JSON json = new JSON(); Map m = json.decode(response); for (Map.Entry entry: m.entrySet()) { + visibleCharacters.put(entry.getKey(), 1); + ArrayList properties = new ArrayList<>(); Map player = entry.getValue(); // 情報の取得 Map position = (Map)player.get("position"); + Map angle = (Map)player.get("angle"); Position3D positionProp = new Position3D(((BigDecimal)position.get("x")).doubleValue(), ((BigDecimal)position.get("y")).doubleValue(), ((BigDecimal)position.get("z")).doubleValue()); - Quaternion3D quaProp = new Quaternion3D(((BigDecimal)position.get("vx")).doubleValue(), ((BigDecimal)position.get("vy")).doubleValue(), ((BigDecimal)position.get("vz")).doubleValue(), ((BigDecimal)position.get("a")).doubleValue()); + Quaternion3D quaProp = new Quaternion3D(((BigDecimal)angle.get("vx")).doubleValue(), ((BigDecimal)angle.get("vy")).doubleValue(), ((BigDecimal)angle.get("vz")).doubleValue(), ((BigDecimal)angle.get("a")).doubleValue()); properties.add(positionProp); properties.add(quaProp); @@ -101,5 +109,12 @@ } universe.apply(entry.getKey(), properties); } + + // 見えなくなったキャラクターの削除 + for (String key : lastVisibleCharacters.keySet()) { + if (visibleCharacters.get(key) == null) { + universe.displace(key); + } + } } }