| |
---|
| | import org.ntlab.radishforandroidstudio.framework.model3D.Model3D; |
---|
| | import org.ntlab.radishforandroidstudio.framework.model3D.Position3D; |
---|
| | import org.ntlab.radishforandroidstudio.framework.model3D.Quaternion3D; |
---|
| | import org.ntlab.radishforandroidstudio.framework.physics.AngularVelocity3D; |
---|
| | import org.ntlab.radishforandroidstudio.framework.physics.PhysicsUtility; |
---|
| | import org.ntlab.radishforandroidstudio.framework.physics.Velocity3D; |
---|
| | |
---|
| | import cactusServer.entities.*; |
---|
| | import cactusServer.entities.Character; |
---|
| | import cactusServer.entities.EmoteState.EmoteType; |
---|
| | import cactusServer.entities.Object.*; |
---|
| | import cactusServer.models.Accounts; |
---|
| | import cactusServer.models.CharacterModelManager; |
---|
| | import cactusServer.models.CollisionManager; |
---|
| | import cactusServer.models.Instances; |
---|
| | import cactusServer.models.ObjectModelManager; |
---|
| | import cactusServer.models.StageModelManager; |
---|
| | import cactusServer.resources.InstancesRest; |
---|
| |
---|
| | |
---|
| | @SuppressWarnings("unused") |
---|
| | @ApplicationPath("/rest") |
---|
| | public class App extends ResourceConfig implements Runnable { |
---|
| | private ScheduledThreadPoolExecutor task = new ScheduledThreadPoolExecutor(4); |
---|
| | private int instancesSize; |
---|
| | private ScheduledThreadPoolExecutor task = new ScheduledThreadPoolExecutor(1000); |
---|
| | |
---|
| | public App() { |
---|
| | ObjectModelManager.getInstance(); |
---|
| | StageModelManager.getInstance(); |
---|
| |
---|
| | } |
---|
| | |
---|
| | @Override |
---|
| | public void run() { |
---|
| | // System.out.println("タスクを実行"); |
---|
| | // instancesSize = Instances.getInstance().getInstances().size(); |
---|
| | // for(int i=0;i<instancesSize;i++) { |
---|
| | // Instance instance = Instances.getInstance().getInstances().get(i); |
---|
| | // int objectsSize = instance.getObjects().size(); |
---|
| | // int playersSize=instance.getCharacters().size(); |
---|
| | // for(int j=0;j<objectsSize;j++) { |
---|
| | // for(int x=0;x<playersSize;x++) { |
---|
| | // //PhysicsUtility.checkCollision(instance.) |
---|
| | // } |
---|
| | // } |
---|
| | // } |
---|
| | // System.out.println("タスクを実行"); |
---|
| | CollisionManager.getCollision().collisionRun(); |
---|
| | removeInactivePlayers(); |
---|
| | } |
---|
| | |
---|
| | public void start(int interval) { |
---|
| | task.scheduleWithFixedDelay(this, interval, interval, TimeUnit.MILLISECONDS); |
---|
| | task.scheduleAtFixedRate(this, interval, interval, TimeUnit.MILLISECONDS); |
---|
| | } |
---|
| | |
---|
| | private void initDummy() { |
---|
| | // ダミーアカウント2つ |
---|
| |
---|
| | Player player2 = new Player("test2", "chara2", cameraState, EmoteType.DUMMY); |
---|
| | Instances.getInstance().getPlayers().put("player2", player2); |
---|
| | // ダミーオブジェクト |
---|
| | Instances.getInstance().getInstance("test1").createObject(new Position3D(0, 0, 0), new Velocity3D(), |
---|
| | new AngularVelocity3D(), new Quaternion3D(), new Attribute(true,1), 0); |
---|
| | // // 確認用 |
---|
| | // String player1Encode = JSON.encode(player1, true); |
---|
| | // String player2Encode = JSON.encode(player2, true); |
---|
| | // Player player1Decode = JSON.decode(player1Encode, Player.class); |
---|
| | // Player player2Decode = JSON.decode(player2Encode, Player.class); |
---|
| | // System.out.println(JSON.encode(player1Decode, true)); |
---|
| | // System.out.println(JSON.encode(player2Decode, true)); |
---|
| | |
---|
| | // JSON json = new JSON(); |
---|
| | // String characterId = player1.getCharacterID(); |
---|
| | // String encodeCharacterId = json.encode(characterId); |
---|
| | // System.out.println(characterId); |
---|
| | // System.out.println(encodeCharacterId); |
---|
| | // String position = json.encode(player1.getPosition()); |
---|
| | // System.out.println(position); |
---|
| | new AngularVelocity3D(), new Quaternion3D(), new Attribute(true, 1), 0); |
---|
| | // // 確認用 |
---|
| | // String player1Encode = JSON.encode(player1, true); |
---|
| | // String player2Encode = JSON.encode(player2, true); |
---|
| | // Player player1Decode = JSON.decode(player1Encode, Player.class); |
---|
| | // Player player2Decode = JSON.decode(player2Encode, Player.class); |
---|
| | // System.out.println(JSON.encode(player1Decode, true)); |
---|
| | // System.out.println(JSON.encode(player2Decode, true)); |
---|
| | |
---|
| | // JSON json = new JSON(); |
---|
| | // String characterId = player1.getCharacterID(); |
---|
| | // String encodeCharacterId = json.encode(characterId); |
---|
| | // System.out.println(characterId); |
---|
| | // System.out.println(encodeCharacterId); |
---|
| | // String position = json.encode(player1.getPosition()); |
---|
| | // System.out.println(position); |
---|
| | } |
---|
| | |
---|
| | |
---|
| | private void removeInactivePlayers() { |
---|
| | long currentTime = System.nanoTime(); |
---|
| | Iterator<Map.Entry<String, Player>> it = Instances.getInstance().getPlayers().entrySet().iterator(); |
---|
| | while (it.hasNext()) { |
---|
| | Map.Entry<String, Player> entry = it.next(); |
---|
| | String playerId = entry.getKey(); |
---|
| | Player player = entry.getValue(); |
---|
| | long lastUpdateTime = player.getLastUpdateTime(); |
---|
| | System.out.println(currentTime + ", " + (lastUpdateTime + Player.STOP_TIME_LIMIT) + " // playerId: " + playerId); |
---|
| | System.out.println( |
---|
| | currentTime + ", " + (lastUpdateTime + Player.STOP_TIME_LIMIT) + " // playerId: " + playerId); |
---|
| | if (currentTime > (lastUpdateTime + Player.STOP_TIME_LIMIT)) { |
---|
| | System.out.println("delete started (playerId: " + playerId + ")"); |
---|
| | player.destroy(); |
---|
| | Instance instance = Instances.getInstance().getInstance(player.getInstanceID()); |
---|
| |
---|
| | |
確認お願いします
マージします.
fc97cf7
intomaster
fromobj
on 9 Oct 2018