diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/Cactus.java b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/Cactus.java index 7625a51..8e7ce84 100644 --- a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/Cactus.java +++ b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/Cactus.java @@ -6,7 +6,7 @@ import android.os.Bundle; import org.ntlab.radishforandroidstudio.cactusClient.models.account.Account; -import org.ntlab.radishforandroidstudio.cactusClient.models.URIAddressedAccount; +import org.ntlab.radishforandroidstudio.cactusClient.models.account.URIAddressedAccount; public class Cactus extends Application { diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/controller/BulletsModel.java b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/controller/BulletsModel.java new file mode 100644 index 0000000..a547a3f --- /dev/null +++ b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/controller/BulletsModel.java @@ -0,0 +1,146 @@ +package org.ntlab.radishforandroidstudio.cactusClient.controller; + +import android.content.res.Resources; + +import net.arnx.jsonic.JSON; +import net.arnx.jsonic.TypeReference; + +import org.ntlab.radishforandroidstudio.cactusClient.connections.BulletGetConnection; +import org.ntlab.radishforandroidstudio.cactusClient.models.bullet.Bullet; +import org.ntlab.radishforandroidstudio.cactusClient.models.bullet.OtherPlayerBullet; +import org.ntlab.radishforandroidstudio.framework.gameMain.OnlineModel; +import org.ntlab.radishforandroidstudio.framework.model3D.ModelFactory; +import org.ntlab.radishforandroidstudio.framework.model3D.Object3D; +import org.ntlab.radishforandroidstudio.framework.model3D.Property3D; +import org.ntlab.radishforandroidstudio.framework.model3D.Universe; +import org.ntlab.radishforandroidstudio.java3d.Appearance; +import org.ntlab.radishforandroidstudio.java3d.Material; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +public class BulletsModel implements OnlineModel { + private Universe universe; + private Resources resources; + private BulletGetConnection con; + private int nextConnectRenaimdTime = 0; + static final private int CONNECT_INTERVAL = 100; + private Map visibleBullets = new HashMap<>(); + private Map playerVisibleBullets = new HashMap<>(); + private String instanceId; + private String playerId; + + private Set bulletsSet; + + public enum BulletType { + Normal + } + + public BulletsModel(Resources fragment, Universe universe) { + this.universe = universe; + this.resources = fragment; + } + + @Override + public void setInstanceId(String id) { + this.instanceId = id; + } + + public void setPlayerId(String id) { + playerId = id; + } + + /** + * 玉の状態を更新する + * + * @param interval 前回の更新からの時間差 + * @author s.iwatani + */ + @Override + public void update(double interval) { + nextConnectRenaimdTime -= interval; + if (nextConnectRenaimdTime <= 0 && instanceId != null) { + nextConnectRenaimdTime = CONNECT_INTERVAL; + con = new BulletGetConnection(instanceId); + con.setCallBack(this); + con.doGet(); + } + } + + @Override + public void onResponse(String response) { + Map lastVisibleBullets = new HashMap<>(visibleBullets); + Map lastPlayerVisibleBullets = new HashMap<>(playerVisibleBullets); + visibleBullets.clear(); + JSON json = new JSON(); + 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<>(); + Bullet b = entry.getValue(); + // 自分自身は無視する + if (b.getPlayerID().equals(playerId)) { + playerVisibleBullets.put(entry.getKey(), 1); + continue; + } + + // 情報の取得 + 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.apply(entry.getKey(), properties); + } + } + } + // 見えなくなったキャラクターの削除 + for (String key : lastVisibleBullets.keySet()) { + if (visibleBullets.get(key) == null) { + universe.displace(key); + } + } + + // 消えた弾の削除(プレイヤーのみ) + for (String key : lastPlayerVisibleBullets.keySet()) { + bulletsSet.add(key); + } + } + + /** + * 消えた弾のうち,セットしたプレイヤーに該当する弾を取得する + * + * @return ArrayList + */ + public ArrayList getDeletedPlayerBullets() { + ArrayList bullets = new ArrayList<>(); + + for (String key : bulletsSet) { + bullets.add(key); + } + bulletsSet.clear(); + return bullets; + } +} diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/controller/CactusRepository.java b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/controller/CactusRepository.java new file mode 100644 index 0000000..e353bb2 --- /dev/null +++ b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/controller/CactusRepository.java @@ -0,0 +1,40 @@ +package org.ntlab.radishforandroidstudio.cactusClient.controller; + +import org.ntlab.radishforandroidstudio.framework.gameMain.GameBaseModel; +import org.ntlab.radishforandroidstudio.framework.gameMain.GameModelContainer; +import org.ntlab.radishforandroidstudio.framework.gameMain.OnlineModel; + +/** + * モデルを管理する + *

+ * singleton + * + * @author s.iwatani + */ +public class CactusRepository extends GameModelContainer implements OnlineModel { + private String instanceId = ""; + + public CactusRepository() { + super(); + } + + public void setInstanceId(String id) { + for (GameBaseModel model : models) { + model.setInstanceId(id); + } + for (GameBaseModel model : nextAddModels) { + model.setInstanceId(id); + } + instanceId = id; + } + + @Override + public void update(double interval) { + super.update(interval); + } + + @Override + public void onResponse(String response) { + + } +} diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/controller/MovableObjectModel.java b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/controller/MovableObjectModel.java new file mode 100644 index 0000000..708b300 --- /dev/null +++ b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/controller/MovableObjectModel.java @@ -0,0 +1,116 @@ +package org.ntlab.radishforandroidstudio.cactusClient.controller; + +import net.arnx.jsonic.JSON; +import net.arnx.jsonic.TypeReference; + +import org.ntlab.radishforandroidstudio.cactusClient.connections.ObjectsConnection; +import org.ntlab.radishforandroidstudio.cactusClient.models.object.MovableObject; +import org.ntlab.radishforandroidstudio.cactusClient.models.object.Object; +import org.ntlab.radishforandroidstudio.framework.gameMain.OnlineModel; +import org.ntlab.radishforandroidstudio.framework.gameMain.RealTime3DFragment; +import org.ntlab.radishforandroidstudio.framework.model3D.ModelFactory; +import org.ntlab.radishforandroidstudio.framework.model3D.Object3D; +import org.ntlab.radishforandroidstudio.framework.model3D.Property3D; +import org.ntlab.radishforandroidstudio.framework.model3D.Universe; +import org.ntlab.radishforandroidstudio.java3d.Appearance; +import org.ntlab.radishforandroidstudio.java3d.Material; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +/** + * オブジェクトを管理するモデル + */ + +public class MovableObjectModel implements OnlineModel { + private Universe universe; + private RealTime3DFragment fragment; + private ObjectsConnection con; + private int nextConnectRenaimdTime = 0; + private int connectInterval = 300; + private String instanceId; + private Map visibleobject = new HashMap<>(); + + public MovableObjectModel(RealTime3DFragment fragment, Universe universe, String instanceId) { + this.fragment = fragment; + this.universe = universe; + this.setInstanceId(instanceId); + } + + + @Override + public void setInstanceId(String instanceId) { + this.instanceId = instanceId; + } + + + /** + * オブジェクトの状態更新 + * + * @param interval 前回の更新からの時間差 + */ + @Override + public void update(double interval) { + nextConnectRenaimdTime -= interval; + if (nextConnectRenaimdTime <= 0) { + nextConnectRenaimdTime = connectInterval; + con = new ObjectsConnection(instanceId); + con.setCallBack(this); + con.doGet(); + } + } + + + @Override + public void onResponse(String response) { + + JSON json = new JSON(); + + + Map o = json.decode(response, new TypeReference>() { + }); + for (Map.Entry entry : o.entrySet()) { + ArrayList properties = new ArrayList<>(); + Object object = entry.getValue(); + + + properties.add(object.getPosition()); + properties.add(object.getAngle()); + + if (!visibleobject.containsKey(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 objBody = null; + try { + objBody = ModelFactory.loadModel(fragment.getResources(), "cube-binary.stl", ap1).createObject(); + objBody.scale(0.1); + } catch (Exception e) { + e.printStackTrace(); + } + + MovableObject object1 = new MovableObject(objBody); + visibleobject.put(entry.getKey(), object1); + universe.place(entry.getKey(), object1); + universe.place(object1); + + } + universe.apply(entry.getKey(), properties); + } + + for (String key : visibleobject.keySet()) { + if (!o.containsKey(key)) { + universe.displace(visibleobject.get(key)); + } + } + + + } +} diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/controller/MyBullet.java b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/controller/MyBullet.java new file mode 100644 index 0000000..de87645 --- /dev/null +++ b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/controller/MyBullet.java @@ -0,0 +1,161 @@ +package org.ntlab.radishforandroidstudio.cactusClient.controller; + +import net.arnx.jsonic.JSON; + +import org.ntlab.radishforandroidstudio.cactusClient.connections.BulletCreateConnection; +import org.ntlab.radishforandroidstudio.cactusClient.connections.BulletUpdateConnection; +import org.ntlab.radishforandroidstudio.framework.animation.Animation3D; +import org.ntlab.radishforandroidstudio.framework.gameMain.Actor; +import org.ntlab.radishforandroidstudio.framework.gameMain.OnlineModel; +import org.ntlab.radishforandroidstudio.framework.model3D.CollisionResult; +import org.ntlab.radishforandroidstudio.framework.model3D.Object3D; +import org.ntlab.radishforandroidstudio.framework.model3D.Placeable; +import org.ntlab.radishforandroidstudio.framework.model3D.Position3D; +import org.ntlab.radishforandroidstudio.framework.model3D.Quaternion3D; +import org.ntlab.radishforandroidstudio.framework.physics.Force3D; +import org.ntlab.radishforandroidstudio.framework.physics.Solid3D; +import org.ntlab.radishforandroidstudio.framework.physics.Velocity3D; +import org.ntlab.radishforandroidstudio.java3d.Vector3d; + +import java.util.ArrayList; +import java.util.UUID; + +public class MyBullet extends Actor implements OnlineModel { + private String instanceId; + private String playerId; + private String uuid; + final private int INIT_UPDATE_INTERVAL = 100; + private int updateInterval = INIT_UPDATE_INTERVAL; + private boolean isCreatedOnServer = false; + private boolean isWaitCreatingOnServer = false; + private boolean isDelete = false; + + public MyBullet(Object3D body, Animation3D animation) { + super(body, animation); + initUuid(); + } + + public MyBullet(Solid3D body, Animation3D animation) { + super(body, animation); + initUuid(); + } + + public void initUuid() { + if (getUuid() == null || getUuid().equals("")) { + uuid = UUID.randomUUID().toString(); + } + } + + public String getUuid() { + return uuid; + } + + public boolean isDelete() { + return isDelete; + } + + @Override + public void onEndFall() { + + } + + @Override + public void onIntersect(CollisionResult normal, long interval) { + + } + + @Override + public void onEndAnimation() { + + } + + @Override + public void addCollidable(ArrayList pList) { + + } + + @Override + public void onCollisionEnter(Placeable p) { + + } + + @Override + public void onCollisionStay(Placeable p) { + + } + + @Override + public void onCollisionExit(Placeable p) { + + } + + @Override + public Force3D getGravity() { + return Force3D.ZERO; + } + + + @Override + final public void update(double interval) { + progress(interval); + // サーバに弾を作成 + if (!isCreatedOnServer && !instanceId.equals("") && !playerId.equals("") && !isWaitCreatingOnServer) { + JSON json = new JSON(); + Quaternion3D q = ((Solid3D) (getBody())).getQuaternion(); + BulletCreateConnection con = new BulletCreateConnection(instanceId, playerId); + con.setCallBack(this); + + con.addFormParam("bulletID", getUuid()); + con.addFormParam("position", json.encode(getPosition())); + con.addFormParam("angle", "{ \"x\":" + q.getX() + ", \"y\":" + q.getY() + ", \"z\":" + q.getZ() + ", \"w\":" + q.getW() + "}"); + + con.doPost(); + + isWaitCreatingOnServer = true; + System.out.println("create shot uuid:" + getUuid()); + + } else if (isCreatedOnServer && !isWaitCreatingOnServer) { + // サーバの弾の情報を更新 + updateInterval -= interval; + if (updateInterval <= 0 && isCreatedOnServer) { + JSON json = new JSON(); + Quaternion3D q = ((Solid3D) (getBody())).getQuaternion(); + updateInterval = INIT_UPDATE_INTERVAL; + BulletUpdateConnection con = new BulletUpdateConnection(instanceId, playerId, getUuid()); + con.setCallBack(this); + + con.addFormParam("position", json.encode(getPosition())); + con.addFormParam("angle", "{ \"x\":" + q.getX() + ", \"y\":" + q.getY() + ", \"z\":" + q.getZ() + ", \"w\":" + q.getW() + "}"); + + con.doPut(); + } + } + } + + public void progress(double interval) { + + } + + public void init(Position3D pos, Quaternion3D angle) { + setPosition(pos); + Vector3d v = new Vector3d(-1.0f, 0, 0); + v = v.rotate(angle); + setVelocity(new Velocity3D(v)); + } + + + @Override + public void setInstanceId(String id) { + instanceId = id; + } + + public void setPlayerid(String id) { + playerId = id; + } + + @Override + public void onResponse(String response) { + isWaitCreatingOnServer = false; + isCreatedOnServer = true; + } +} diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/controller/NormalBullet.java b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/controller/NormalBullet.java new file mode 100644 index 0000000..57f0904 --- /dev/null +++ b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/controller/NormalBullet.java @@ -0,0 +1,15 @@ +package org.ntlab.radishforandroidstudio.cactusClient.controller; + +import org.ntlab.radishforandroidstudio.framework.animation.Animation3D; +import org.ntlab.radishforandroidstudio.framework.model3D.Object3D; +import org.ntlab.radishforandroidstudio.framework.physics.Solid3D; + +public class NormalBullet extends MyBullet { + public NormalBullet(Object3D body, Animation3D animation) { + super(body, animation); + } + + public NormalBullet(Solid3D body, Animation3D animation) { + super(body, animation); + } +} diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/controller/OtherPlayerCharactersModel.java b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/controller/OtherPlayerCharactersModel.java new file mode 100644 index 0000000..bc2ca23 --- /dev/null +++ b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/controller/OtherPlayerCharactersModel.java @@ -0,0 +1,121 @@ +package org.ntlab.radishforandroidstudio.cactusClient.controller; + +import net.arnx.jsonic.JSON; +import net.arnx.jsonic.TypeReference; + +import org.ntlab.radishforandroidstudio.cactusClient.connections.PlayersConnection; +import org.ntlab.radishforandroidstudio.cactusClient.models.player.OtherPlayerCharacter; +import org.ntlab.radishforandroidstudio.cactusClient.models.player.Player; +import org.ntlab.radishforandroidstudio.framework.gameMain.OnlineModel; +import org.ntlab.radishforandroidstudio.framework.gameMain.RealTime3DFragment; +import org.ntlab.radishforandroidstudio.framework.model3D.ModelFactory; +import org.ntlab.radishforandroidstudio.framework.model3D.Object3D; +import org.ntlab.radishforandroidstudio.framework.model3D.Property3D; +import org.ntlab.radishforandroidstudio.framework.model3D.Universe; +import org.ntlab.radishforandroidstudio.java3d.Appearance; +import org.ntlab.radishforandroidstudio.java3d.Material; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +/** + * 自キャラ以外の全操作キャラを管理するモデル + * + * @author s.iwatani + */ +public class OtherPlayerCharactersModel implements OnlineModel { + private Universe universe; + private RealTime3DFragment fragment; + private PlayersConnection con; + private int nextConnectRenaimdTime = 0; + static final private int CONNECT_INTERVAL = 300; + private Map visibleCharacters = new HashMap<>(); + private String instanceId; + private String playerId; + + public OtherPlayerCharactersModel(RealTime3DFragment fragment, Universe universe) { + this.fragment = fragment; + this.universe = universe; + } + + public void setInstanceId(String id) { + this.instanceId = id; + } + + public void setPlayerId(String id) { + playerId = id; + } + + /** + * キャラクターの状態を更新する + * + * @param interval 前回の更新からの時間差 + * @author s.iwatani + */ + @Override + public void update(double interval) { + nextConnectRenaimdTime -= interval; + if (nextConnectRenaimdTime <= 0) { + nextConnectRenaimdTime = CONNECT_INTERVAL; + con = new PlayersConnection(); + con.addQueryParam("instanceId", instanceId); + con.setCallBack(this); + con.doGet(); + } + } + + @Override + public void onResponse(String response) { + Map lastVisibleCharacters = new HashMap<>(visibleCharacters); + visibleCharacters.clear(); + JSON json = new JSON(); + Map m = json.decode(response, new TypeReference>() { + }); + for (Map.Entry entry : m.entrySet()) { + visibleCharacters.put(entry.getKey(), 1); + ArrayList properties = new ArrayList<>(); + Player player = entry.getValue(); + + // 自分自身は無視する + if (entry.getKey().equals(playerId)) continue; + + // 情報の取得 +// 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(fragment.getResources(), "pocha.stl", ap1).createObject(); + } catch (Exception e) { + e.printStackTrace(); + } + OtherPlayerCharacter chara = new OtherPlayerCharacter(pochaBody); + universe.place(entry.getKey(), chara); + } + universe.apply(entry.getKey(), properties); + } + + // 見えなくなったキャラクターの削除 + for (String key : lastVisibleCharacters.keySet()) { + if (visibleCharacters.get(key) == null) { + universe.displace(key); + } + } + } +} diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/controller/OwnBulletsModel.java b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/controller/OwnBulletsModel.java new file mode 100644 index 0000000..b33888a --- /dev/null +++ b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/controller/OwnBulletsModel.java @@ -0,0 +1,105 @@ +package org.ntlab.radishforandroidstudio.cactusClient.controller; + +import android.content.res.Resources; + +import org.ntlab.radishforandroidstudio.framework.event.BulletShotEvent; +import org.ntlab.radishforandroidstudio.framework.gameMain.OnlineModel; +import org.ntlab.radishforandroidstudio.framework.listener.BulletShotListener; +import org.ntlab.radishforandroidstudio.framework.model3D.Position3D; +import org.ntlab.radishforandroidstudio.framework.model3D.Quaternion3D; +import org.ntlab.radishforandroidstudio.framework.model3D.Universe; + +import java.util.ArrayList; +import java.util.Iterator; + +public class OwnBulletsModel implements OnlineModel, BulletShotListener { + private ArrayList bullets = new ArrayList<>(); + private String playerId; + private String instanceId; + private Resources resources; + private Universe universe; + private Position3D playerPos; + private Quaternion3D playerAngle; + + public OwnBulletsModel(Resources resources, Universe universe, String instanceId, String playerId) { + this.resources = resources; + this.universe = universe; + + setInstanceId(instanceId); + setPlayerId(playerId); + } + + public void setPosition(Position3D pos) { + playerPos = pos; + } + + public void setAngle(Quaternion3D angle) { + playerAngle = angle; + } + + public void sendDeleteBulletForServer(MyBullet myBullet) { + // TODO: 弾消し情報を送信 + } + + @Override + public void update(double interval) { + for (Iterator bulletIterator = bullets.iterator(); bulletIterator.hasNext();) { + MyBullet bullet = bulletIterator.next(); + bullet.update(interval); + // 弾削除 + if (bullet.isDelete()) { + sendDeleteBulletForServer(bullet); + bulletIterator.remove(); + } + } + } + + public void deleteBullets(ArrayList deletedBullets) { + for (Iterator bulletIterator = bullets.iterator(); bulletIterator.hasNext();) { + MyBullet bullet = bulletIterator.next(); + + for(String deleteBullet : deletedBullets) { // 弾削除 + if (bullet.getUuid().equals(bullets)) { + universe.displace(bullet); + sendDeleteBulletForServer(bullet); + bulletIterator.remove(); + break; + } + } + } + } + + @Override + public void setInstanceId(String id) { + instanceId = id; + } + + public void setPlayerId(String id) { + playerId = id; + } + + /** + * 弾作成のイベント受け + * + * @param event イベントの情報 + * @return + */ + @Override + public boolean onEvent(BulletShotEvent event) { + if (playerPos == null || playerAngle == null || playerId == null || instanceId == null) { + return false; + } + MyBullet b = event.getBullet(); + b.setPlayerid(playerId); + b.setInstanceId(instanceId); + b.init(playerPos, playerAngle); + bullets.add(b); + universe.place(b); + return true; + } + + @Override + public void onResponse(String response) { + + } +} diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/factory/BulletFactory.java b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/factory/BulletFactory.java index 2ea983e..fe6474c 100644 --- a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/factory/BulletFactory.java +++ b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/factory/BulletFactory.java @@ -2,7 +2,7 @@ import android.content.res.Resources; -import org.ntlab.radishforandroidstudio.cactusClient.models.bullet.MyBullet; +import org.ntlab.radishforandroidstudio.cactusClient.controller.MyBullet; import org.ntlab.radishforandroidstudio.framework.model3D.ModelFactory; import org.ntlab.radishforandroidstudio.framework.model3D.Object3D; import org.ntlab.radishforandroidstudio.java3d.Appearance; diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/Angle.java b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/Angle.java deleted file mode 100644 index 2f4f0cf..0000000 --- a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/Angle.java +++ /dev/null @@ -1,52 +0,0 @@ -package org.ntlab.radishforandroidstudio.cactusClient.models; - - -public class Angle { - private double vx; - private double vy; - private double vz; - private double a; - - private Angle() { - // JSONDecode時の呼び出し用 - } - - public Angle(double vx, double vy, double vz, double a) { - setVx(vx); - setVy(vy); - setVz(vz); - setA(a); - } - - public double getVx() { - return vx; - } - - public double getVy() { - return vy; - } - - public double getVz() { - return vz; - } - - public double getA() { - return a; - } - - public void setVx(double vx) { - this.vx = vx; - } - - public void setVy(double vy) { - this.vy = vy; - } - - public void setVz(double vz) { - this.vz = vz; - } - - public void setA(double a) { - this.a = a; - } -} \ No newline at end of file diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/CactusRepository.java b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/CactusRepository.java deleted file mode 100644 index 961c027..0000000 --- a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/CactusRepository.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.ntlab.radishforandroidstudio.cactusClient.models; - -import org.ntlab.radishforandroidstudio.framework.gameMain.GameBaseModel; -import org.ntlab.radishforandroidstudio.framework.gameMain.GameModelContainer; -import org.ntlab.radishforandroidstudio.framework.gameMain.OnlineModel; - -/** - * モデルを管理する - *

- * singleton - * - * @author s.iwatani - */ -public class CactusRepository extends GameModelContainer implements OnlineModel { - private String instanceId = ""; - - public CactusRepository() { - super(); - } - - public void setInstanceId(String id) { - for (GameBaseModel model : models) { - model.setInstanceId(id); - } - for (GameBaseModel model : nextAddModels) { - model.setInstanceId(id); - } - instanceId = id; - } - - @Override - public void update(double interval) { - super.update(interval); - } - - @Override - public void onResponse(String response) { - - } -} diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/CameraState.java b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/CameraState.java deleted file mode 100644 index 04f22c3..0000000 --- a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/CameraState.java +++ /dev/null @@ -1,52 +0,0 @@ -package org.ntlab.radishforandroidstudio.cactusClient.models; - - -public class CameraState { - private double distance; // キャラからの距離 - private Angle angle; - private double tilt; // チルト(rad) - private double fov; // 視野角(rad) - - private CameraState() { - // JSONDecode時の呼び出し用 - } - - public CameraState(double distance, Angle angle, double tilt, double fov) { - setDistance(distance); - setAngle(angle); - setTilt(tilt); - setFov(fov); - } - - public double getDistance() { - return distance; - } - - public Angle getAngle() { - return angle; - } - - public double getTilt() { - return tilt; - } - - public double getFov() { - return fov; - } - - public void setDistance(double distance) { - this.distance = distance; - } - - public void setAngle(Angle angle) { - this.angle = angle; - } - - public void setTilt(double tilt) { - this.tilt = tilt; - } - - public void setFov(double fov) { - this.fov = fov; - } -} \ No newline at end of file diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/CharacterModelManager.java b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/CharacterModelManager.java deleted file mode 100644 index a42d3d0..0000000 --- a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/CharacterModelManager.java +++ /dev/null @@ -1,80 +0,0 @@ -package org.ntlab.radishforandroidstudio.cactusClient.models; - - -import org.ntlab.radishforandroidstudio.framework.model3D.Model3D; - -import java.io.UnsupportedEncodingException; -import java.net.URLDecoder; -import java.util.HashMap; -import java.util.Map; - -public class CharacterModelManager { - private static CharacterModelManager theInstance = null; - private HashMap characterModels = new HashMap<>(); - private int nextKey = 0; - private static final String MODEL_PATH = "../../"; - - private CharacterModelManager() { - initCharacterModels(); - } - - private void initCharacterModels() { - String[] initCharacterModelFileNames = {"pocha.stl", "Head4.obj"}; - for (String fileName : initCharacterModelFileNames) { - addCharacterModel(fileName); - } - } - - public static CharacterModelManager getInstance() { - if (theInstance == null) { - theInstance = new CharacterModelManager(); - } - return theInstance; - } - - public Model3D getCharacterModel(int id) { - return characterModels.get(id); - } - - public int getCharacterModelCount() { - return characterModels.size(); - } - - public int addCharacterModel(String fileName) { - String path = createModelFilePath(MODEL_PATH + fileName); - characterModels.put(nextKey, loadModel(path)); - return nextKey++; - } - - private String createModelFilePath(String fileName) { - String path = getClass().getResource(fileName).getPath(); - try { - path = URLDecoder.decode(path, "utf-8"); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } - return path; - } - - private Model3D loadModel(String fileName) { - /***************************************************************************************************** - try { - return ModelFactory.loadModel(fileName, null, false, true); - } catch (IOException | ModelFileFormatException e) { - e.printStackTrace(); - } - *****************************************************************************************************/ - return null; - } - - /** - * 現在のCharacterModelMapの中身の確認用 - */ - private void confirmModelMap() { - // 確認用 - System.out.println(getCharacterModelCount() + "個のマッピングが存在するよ!"); - for (Map.Entry entry : characterModels.entrySet()) { - System.out.println(entry.getKey() + ": " + entry.getValue()); - } - } -} \ No newline at end of file diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/Entity.java b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/Entity.java deleted file mode 100644 index bf9cf2e..0000000 --- a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/Entity.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.ntlab.radishforandroidstudio.cactusClient.models; - -/** - * AddressedEntityクラスにて扱う実体を表す抽象クラス - * - * @author r-isitani - */ -public abstract class Entity { - -} \ No newline at end of file diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/Entity3D.java b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/Entity3D.java deleted file mode 100644 index c99bfe0..0000000 --- a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/Entity3D.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.ntlab.radishforandroidstudio.cactusClient.models; - - -import net.arnx.jsonic.JSONHint; - -import org.ntlab.radishforandroidstudio.framework.model3D.Placeable; - -public abstract class Entity3D extends Entity { - private Placeable placeable; - - protected Entity3D() { - // JSONDecode時の呼び出し用 - } - - public Entity3D(Placeable placeable) { - setPlaceable(placeable); - } - - @JSONHint(ignore = true) - public Placeable getPlaceable() { - return placeable; - } - - @JSONHint(ignore = true) - public void setPlaceable(Placeable placeable) { - this.placeable = placeable; - } -} \ No newline at end of file diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/Item.java b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/Item.java deleted file mode 100644 index ab0f447..0000000 --- a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/Item.java +++ /dev/null @@ -1,66 +0,0 @@ -package org.ntlab.radishforandroidstudio.cactusClient.models; - -import net.arnx.jsonic.JSONHint; - -public class Item extends Entity { - private String name; - private int amount; - - @JSONHint(ignore = true) - public static final int UNIQUE_ID_LENGTH = 12; - - private Item() { - // JSONDecode時の呼び出し用 - } - - public Item(String name, int amount) { - setName(name); - setAmount(amount); - } - - public String getName() { - return name; - } - - public int getAmount() { - return amount; - } - - public boolean isEmpty() { - return (amount == 0); - } - - public void setName(String name) { - this.name = name; - } - - public void setAmount(int amount) { - this.amount = amount; - } - - public Item changeAmount(int amountOfChange) { - amount = Math.max(amount + amountOfChange, 0); - return this; - } - - @Override - public int hashCode() { - int result = 17; - result = result * 31 + name.hashCode(); - return result; - } - - @Override - public boolean equals(java.lang.Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof Item) { - Item item = (Item) obj; - if (this.name.equals(item.name)) { - return true; // 同名のアイテムは等価 - } - } - return false; - } -} \ No newline at end of file diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/RandomStringGenerator.java b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/RandomStringGenerator.java deleted file mode 100644 index 3f48a41..0000000 --- a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/RandomStringGenerator.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.ntlab.radishforandroidstudio.cactusClient.models; - -import org.apache.commons.lang3.RandomStringUtils; - -import java.util.Set; - -public class RandomStringGenerator { - public static final String ALPHA_NUMERIC = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; - - private RandomStringGenerator() { - - } - - static public String generateRandomString(int num, String seed) { - return RandomStringUtils.random(num, seed); - } - - static public boolean checkString(String str, Set set) { - return set.contains(str); - } - - static public String generateUniqueString(int num, String seed, Set set) { - String str; - do { - str = generateRandomString(num, seed); - } while (checkString(str, set)); - return str; - } -} \ No newline at end of file diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/URIAddressedAccount.java b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/URIAddressedAccount.java deleted file mode 100644 index a538583..0000000 --- a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/URIAddressedAccount.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.ntlab.radishforandroidstudio.cactusClient.models; - -import org.ntlab.radishforandroidstudio.cactusClient.models.account.Account; - -import java.net.URI; - -public class URIAddressedAccount { - private URI uri; - private Account account; - - private URIAddressedAccount() { - // JSONDecode時の呼び出し用 - } - - public URIAddressedAccount(URI uri, Account body) { - setAccount(body); - setUri(uri); - } - - public URIAddressedAccount(String str, Account body) { - setAccount(body); - setUri(URI.create(str)); - } - - public URI getUri() { - return uri; - } - - public void setUri(URI uri) { - this.uri = uri; - } - - public Account getAccount() { - return account; - } - - public void setAccount(Account account) { - this.account = account; - } - -} \ No newline at end of file diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/UpdateUsecase.java b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/UpdateUsecase.java index 177af6f..7faffd5 100644 --- a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/UpdateUsecase.java +++ b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/UpdateUsecase.java @@ -1,5 +1,7 @@ package org.ntlab.radishforandroidstudio.cactusClient.models; +import org.ntlab.radishforandroidstudio.cactusClient.controller.CactusRepository; + public class UpdateUsecase implements UpdateBoundary { CactusRepository cactusRepository; diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/account/Account.java b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/account/Account.java index 5544aef..3e72896 100644 --- a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/account/Account.java +++ b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/account/Account.java @@ -2,8 +2,6 @@ import net.arnx.jsonic.JSONHint; -import org.ntlab.radishforandroidstudio.cactusClient.models.RandomStringGenerator; - public class Account { private String id, name, token, pass, uniqueID; private boolean login = false; diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/account/RandomStringGenerator.java b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/account/RandomStringGenerator.java new file mode 100644 index 0000000..5b9f61c --- /dev/null +++ b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/account/RandomStringGenerator.java @@ -0,0 +1,29 @@ +package org.ntlab.radishforandroidstudio.cactusClient.models.account; + +import org.apache.commons.lang3.RandomStringUtils; + +import java.util.Set; + +public class RandomStringGenerator { + public static final String ALPHA_NUMERIC = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; + + private RandomStringGenerator() { + + } + + static public String generateRandomString(int num, String seed) { + return RandomStringUtils.random(num, seed); + } + + static public boolean checkString(String str, Set set) { + return set.contains(str); + } + + static public String generateUniqueString(int num, String seed, Set set) { + String str; + do { + str = generateRandomString(num, seed); + } while (checkString(str, set)); + return str; + } +} \ No newline at end of file diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/account/URIAddressedAccount.java b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/account/URIAddressedAccount.java new file mode 100644 index 0000000..ab07572 --- /dev/null +++ b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/account/URIAddressedAccount.java @@ -0,0 +1,39 @@ +package org.ntlab.radishforandroidstudio.cactusClient.models.account; + +import java.net.URI; + +public class URIAddressedAccount { + private URI uri; + private Account account; + + private URIAddressedAccount() { + // JSONDecode時の呼び出し用 + } + + public URIAddressedAccount(URI uri, Account body) { + setAccount(body); + setUri(uri); + } + + public URIAddressedAccount(String str, Account body) { + setAccount(body); + setUri(URI.create(str)); + } + + public URI getUri() { + return uri; + } + + public void setUri(URI uri) { + this.uri = uri; + } + + public Account getAccount() { + return account; + } + + public void setAccount(Account account) { + this.account = account; + } + +} \ No newline at end of file diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/bullet/Bullet.java b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/bullet/Bullet.java index b826825..582235e 100644 --- a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/bullet/Bullet.java +++ b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/bullet/Bullet.java @@ -2,7 +2,7 @@ import net.arnx.jsonic.JSONHint; -import org.ntlab.radishforandroidstudio.cactusClient.models.Entity; +import org.ntlab.radishforandroidstudio.cactusClient.models.state.Entity; import org.ntlab.radishforandroidstudio.framework.model3D.Position3D; import org.ntlab.radishforandroidstudio.framework.model3D.Quaternion3D; @@ -17,8 +17,6 @@ } 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); @@ -47,16 +45,10 @@ 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) diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/bullet/BulletsModel.java b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/bullet/BulletsModel.java deleted file mode 100644 index b56a344..0000000 --- a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/bullet/BulletsModel.java +++ /dev/null @@ -1,148 +0,0 @@ -package org.ntlab.radishforandroidstudio.cactusClient.models.bullet; - -import android.content.res.Resources; - -import net.arnx.jsonic.JSON; -import net.arnx.jsonic.TypeReference; - -import org.ntlab.radishforandroidstudio.cactusClient.connections.BulletGetConnection; -import org.ntlab.radishforandroidstudio.framework.gameMain.OnlineModel; -import org.ntlab.radishforandroidstudio.framework.model3D.ModelFactory; -import org.ntlab.radishforandroidstudio.framework.model3D.Object3D; -import org.ntlab.radishforandroidstudio.framework.model3D.Property3D; -import org.ntlab.radishforandroidstudio.framework.model3D.Universe; -import org.ntlab.radishforandroidstudio.java3d.Appearance; -import org.ntlab.radishforandroidstudio.java3d.Material; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; - -public class BulletsModel implements OnlineModel { - private Universe universe; - private Resources resources; - private BulletGetConnection con; - private int nextConnectRenaimdTime = 0; - static final private int CONNECT_INTERVAL = 100; - private Map visibleBullets = new HashMap<>(); - private Map playerVisibleBullets = new HashMap<>(); - private String instanceId; - private String playerId; - - private Set bulletsSet; - - public enum BulletType { - Normal - } - - public BulletsModel(Resources fragment, Universe universe) { - this.universe = universe; - this.resources = fragment; - } - - @Override - public void setInstanceId(String id) { - this.instanceId = id; - } - - public void setPlayerId(String id) { - playerId = id; - } - - /** - * 玉の状態を更新する - * - * @param interval 前回の更新からの時間差 - * @author s.iwatani - */ - @Override - public void update(double interval) { - nextConnectRenaimdTime -= interval; - if (nextConnectRenaimdTime <= 0 && instanceId != null) { - nextConnectRenaimdTime = CONNECT_INTERVAL; - con = new BulletGetConnection(instanceId); - con.setCallBack(this); - con.doGet(); - } - } - - @Override - public void onResponse(String response) { - Map lastVisibleBullets = new HashMap<>(visibleBullets); - Map lastPlayerVisibleBullets = new HashMap<>(playerVisibleBullets); - visibleBullets.clear(); - JSON json = new JSON(); - 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<>(); - - Bullet b = entry.getValue(); - - // 自分自身は無視する - if (b.getPlayerID().equals(playerId)) { - playerVisibleBullets.put(entry.getKey(), 1); - continue; - } - - - // 情報の取得 - 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.apply(entry.getKey(), properties); - } - } - } - // 見えなくなったキャラクターの削除 - for (String key : lastVisibleBullets.keySet()) { - if (visibleBullets.get(key) == null) { - universe.displace(key); - } - } - - // 消えた弾の削除(プレイヤーのみ) - for (String key : lastPlayerVisibleBullets.keySet()) { - bulletsSet.add(key); - } - } - - /** - * 消えた弾のうち,セットしたプレイヤーに該当する弾を取得する - * - * @return ArrayList - */ - public ArrayList getDeletedPlayerBullets() { - ArrayList bullets = new ArrayList<>(); - - for (String key : bulletsSet) { - bullets.add(key); - } - bulletsSet.clear(); - return bullets; - } -} diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/bullet/MyBullet.java b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/bullet/MyBullet.java deleted file mode 100644 index 4517749..0000000 --- a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/bullet/MyBullet.java +++ /dev/null @@ -1,161 +0,0 @@ -package org.ntlab.radishforandroidstudio.cactusClient.models.bullet; - -import net.arnx.jsonic.JSON; - -import org.ntlab.radishforandroidstudio.cactusClient.connections.BulletCreateConnection; -import org.ntlab.radishforandroidstudio.cactusClient.connections.BulletUpdateConnection; -import org.ntlab.radishforandroidstudio.framework.animation.Animation3D; -import org.ntlab.radishforandroidstudio.framework.gameMain.Actor; -import org.ntlab.radishforandroidstudio.framework.gameMain.OnlineModel; -import org.ntlab.radishforandroidstudio.framework.model3D.CollisionResult; -import org.ntlab.radishforandroidstudio.framework.model3D.Object3D; -import org.ntlab.radishforandroidstudio.framework.model3D.Placeable; -import org.ntlab.radishforandroidstudio.framework.model3D.Position3D; -import org.ntlab.radishforandroidstudio.framework.model3D.Quaternion3D; -import org.ntlab.radishforandroidstudio.framework.physics.Force3D; -import org.ntlab.radishforandroidstudio.framework.physics.Solid3D; -import org.ntlab.radishforandroidstudio.framework.physics.Velocity3D; -import org.ntlab.radishforandroidstudio.java3d.Vector3d; - -import java.util.ArrayList; -import java.util.UUID; - -public class MyBullet extends Actor implements OnlineModel { - private String instanceId; - private String playerId; - private String uuid; - final private int INIT_UPDATE_INTERVAL = 100; - private int updateInterval = INIT_UPDATE_INTERVAL; - private boolean isCreatedOnServer = false; - private boolean isWaitCreatingOnServer = false; - private boolean isDelete = false; - - public MyBullet(Object3D body, Animation3D animation) { - super(body, animation); - initUuid(); - } - - public MyBullet(Solid3D body, Animation3D animation) { - super(body, animation); - initUuid(); - } - - public void initUuid() { - if (getUuid() == null || getUuid().equals("")) { - uuid = UUID.randomUUID().toString(); - } - } - - public String getUuid() { - return uuid; - } - - public boolean isDelete() { - return isDelete; - } - - @Override - public void onEndFall() { - - } - - @Override - public void onIntersect(CollisionResult normal, long interval) { - - } - - @Override - public void onEndAnimation() { - - } - - @Override - public void addCollidable(ArrayList pList) { - - } - - @Override - public void onCollisionEnter(Placeable p) { - - } - - @Override - public void onCollisionStay(Placeable p) { - - } - - @Override - public void onCollisionExit(Placeable p) { - - } - - @Override - public Force3D getGravity() { - return Force3D.ZERO; - } - - - @Override - final public void update(double interval) { - progress(interval); - // サーバに弾を作成 - if (!isCreatedOnServer && !instanceId.equals("") && !playerId.equals("") && !isWaitCreatingOnServer) { - JSON json = new JSON(); - Quaternion3D q = ((Solid3D) (getBody())).getQuaternion(); - BulletCreateConnection con = new BulletCreateConnection(instanceId, playerId); - con.setCallBack(this); - - con.addFormParam("bulletID", getUuid()); - con.addFormParam("position", json.encode(getPosition())); - con.addFormParam("angle", "{ \"x\":" + q.getX() + ", \"y\":" + q.getY() + ", \"z\":" + q.getZ() + ", \"w\":" + q.getW() + "}"); - - con.doPost(); - - isWaitCreatingOnServer = true; - System.out.println("create shot uuid:" + getUuid()); - - } else if (isCreatedOnServer && !isWaitCreatingOnServer) { - // サーバの弾の情報を更新 - updateInterval -= interval; - if (updateInterval <= 0 && isCreatedOnServer) { - JSON json = new JSON(); - Quaternion3D q = ((Solid3D) (getBody())).getQuaternion(); - updateInterval = INIT_UPDATE_INTERVAL; - BulletUpdateConnection con = new BulletUpdateConnection(instanceId, playerId, getUuid()); - con.setCallBack(this); - - con.addFormParam("position", json.encode(getPosition())); - con.addFormParam("angle", "{ \"x\":" + q.getX() + ", \"y\":" + q.getY() + ", \"z\":" + q.getZ() + ", \"w\":" + q.getW() + "}"); - - con.doPut(); - } - } - } - - public void progress(double interval) { - - } - - public void init(Position3D pos, Quaternion3D angle) { - setPosition(pos); - Vector3d v = new Vector3d(-1.0f, 0, 0); - v = v.rotate(angle); - setVelocity(new Velocity3D(v)); - } - - - @Override - public void setInstanceId(String id) { - instanceId = id; - } - - public void setPlayerid(String id) { - playerId = id; - } - - @Override - public void onResponse(String response) { - isWaitCreatingOnServer = false; - isCreatedOnServer = true; - } -} diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/bullet/NormalBullet.java b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/bullet/NormalBullet.java deleted file mode 100644 index cccef77..0000000 --- a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/bullet/NormalBullet.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.ntlab.radishforandroidstudio.cactusClient.models.bullet; - -import org.ntlab.radishforandroidstudio.framework.animation.Animation3D; -import org.ntlab.radishforandroidstudio.framework.model3D.Object3D; -import org.ntlab.radishforandroidstudio.framework.physics.Solid3D; - -public class NormalBullet extends MyBullet { - public NormalBullet(Object3D body, Animation3D animation) { - super(body, animation); - } - - public NormalBullet(Solid3D body, Animation3D animation) { - super(body, animation); - } -} diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/bullet/OwnBulletsModel.java b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/bullet/OwnBulletsModel.java deleted file mode 100644 index 7a23ec0..0000000 --- a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/bullet/OwnBulletsModel.java +++ /dev/null @@ -1,105 +0,0 @@ -package org.ntlab.radishforandroidstudio.cactusClient.models.bullet; - -import android.content.res.Resources; - -import org.ntlab.radishforandroidstudio.framework.event.BulletShotEvent; -import org.ntlab.radishforandroidstudio.framework.gameMain.OnlineModel; -import org.ntlab.radishforandroidstudio.framework.listener.BulletShotListener; -import org.ntlab.radishforandroidstudio.framework.model3D.Position3D; -import org.ntlab.radishforandroidstudio.framework.model3D.Quaternion3D; -import org.ntlab.radishforandroidstudio.framework.model3D.Universe; - -import java.util.ArrayList; -import java.util.Iterator; - -public class OwnBulletsModel implements OnlineModel, BulletShotListener { - private ArrayList bullets = new ArrayList<>(); - private String playerId; - private String instanceId; - private Resources resources; - private Universe universe; - private Position3D playerPos; - private Quaternion3D playerAngle; - - public OwnBulletsModel(Resources resources, Universe universe, String instanceId, String playerId) { - this.resources = resources; - this.universe = universe; - - setInstanceId(instanceId); - setPlayerId(playerId); - } - - public void setPosition(Position3D pos) { - playerPos = pos; - } - - public void setAngle(Quaternion3D angle) { - playerAngle = angle; - } - - public void sendDeleteBulletForServer(MyBullet myBullet) { - // TODO: 弾消し情報を送信 - } - - @Override - public void update(double interval) { - for (Iterator bulletIterator = bullets.iterator(); bulletIterator.hasNext();) { - MyBullet bullet = bulletIterator.next(); - bullet.update(interval); - // 弾削除 - if (bullet.isDelete()) { - sendDeleteBulletForServer(bullet); - bulletIterator.remove(); - } - } - } - - public void deleteBullets(ArrayList deletedBullets) { - for (Iterator bulletIterator = bullets.iterator(); bulletIterator.hasNext();) { - MyBullet bullet = bulletIterator.next(); - - for(String deleteBullet : deletedBullets) { // 弾削除 - if (bullet.getUuid().equals(bullets)) { - universe.displace(bullet); - sendDeleteBulletForServer(bullet); - bulletIterator.remove(); - break; - } - } - } - } - - @Override - public void setInstanceId(String id) { - instanceId = id; - } - - public void setPlayerId(String id) { - playerId = id; - } - - /** - * 弾作成のイベント受け - * - * @param event イベントの情報 - * @return - */ - @Override - public boolean onEvent(BulletShotEvent event) { - if (playerPos == null || playerAngle == null || playerId == null || instanceId == null) { - return false; - } - MyBullet b = event.getBullet(); - b.setPlayerid(playerId); - b.setInstanceId(instanceId); - b.init(playerPos, playerAngle); - bullets.add(b); - universe.place(b); - return true; - } - - @Override - public void onResponse(String response) { - - } -} diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/instance/Area.java b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/instance/Area.java index 193f911..af1dc56 100644 --- a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/instance/Area.java +++ b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/instance/Area.java @@ -3,7 +3,7 @@ import net.arnx.jsonic.JSONHint; -import org.ntlab.radishforandroidstudio.cactusClient.models.Entity; +import org.ntlab.radishforandroidstudio.cactusClient.models.state.Entity; import org.ntlab.radishforandroidstudio.framework.model3D.Position3D; import java.util.HashSet; diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/instance/Instance.java b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/instance/Instance.java index c1f73ff..a81592c 100644 --- a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/instance/Instance.java +++ b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/instance/Instance.java @@ -4,9 +4,9 @@ import org.ntlab.radishforandroidstudio.cactusClient.models.instance.Area.Allowed; import org.ntlab.radishforandroidstudio.cactusClient.models.player.Character; -import org.ntlab.radishforandroidstudio.cactusClient.models.Entity; +import org.ntlab.radishforandroidstudio.cactusClient.models.state.Entity; import org.ntlab.radishforandroidstudio.cactusClient.models.object.MovableObject; -import org.ntlab.radishforandroidstudio.cactusClient.models.RandomStringGenerator; +import org.ntlab.radishforandroidstudio.cactusClient.models.account.RandomStringGenerator; import org.ntlab.radishforandroidstudio.framework.model3D.Object3D; import org.ntlab.radishforandroidstudio.framework.model3D.Position3D; import org.ntlab.radishforandroidstudio.framework.model3D.Quaternion3D; diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/instance/Instances.java b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/instance/Instances.java index d8c9f42..a8fdc90 100644 --- a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/instance/Instances.java +++ b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/instance/Instances.java @@ -1,10 +1,10 @@ package org.ntlab.radishforandroidstudio.cactusClient.models.instance; -import org.ntlab.radishforandroidstudio.cactusClient.models.CameraState; -import org.ntlab.radishforandroidstudio.cactusClient.models.player.EmoteState; +import org.ntlab.radishforandroidstudio.cactusClient.models.state.CameraState; +import org.ntlab.radishforandroidstudio.cactusClient.models.state.EmoteState; import org.ntlab.radishforandroidstudio.cactusClient.models.player.Player; -import org.ntlab.radishforandroidstudio.cactusClient.models.RandomStringGenerator; +import org.ntlab.radishforandroidstudio.cactusClient.models.account.RandomStringGenerator; import org.ntlab.radishforandroidstudio.framework.model3D.Position3D; import org.ntlab.radishforandroidstudio.framework.model3D.Quaternion3D; @@ -39,8 +39,7 @@ } public HashMap createInstance(String name, int stageID) { - String id = RandomStringGenerator.generateUniqueString(Instance.UNIQUE_ID_LENGTH, - RandomStringGenerator.ALPHA_NUMERIC, instanceMap.keySet()); + String id = RandomStringGenerator.generateUniqueString(Instance.UNIQUE_ID_LENGTH, RandomStringGenerator.ALPHA_NUMERIC, instanceMap.keySet()); Instance instance = new Instance(name, stageID); instanceMap.put(id, instance); HashMap returnedMap = new HashMap<>(); @@ -50,8 +49,7 @@ public HashMap createPlayer(String instanceURI, String characterURI, CameraState cameraState, EmoteState.EmoteType animationClassToStart) { - String id = RandomStringGenerator.generateUniqueString(Player.UNIQUE_ID_LENGTH, - RandomStringGenerator.ALPHA_NUMERIC, playerMap.keySet()); + String id = RandomStringGenerator.generateUniqueString(Player.UNIQUE_ID_LENGTH, RandomStringGenerator.ALPHA_NUMERIC, playerMap.keySet()); Player player = new Player(instanceURI, characterURI, cameraState, animationClassToStart); playerMap.put(id, player); HashMap returnedMap = new HashMap<>(); diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/object/MovableObjectModel.java b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/object/MovableObjectModel.java deleted file mode 100644 index de26fa6..0000000 --- a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/object/MovableObjectModel.java +++ /dev/null @@ -1,114 +0,0 @@ -package org.ntlab.radishforandroidstudio.cactusClient.models.object; - -import net.arnx.jsonic.JSON; -import net.arnx.jsonic.TypeReference; - -import org.ntlab.radishforandroidstudio.cactusClient.connections.ObjectsConnection; -import org.ntlab.radishforandroidstudio.framework.gameMain.OnlineModel; -import org.ntlab.radishforandroidstudio.framework.gameMain.RealTime3DFragment; -import org.ntlab.radishforandroidstudio.framework.model3D.ModelFactory; -import org.ntlab.radishforandroidstudio.framework.model3D.Object3D; -import org.ntlab.radishforandroidstudio.framework.model3D.Property3D; -import org.ntlab.radishforandroidstudio.framework.model3D.Universe; -import org.ntlab.radishforandroidstudio.java3d.Appearance; -import org.ntlab.radishforandroidstudio.java3d.Material; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; - -/** - * オブジェクトを管理するモデル - */ - -public class MovableObjectModel implements OnlineModel { - private Universe universe; - private RealTime3DFragment fragment; - private ObjectsConnection con; - private int nextConnectRenaimdTime = 0; - private int connectInterval = 300; - private String instanceId; - private Map visibleobject = new HashMap<>(); - - public MovableObjectModel(RealTime3DFragment fragment, Universe universe, String instanceId) { - this.fragment = fragment; - this.universe = universe; - this.setInstanceId(instanceId); - } - - - @Override - public void setInstanceId(String instanceId) { - this.instanceId = instanceId; - } - - - /** - * オブジェクトの状態更新 - * - * @param interval 前回の更新からの時間差 - */ - @Override - public void update(double interval) { - nextConnectRenaimdTime -= interval; - if (nextConnectRenaimdTime <= 0) { - nextConnectRenaimdTime = connectInterval; - con = new ObjectsConnection(instanceId); - con.setCallBack(this); - con.doGet(); - } - } - - - @Override - public void onResponse(String response) { - - JSON json = new JSON(); - - - Map o = json.decode(response, new TypeReference>() { - }); - for (Map.Entry entry : o.entrySet()) { - ArrayList properties = new ArrayList<>(); - Object object = entry.getValue(); - - - properties.add(object.getPosition()); - properties.add(object.getAngle()); - - if (!visibleobject.containsKey(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 objBody = null; - try { - objBody = ModelFactory.loadModel(fragment.getResources(), "cube-binary.stl", ap1).createObject(); - objBody.scale(0.1); - } catch (Exception e) { - e.printStackTrace(); - } - - MovableObject object1 = new MovableObject(objBody); - visibleobject.put(entry.getKey(), object1); - universe.place(entry.getKey(), object1); - universe.place(object1); - - } - universe.apply(entry.getKey(), properties); - } - - for (String key : visibleobject.keySet()) { - if (!o.containsKey(key)) { - universe.displace(visibleobject.get(key)); - } - } - - - } -} diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/object/Object.java b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/object/Object.java index e111491..82b604b 100644 --- a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/object/Object.java +++ b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/object/Object.java @@ -2,7 +2,7 @@ import net.arnx.jsonic.JSONHint; -import org.ntlab.radishforandroidstudio.cactusClient.models.Entity3D; +import org.ntlab.radishforandroidstudio.cactusClient.models.state.Entity3D; import org.ntlab.radishforandroidstudio.framework.model3D.Model3D; import org.ntlab.radishforandroidstudio.framework.model3D.Object3D; import org.ntlab.radishforandroidstudio.framework.model3D.Position3D; diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/player/Character.java b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/player/Character.java index 1e00909..86d5b7c 100644 --- a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/player/Character.java +++ b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/player/Character.java @@ -3,9 +3,9 @@ import net.arnx.jsonic.JSONHint; -import org.ntlab.radishforandroidstudio.cactusClient.models.Entity; -import org.ntlab.radishforandroidstudio.cactusClient.models.Item; -import org.ntlab.radishforandroidstudio.cactusClient.models.RandomStringGenerator; +import org.ntlab.radishforandroidstudio.cactusClient.models.state.Entity; +import org.ntlab.radishforandroidstudio.cactusClient.models.state.Item; +import org.ntlab.radishforandroidstudio.cactusClient.models.account.RandomStringGenerator; import org.ntlab.radishforandroidstudio.cactusClient.models.instance.Area; import org.ntlab.radishforandroidstudio.cactusClient.models.instance.Instance; import org.ntlab.radishforandroidstudio.cactusClient.models.instance.Instances; diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/player/CharacterModelManager.java b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/player/CharacterModelManager.java new file mode 100644 index 0000000..005da3f --- /dev/null +++ b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/player/CharacterModelManager.java @@ -0,0 +1,80 @@ +package org.ntlab.radishforandroidstudio.cactusClient.models.player; + + +import org.ntlab.radishforandroidstudio.framework.model3D.Model3D; + +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.util.HashMap; +import java.util.Map; + +public class CharacterModelManager { + private static CharacterModelManager theInstance = null; + private HashMap characterModels = new HashMap<>(); + private int nextKey = 0; + private static final String MODEL_PATH = "../../"; + + private CharacterModelManager() { + initCharacterModels(); + } + + private void initCharacterModels() { + String[] initCharacterModelFileNames = {"pocha.stl", "Head4.obj"}; + for (String fileName : initCharacterModelFileNames) { + addCharacterModel(fileName); + } + } + + public static CharacterModelManager getInstance() { + if (theInstance == null) { + theInstance = new CharacterModelManager(); + } + return theInstance; + } + + public Model3D getCharacterModel(int id) { + return characterModels.get(id); + } + + public int getCharacterModelCount() { + return characterModels.size(); + } + + public int addCharacterModel(String fileName) { + String path = createModelFilePath(MODEL_PATH + fileName); + characterModels.put(nextKey, loadModel(path)); + return nextKey++; + } + + private String createModelFilePath(String fileName) { + String path = getClass().getResource(fileName).getPath(); + try { + path = URLDecoder.decode(path, "utf-8"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + return path; + } + + private Model3D loadModel(String fileName) { + /***************************************************************************************************** + try { + return ModelFactory.loadModel(fileName, null, false, true); + } catch (IOException | ModelFileFormatException e) { + e.printStackTrace(); + } + *****************************************************************************************************/ + return null; + } + + /** + * 現在のCharacterModelMapの中身の確認用 + */ + private void confirmModelMap() { + // 確認用 + System.out.println(getCharacterModelCount() + "個のマッピングが存在するよ!"); + for (Map.Entry entry : characterModels.entrySet()) { + System.out.println(entry.getKey() + ": " + entry.getValue()); + } + } +} \ No newline at end of file diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/player/EmoteState.java b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/player/EmoteState.java deleted file mode 100644 index 44d94d8..0000000 --- a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/player/EmoteState.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.ntlab.radishforandroidstudio.cactusClient.models.player; - - -/** - * エモートの情報を表すクラス
- * 内部にエモートの種類を表す列挙型も定義 - * - * @author r-isitani - */ -public class EmoteState { - private EmoteType emoteType; - - private EmoteState() { - // JSONDecode時の呼び出し用 - } - - public EmoteState(EmoteType emoteType) { - setEmoteType(emoteType); - } - - public EmoteType getEmoteType() { - return emoteType; - } - - public void setEmoteType(EmoteType emoteType) { - this.emoteType = emoteType; - } - - public static enum EmoteType { - // 開始するエモートの種類の列挙 - DUMMY; - } -} \ No newline at end of file diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/player/OtherPlayerCharactersModel.java b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/player/OtherPlayerCharactersModel.java deleted file mode 100644 index 51378d3..0000000 --- a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/player/OtherPlayerCharactersModel.java +++ /dev/null @@ -1,119 +0,0 @@ -package org.ntlab.radishforandroidstudio.cactusClient.models.player; - -import net.arnx.jsonic.JSON; -import net.arnx.jsonic.TypeReference; - -import org.ntlab.radishforandroidstudio.cactusClient.connections.PlayersConnection; -import org.ntlab.radishforandroidstudio.framework.gameMain.OnlineModel; -import org.ntlab.radishforandroidstudio.framework.gameMain.RealTime3DFragment; -import org.ntlab.radishforandroidstudio.framework.model3D.ModelFactory; -import org.ntlab.radishforandroidstudio.framework.model3D.Object3D; -import org.ntlab.radishforandroidstudio.framework.model3D.Property3D; -import org.ntlab.radishforandroidstudio.framework.model3D.Universe; -import org.ntlab.radishforandroidstudio.java3d.Appearance; -import org.ntlab.radishforandroidstudio.java3d.Material; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; - -/** - * 自キャラ以外の全操作キャラを管理するモデル - * - * @author s.iwatani - */ -public class OtherPlayerCharactersModel implements OnlineModel { - private Universe universe; - private RealTime3DFragment fragment; - private PlayersConnection con; - private int nextConnectRenaimdTime = 0; - static final private int CONNECT_INTERVAL = 300; - private Map visibleCharacters = new HashMap<>(); - private String instanceId; - private String playerId; - - public OtherPlayerCharactersModel(RealTime3DFragment fragment, Universe universe) { - this.fragment = fragment; - this.universe = universe; - } - - public void setInstanceId(String id) { - this.instanceId = id; - } - - public void setPlayerId(String id) { - playerId = id; - } - - /** - * キャラクターの状態を更新する - * - * @param interval 前回の更新からの時間差 - * @author s.iwatani - */ - @Override - public void update(double interval) { - nextConnectRenaimdTime -= interval; - if (nextConnectRenaimdTime <= 0) { - nextConnectRenaimdTime = CONNECT_INTERVAL; - con = new PlayersConnection(); - con.addQueryParam("instanceId", instanceId); - con.setCallBack(this); - con.doGet(); - } - } - - @Override - public void onResponse(String response) { - Map lastVisibleCharacters = new HashMap<>(visibleCharacters); - visibleCharacters.clear(); - JSON json = new JSON(); - Map m = json.decode(response, new TypeReference>() { - }); - for (Map.Entry entry : m.entrySet()) { - visibleCharacters.put(entry.getKey(), 1); - ArrayList properties = new ArrayList<>(); - Player player = entry.getValue(); - - // 自分自身は無視する - if (entry.getKey().equals(playerId)) continue; - - // 情報の取得 -// 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(fragment.getResources(), "pocha.stl", ap1).createObject(); - } catch (Exception e) { - e.printStackTrace(); - } - OtherPlayerCharacter chara = new OtherPlayerCharacter(pochaBody); - universe.place(entry.getKey(), chara); - } - universe.apply(entry.getKey(), properties); - } - - // 見えなくなったキャラクターの削除 - for (String key : lastVisibleCharacters.keySet()) { - if (visibleCharacters.get(key) == null) { - universe.displace(key); - } - } - } -} diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/player/OwnPlayerModel.java b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/player/OwnPlayerModel.java index 666352d..1dacefe 100644 --- a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/player/OwnPlayerModel.java +++ b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/player/OwnPlayerModel.java @@ -7,8 +7,7 @@ import net.arnx.jsonic.JSON; import org.ntlab.radishforandroidstudio.cactusClient.connections.CharacterConnection; -import org.ntlab.radishforandroidstudio.cactusClient.models.bullet.OwnBulletsModel; -import org.ntlab.radishforandroidstudio.cactusClient.models.player.Player; +import org.ntlab.radishforandroidstudio.cactusClient.controller.OwnBulletsModel; import org.ntlab.radishforandroidstudio.framework.animation.Animation3D; import org.ntlab.radishforandroidstudio.framework.event.PadEvent; import org.ntlab.radishforandroidstudio.framework.gameMain.OnlineModel; diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/player/Player.java b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/player/Player.java index b18c332..ac74d0f 100644 --- a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/player/Player.java +++ b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/player/Player.java @@ -4,9 +4,9 @@ import net.arnx.jsonic.JSONHint; import org.ntlab.radishforandroidstudio.cactusClient.models.instance.Area; -import org.ntlab.radishforandroidstudio.cactusClient.models.CameraState; -import org.ntlab.radishforandroidstudio.cactusClient.models.CharacterModelManager; -import org.ntlab.radishforandroidstudio.cactusClient.models.Entity3D; +import org.ntlab.radishforandroidstudio.cactusClient.models.state.CameraState; +import org.ntlab.radishforandroidstudio.cactusClient.models.state.EmoteState; +import org.ntlab.radishforandroidstudio.cactusClient.models.state.Entity3D; import org.ntlab.radishforandroidstudio.cactusClient.models.instance.Instance; import org.ntlab.radishforandroidstudio.cactusClient.models.instance.Instances; import org.ntlab.radishforandroidstudio.framework.gameMain.OvergroundActor; @@ -31,8 +31,7 @@ // JSONDecode時の呼び出し用 } - public Player(String instanceID, String characterID, CameraState cameraState, - EmoteState.EmoteType animationClassToStart) { + public Player(String instanceID, String characterID, CameraState cameraState, EmoteState.EmoteType animationClassToStart) { setInstanceID(instanceID); setCharacterID(characterID); setCameraState(cameraState); diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/state/Angle.java b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/state/Angle.java new file mode 100644 index 0000000..4189e8f --- /dev/null +++ b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/state/Angle.java @@ -0,0 +1,52 @@ +package org.ntlab.radishforandroidstudio.cactusClient.models.state; + + +public class Angle { + private double vx; + private double vy; + private double vz; + private double a; + + private Angle() { + // JSONDecode時の呼び出し用 + } + + public Angle(double vx, double vy, double vz, double a) { + setVx(vx); + setVy(vy); + setVz(vz); + setA(a); + } + + public double getVx() { + return vx; + } + + public double getVy() { + return vy; + } + + public double getVz() { + return vz; + } + + public double getA() { + return a; + } + + public void setVx(double vx) { + this.vx = vx; + } + + public void setVy(double vy) { + this.vy = vy; + } + + public void setVz(double vz) { + this.vz = vz; + } + + public void setA(double a) { + this.a = a; + } +} \ No newline at end of file diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/state/CameraState.java b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/state/CameraState.java new file mode 100644 index 0000000..c4a5fe7 --- /dev/null +++ b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/state/CameraState.java @@ -0,0 +1,52 @@ +package org.ntlab.radishforandroidstudio.cactusClient.models.state; + + +public class CameraState { + private double distance; // キャラからの距離 + private Angle angle; + private double tilt; // チルト(rad) + private double fov; // 視野角(rad) + + private CameraState() { + // JSONDecode時の呼び出し用 + } + + public CameraState(double distance, Angle angle, double tilt, double fov) { + setDistance(distance); + setAngle(angle); + setTilt(tilt); + setFov(fov); + } + + public double getDistance() { + return distance; + } + + public Angle getAngle() { + return angle; + } + + public double getTilt() { + return tilt; + } + + public double getFov() { + return fov; + } + + public void setDistance(double distance) { + this.distance = distance; + } + + public void setAngle(Angle angle) { + this.angle = angle; + } + + public void setTilt(double tilt) { + this.tilt = tilt; + } + + public void setFov(double fov) { + this.fov = fov; + } +} \ No newline at end of file diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/state/EmoteState.java b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/state/EmoteState.java new file mode 100644 index 0000000..ed6bfae --- /dev/null +++ b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/state/EmoteState.java @@ -0,0 +1,33 @@ +package org.ntlab.radishforandroidstudio.cactusClient.models.state; + + +/** + * エモートの情報を表すクラス
+ * 内部にエモートの種類を表す列挙型も定義 + * + * @author r-isitani + */ +public class EmoteState { + private EmoteType emoteType; + + private EmoteState() { + // JSONDecode時の呼び出し用 + } + + public EmoteState(EmoteType emoteType) { + setEmoteType(emoteType); + } + + public EmoteType getEmoteType() { + return emoteType; + } + + public void setEmoteType(EmoteType emoteType) { + this.emoteType = emoteType; + } + + public static enum EmoteType { + // 開始するエモートの種類の列挙 + DUMMY; + } +} \ No newline at end of file diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/state/Entity.java b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/state/Entity.java new file mode 100644 index 0000000..4530188 --- /dev/null +++ b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/state/Entity.java @@ -0,0 +1,10 @@ +package org.ntlab.radishforandroidstudio.cactusClient.models.state; + +/** + * AddressedEntityクラスにて扱う実体を表す抽象クラス + * + * @author r-isitani + */ +public abstract class Entity { + +} \ No newline at end of file diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/state/Entity3D.java b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/state/Entity3D.java new file mode 100644 index 0000000..b2d4740 --- /dev/null +++ b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/state/Entity3D.java @@ -0,0 +1,28 @@ +package org.ntlab.radishforandroidstudio.cactusClient.models.state; + + +import net.arnx.jsonic.JSONHint; + +import org.ntlab.radishforandroidstudio.framework.model3D.Placeable; + +public abstract class Entity3D extends Entity { + private Placeable placeable; + + protected Entity3D() { + // JSONDecode時の呼び出し用 + } + + public Entity3D(Placeable placeable) { + setPlaceable(placeable); + } + + @JSONHint(ignore = true) + public Placeable getPlaceable() { + return placeable; + } + + @JSONHint(ignore = true) + public void setPlaceable(Placeable placeable) { + this.placeable = placeable; + } +} \ No newline at end of file diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/state/Item.java b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/state/Item.java new file mode 100644 index 0000000..e7156e0 --- /dev/null +++ b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/state/Item.java @@ -0,0 +1,66 @@ +package org.ntlab.radishforandroidstudio.cactusClient.models.state; + +import net.arnx.jsonic.JSONHint; + +public class Item extends Entity { + private String name; + private int amount; + + @JSONHint(ignore = true) + public static final int UNIQUE_ID_LENGTH = 12; + + private Item() { + // JSONDecode時の呼び出し用 + } + + public Item(String name, int amount) { + setName(name); + setAmount(amount); + } + + public String getName() { + return name; + } + + public int getAmount() { + return amount; + } + + public boolean isEmpty() { + return (amount == 0); + } + + public void setName(String name) { + this.name = name; + } + + public void setAmount(int amount) { + this.amount = amount; + } + + public Item changeAmount(int amountOfChange) { + amount = Math.max(amount + amountOfChange, 0); + return this; + } + + @Override + public int hashCode() { + int result = 17; + result = result * 31 + name.hashCode(); + return result; + } + + @Override + public boolean equals(java.lang.Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof Item) { + Item item = (Item) obj; + if (this.name.equals(item.name)) { + return true; // 同名のアイテムは等価 + } + } + return false; + } +} \ No newline at end of file diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/views/LoginFragment.java b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/views/LoginFragment.java index e8c66ce..83f151f 100644 --- a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/views/LoginFragment.java +++ b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/views/LoginFragment.java @@ -15,7 +15,7 @@ import org.ntlab.radishforandroidstudio.cactusClient.Cactus; import org.ntlab.radishforandroidstudio.cactusClient.connections.LoginFragmentConnection; import org.ntlab.radishforandroidstudio.cactusClient.models.account.Account; -import org.ntlab.radishforandroidstudio.cactusClient.models.URIAddressedAccount; +import org.ntlab.radishforandroidstudio.cactusClient.models.account.URIAddressedAccount; import org.ntlab.radishforandroidstudio.framework.network.CallBack; diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/views/PlayerFragment.java b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/views/PlayerFragment.java index 7f5c156..d22a03b 100644 --- a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/views/PlayerFragment.java +++ b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/views/PlayerFragment.java @@ -12,11 +12,11 @@ import android.widget.Button; import org.ntlab.radishforandroidstudio.R; -import org.ntlab.radishforandroidstudio.cactusClient.models.bullet.BulletsModel; -import org.ntlab.radishforandroidstudio.cactusClient.models.CactusRepository; -import org.ntlab.radishforandroidstudio.cactusClient.models.object.MovableObjectModel; -import org.ntlab.radishforandroidstudio.cactusClient.models.player.OtherPlayerCharactersModel; -import org.ntlab.radishforandroidstudio.cactusClient.models.bullet.OwnBulletsModel; +import org.ntlab.radishforandroidstudio.cactusClient.controller.BulletsModel; +import org.ntlab.radishforandroidstudio.cactusClient.controller.CactusRepository; +import org.ntlab.radishforandroidstudio.cactusClient.controller.MovableObjectModel; +import org.ntlab.radishforandroidstudio.cactusClient.controller.OtherPlayerCharactersModel; +import org.ntlab.radishforandroidstudio.cactusClient.controller.OwnBulletsModel; import org.ntlab.radishforandroidstudio.cactusClient.models.player.OwnPlayerModel; import org.ntlab.radishforandroidstudio.cactusClient.models.player.Player; import org.ntlab.radishforandroidstudio.framework.RWT.RWTPad; diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/views/SignUpFragment.java b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/views/SignUpFragment.java index 6c8ffb2..a709692 100644 --- a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/views/SignUpFragment.java +++ b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/views/SignUpFragment.java @@ -13,7 +13,7 @@ import org.ntlab.radishforandroidstudio.R; import org.ntlab.radishforandroidstudio.cactusClient.connections.SignUpFragmentConnection; -import org.ntlab.radishforandroidstudio.cactusClient.models.URIAddressedAccount; +import org.ntlab.radishforandroidstudio.cactusClient.models.account.URIAddressedAccount; import org.ntlab.radishforandroidstudio.framework.network.CallBack; public class SignUpFragment extends BaseFragment { diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/framework/RWT/RWTShotButton.java b/app/src/main/java/org/ntlab/radishforandroidstudio/framework/RWT/RWTShotButton.java index e1ccd01..b854caf 100644 --- a/app/src/main/java/org/ntlab/radishforandroidstudio/framework/RWT/RWTShotButton.java +++ b/app/src/main/java/org/ntlab/radishforandroidstudio/framework/RWT/RWTShotButton.java @@ -8,7 +8,6 @@ import org.ntlab.radishforandroidstudio.cactusClient.factory.NormalBulletFactory; import org.ntlab.radishforandroidstudio.framework.event.BulletShotEvent; import org.ntlab.radishforandroidstudio.framework.listener.BulletShotListener; -import org.ntlab.radishforandroidstudio.framework.listener.PadListener; import org.ntlab.radishforandroidstudio.framework.subject.BulletShotSubject; public class RWTShotButton extends RWTButton { @@ -44,6 +43,7 @@ /** * 弾発射ボタン操作時に発生するイベントのリスナを追加する + * * @param listener */ public void addListener(BulletShotListener listener) { diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/framework/event/BulletShotEvent.java b/app/src/main/java/org/ntlab/radishforandroidstudio/framework/event/BulletShotEvent.java index 898802f..b4ec2ca 100644 --- a/app/src/main/java/org/ntlab/radishforandroidstudio/framework/event/BulletShotEvent.java +++ b/app/src/main/java/org/ntlab/radishforandroidstudio/framework/event/BulletShotEvent.java @@ -2,7 +2,7 @@ import android.view.MotionEvent; -import org.ntlab.radishforandroidstudio.cactusClient.models.bullet.MyBullet; +import org.ntlab.radishforandroidstudio.cactusClient.controller.MyBullet; public class BulletShotEvent extends MyEvent { private MyBullet b;