Newer
Older
CactusServer / src / main / java / cactusServer / utils / App.java
package cactusServer.utils;

import java.util.Timer;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;

import org.glassfish.jersey.server.ResourceConfig;
import org.ntlab.radishforandroidstudio.framework.model3D.Position3D;
import org.ntlab.radishforandroidstudio.framework.model3D.Quaternion3D;

import cactusServer.entities.*;
import cactusServer.entities.Character;
import cactusServer.entities.EmoteState.EmoteType;
import cactusServer.models.Accounts;
import cactusServer.models.CharacterModelManager;
import cactusServer.models.Instances;
import cactusServer.models.StageModelManager;
import cactusServer.resources.InstancesRest;
import net.arnx.jsonic.JSON;

@SuppressWarnings("unused")
@ApplicationPath("/rest")
public class App extends ResourceConfig implements Runnable {
	private ScheduledThreadPoolExecutor task = new ScheduledThreadPoolExecutor(4);

	public App() {
		StageModelManager.getInstance();
		CharacterModelManager.getInstance();
		Instances.getInstance();
		Accounts.getInstance();
		initDummy();
		start(10000);
		System.out.println("pass");
	}

	@Override
	public void run() {
		System.out.println("タスクを実行");
	}

	public void start(int interval) {
		task.scheduleWithFixedDelay(this, interval, interval, TimeUnit.MILLISECONDS);
	}

	private void initDummy() {
		// ダミーアカウント1つ
		Accounts.getInstance().createAcount("test", "test", "test");
		// ダミーインスタンス2つ
		Instances.getInstance().getInstances().put("test1", new Instance("test1", 0));
		Instances.getInstance().getInstances().put("test2", new Instance("test2", 1));
		// ダミーキャラクター4つ
		String accountUri = "/CactusServer/rest/accounts/"
				+ Accounts.getInstance().getAccountByID("test").getUniqueID();
		Character chara1 = new Character("test1", accountUri, "chara1", new Position3D(), new Quaternion3D(), 0);
		Character chara2 = new Character("test2", accountUri, "chara2", new Position3D(), new Quaternion3D(), 0);
		Instances.getInstance().getInstance("test1").getCharacters().put("chara1", chara1);
		Instances.getInstance().getInstance("test1").getCharacters().put("chara2", chara2);
		Instances.getInstance().getInstance("test2").getCharacters().put("chara1", chara1);
		Instances.getInstance().getInstance("test2").getCharacters().put("chara2", chara2);
		// ダミープレイヤー2つ
		chara1.setPosition(new Position3D(34.5, 23.4, 19));
		CameraState cameraState = new CameraState(1.24, new Quaternion3D(), 2.38, 3);
		String instanceTest1URI = InstancesRest.INSTANCES_URI + "/" + "test1";
		String characterTest1URi = instanceTest1URI + "/" + "characters" + "/" + "chara1";
		Player player1 = new Player(instanceTest1URI , characterTest1URi, cameraState, EmoteType.DUMMY);
		Instances.getInstance().getPlayers().put("player1", player1);
		String instanceTest2URI = InstancesRest.INSTANCES_URI + "/" + "test2";
		String characterTest2URi = instanceTest2URI + "/" + "characters" + "/" + "chara2";
		Player player2 = new Player(instanceTest2URI , characterTest2URi, cameraState, EmoteType.DUMMY);
		Instances.getInstance().getPlayers().put("player2", player2);
	}
}