diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser index d7116a2..9867642 100644 --- a/.idea/caches/build_file_checksums.ser +++ b/.idea/caches/build_file_checksums.ser Binary files differ diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/Bullet.java b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/Bullet.java new file mode 100644 index 0000000..1c86634 --- /dev/null +++ b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/Bullet.java @@ -0,0 +1,71 @@ +package org.ntlab.radishforandroidstudio.cactusClient.models; + +import net.arnx.jsonic.JSONHint; + +import org.ntlab.radishforandroidstudio.framework.model3D.Object3D; +import org.ntlab.radishforandroidstudio.framework.model3D.Position3D; +import org.ntlab.radishforandroidstudio.framework.model3D.Quaternion3D; + +public class Bullet extends Entity{ + private String playerID; + private Position3D position; + private Quaternion3D angle; + private boolean isAlive = true; + + public Bullet() { + // JSONエンコード時の呼び出し用 + } + + public Bullet(String playerID, Position3D position, Quaternion3D angle) { +// Object3D body = BulletModelManager.getInstance().getBulletModel(0).createObject(); // モデルIDは仮に0を指定 +// setPlaceable(body); + setPlayerID(playerID); + setPosition(position); + setAngle(angle); + } + + public String getPlayerID() { + return playerID; + } + + public Position3D getPosition() { + return position; + } + + public Quaternion3D getAngle() { + return angle; + } + + @JSONHint(ignore = true) + public boolean isAlive() { + return isAlive; + } + + public void setPlayerID(String playerID) { + this.playerID = playerID; + } + + public void setPosition(Position3D position) { + this.position = position; +// if (this.placeable != null) { +// ((Object3D)this.placeable.getBody()).setPosition(position); +// } + } + + public void setAngle(Quaternion3D angle) { + this.angle = angle; +// if (this.placeable != null) { +// ((Object3D)this.placeable.getBody()).apply(angle, false); +// } + } + + @JSONHint(ignore = true) + public void setAlive(boolean isAlive) { + this.isAlive = isAlive; + } + + public void update(Position3D position, Quaternion3D angle) { + setPosition(position); + setAngle(angle); + } +} diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/BulletsManager.java b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/BulletsManager.java index 28e3d06..d0e0a76 100644 --- a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/BulletsManager.java +++ b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/BulletsManager.java @@ -12,17 +12,16 @@ import org.ntlab.radishforandroidstudio.framework.model3D.Property3D; import org.ntlab.radishforandroidstudio.framework.model3D.Universe; import org.ntlab.radishforandroidstudio.framework.network.CallBack; -import org.ntlab.radishforandroidstudio.framework.physics.Velocity3D; import org.ntlab.radishforandroidstudio.java3d.Appearance; import org.ntlab.radishforandroidstudio.java3d.Material; -import org.ntlab.radishforandroidstudio.java3d.Vector3d; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; import java.util.Set; -public class BulletsManager implements GameBaseModel, CallBack { +public class +BulletsManager implements GameBaseModel, CallBack { private Universe universe; private Resources resources; private BulletGetConnection con; @@ -76,49 +75,49 @@ Map lastPlayerVisibleBullets = new HashMap<>(playerVisibleBullets); visibleBullets.clear(); JSON json = new JSON(); - ArrayList> m = json.decode(response, new TypeReference>>(){}); - for(Map eachPlayerBullets : m) { - for (Map.Entry entry : eachPlayerBullets.entrySet()) { - visibleBullets.put(entry.getKey(), 1); - ArrayList properties = new ArrayList<>(); + if (!response.equals("{}")) { + ArrayList> m = json.decode(response, new TypeReference>>() {}); + for (Map eachPlayerBullets : m) { + for (Map.Entry entry : eachPlayerBullets.entrySet()) { + visibleBullets.put(entry.getKey(), 1); + ArrayList properties = new ArrayList<>(); - // 自分自身は無視する - if (entry.getKey().equals(playerId)) { - playerVisibleBullets.put(entry.getKey(), 1); - continue; - } + Bullet b = 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)angle.get("x")).doubleValue(), ((BigDecimal)angle.get("y")).doubleValue(), ((BigDecimal)angle.get("z")).doubleValue(), ((BigDecimal)angle.get("w")).doubleValue()); - -// properties.add(player.getPosition()); -// properties.add(player.getAngle()); - - if (!universe.doHaveObj(entry.getKey())) { - Appearance ap1 = new Appearance(); - Material mat = new Material(); - mat.setDiffuseColor(0.0f, 0.3f, 1.0f); - mat.setAmbientColor(0.0f, 0.0f, 0.0f); - mat.setEmissiveColor(0.0f, 0.0f, 0.0f); - mat.setSpecularColor(0.0f, 0.0f, 0.0f); - mat.setShininess(5.0f); - ap1.setMaterial(mat); - - Object3D pochaBody = null; - try { - pochaBody = ModelFactory.loadModel(resources, "pocha.stl", ap1).createObject(); - pochaBody.scale(5.0); - } catch (Exception e) { - e.printStackTrace(); + // 自分自身は無視する + if (b.getPlayerID().equals(playerId)) { + playerVisibleBullets.put(entry.getKey(), 1); + continue; } - OtherPlayerBullet bullet = new OtherPlayerBullet(pochaBody); - universe.place(entry.getKey(), bullet); - universe.place(bullet); + + + // 情報の取得 + properties.add(b.getPosition()); + properties.add(b.getAngle()); + + if (!universe.doHaveObj(entry.getKey())) { + Appearance ap1 = new Appearance(); + Material mat = new Material(); + mat.setDiffuseColor(0.0f, 0.3f, 1.0f); + mat.setAmbientColor(0.0f, 0.0f, 0.0f); + mat.setEmissiveColor(0.0f, 0.0f, 0.0f); + mat.setSpecularColor(0.0f, 0.0f, 0.0f); + mat.setShininess(5.0f); + ap1.setMaterial(mat); + + Object3D pochaBody = null; + try { + pochaBody = ModelFactory.loadModel(resources, "pocha.stl", ap1).createObject(); + pochaBody.scale(0.5); + } catch (Exception e) { + e.printStackTrace(); + } + OtherPlayerBullet bullet = new OtherPlayerBullet(pochaBody); + universe.place(entry.getKey(), bullet); + universe.place(bullet); + } + universe.apply(entry.getKey(), properties); } - universe.apply(entry.getKey(), properties); } } // 見えなくなったキャラクターの削除 diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/DummyBullet.java b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/DummyBullet.java deleted file mode 100644 index c900e77..0000000 --- a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/DummyBullet.java +++ /dev/null @@ -1,4 +0,0 @@ -package org.ntlab.radishforandroidstudio.cactusClient.models; - -public class DummyBullet { -} diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/MyBullet.java b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/MyBullet.java index 7ce959c..fadd0f2 100644 --- a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/MyBullet.java +++ b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/MyBullet.java @@ -28,7 +28,6 @@ private String instanceId; private String playerId; private String uuid; - private DummyBullet bullet; final private int INIT_UPDATE_INTERVAL = 100; private int updateInterval = INIT_UPDATE_INTERVAL; private boolean isCreatedOnServer = false; diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/framework/gameMain/GameBaseModelManager.java b/app/src/main/java/org/ntlab/radishforandroidstudio/framework/gameMain/GameBaseModelManager.java index c9d94e9..d4f617a 100644 --- a/app/src/main/java/org/ntlab/radishforandroidstudio/framework/gameMain/GameBaseModelManager.java +++ b/app/src/main/java/org/ntlab/radishforandroidstudio/framework/gameMain/GameBaseModelManager.java @@ -3,11 +3,12 @@ import org.ntlab.radishforandroidstudio.framework.model3D.Universe; import java.util.ArrayList; +import java.util.Iterator; public abstract class GameBaseModelManager implements GameBaseModel { protected ArrayList models = new ArrayList<>(); protected ArrayList nextAddModels = new ArrayList<>(); - + protected ArrayList nextRemoveModels = new ArrayList<>(); public void setFragment(RealTime3DFragment fragment) { this.fragment = fragment; } @@ -32,6 +33,8 @@ nextAddModels.add(model); } + public void removeModel(GameBaseModel model) { nextRemoveModels.add(model); } + /** * モデルの状態を更新する * @@ -47,5 +50,19 @@ for (GameBaseModel model : nextAddModels) { models.add(model); } + nextAddModels.clear(); + + // モデルの消去 + Iterator it = nextRemoveModels.iterator(); + while(it.hasNext()) { + GameBaseModel model = it.next(); + for(GameBaseModel removeModel : nextRemoveModels) { + if (model.equals(removeModel)) { + it.remove(); + break; + } + } + } + nextRemoveModels.clear(); } }