public void TryAddPlayerToScene(LitePlayer p, int sceneId) { AtlasWorld world = WorldAtlas.current.GetWorld(sceneId); //this naming convention is awful // Remove player from his current chunk WorldChunk currChunk = GetChunk(p.GetChunkId()); currChunk.connectedPlayers.Remove(p); if (world.instanced) { // {Todo} } else { List <WorldChunk> chunks = chunkRefs[sceneId]; if (chunks == null) { WorldChunk chunk = RequestChunk(sceneId); chunk.connectedPlayers.Add(p); } else { chunks[0].connectedPlayers.Add(p); } } }
public WorldChunk RequestChunk(int sceneId, System.Action <WorldChunk> callback = null) { // Try get chunk size AtlasWorld world = WorldAtlas.current.GetWorld(sceneId); //this naming convention is awful if (world != null) { int width = world.width, height = world.height; int chunk = FindChunk(width, height); int chunkX = chunk % numColumns; int chunkY = chunk / numColumns; WorldChunk chunkObj = new WorldChunk() { x = chunkX, y = chunkY, width = width, height = height, chunkSceneId = sceneId, world = world }; if (!chunkRefs.ContainsKey(sceneId)) { chunkRefs[sceneId] = new List <WorldChunk>() { chunkObj }; } else { chunkRefs[sceneId].Add(chunkObj); } for (int w = 0; w < width; w++) { for (int h = 0; h < height; h++) { allChunks[w + chunkX][h + chunkY] = chunkObj; } } // callback(chunkObj); waitingChunk = chunkObj; chunkObj.callback = callback; ServerSceneLoader.LoadScene(sceneId); return(chunkObj); } else { Debug.LogError("Scene " + sceneId + " has no attached AtlasWorld"); return(null); } }
public void GenerateDebugData() { worlds = new Dictionary <int, AtlasWorld>(); // Generate the links WorldLinkData leftToCore = new WorldLinkData() { name = "toLobbyFromLeft", isDiscontinuous = true, approxLocation = Vector3.zero, connectedLinks = new List <WorldLinkData>() }; WorldLinkData coreToLeft = new WorldLinkData() { name = "toLeft", isDiscontinuous = true, approxLocation = Vector3.zero, connectedLinks = new List <WorldLinkData>() }; WorldLinkData topToCore = new WorldLinkData() { name = "toLobbyFromTop", isDiscontinuous = true, approxLocation = Vector3.zero, connectedLinks = new List <WorldLinkData>() }; WorldLinkData coreToTop = new WorldLinkData() { name = "toTop", isDiscontinuous = true, approxLocation = Vector3.zero, connectedLinks = new List <WorldLinkData>() }; // Connect links leftToCore.connectedLinks.Add(coreToLeft); coreToLeft.connectedLinks.Add(leftToCore); topToCore.connectedLinks.Add(coreToTop); coreToTop.connectedLinks.Add(topToCore); // Generate the worlds AtlasWorld core = new AtlasWorld() { sceneId = 0, width = 1, height = 1, instanced = false, links = new List <WorldLinkData>() { coreToTop, coreToLeft } }; AtlasWorld top = new AtlasWorld() { sceneId = 2, width = 1, height = 1, instanced = true, links = new List <WorldLinkData>() { topToCore } }; AtlasWorld left = new AtlasWorld() { sceneId = 1, width = 1, height = 1, instanced = false, links = new List <WorldLinkData>() { leftToCore } }; // Add them worlds[core.sceneId] = core; worlds[top.sceneId] = top; worlds[left.sceneId] = left; }