public async Task <GenericResponse> Associate(ActorId informChunkActorId, ActorId blockPerChunkActorId, ActorId playersPerChunkActorId, int fidelity, Position position, int blockStride) { var associations = await this.StateManager.GetStateAsync <Dictionary <ActorId, AssociateChunkMetaData> >("associations"); var metaData = new AssociateChunkMetaData(informChunkActorId, blockPerChunkActorId, playersPerChunkActorId, fidelity, position, blockStride); associations.Add(informChunkActorId, metaData); await this.StateManager.SetStateAsync <Dictionary <ActorId, AssociateChunkMetaData> >("associations", associations); return(new GenericResponse()); }
public async Task <InformOfChunkChangeResponse> InformOfChange(ActorId[] observer, AssociateChunkMetaData associate, TrackingChunkMetaData tracking) { var maxVersion = MinecraftVersion.GetNext(); //Get the data associated with request var blockPerChunkActor = ActorProxy.Create <BlocksPerChunkActor>(associate.blocksPerChunkActorId, this.ServiceUri); var playerPerChunkActor = ActorProxy.Create <PlayersPerChunkActor>(associate.playersPerChunkActorId, this.ServiceUri); var taskPlayerData = playerPerChunkActor.GetAsync(); var taskBlockData = blockPerChunkActor.GetAsync(); await Task.WhenAll(taskPlayerData, taskBlockData); var blockData = taskBlockData.Result; var playerData = taskPlayerData.Result; //gather new changes from the last delta of changes with the max requested being filled out GatherChangesAndUpdateObservers(observer, tracking.blockVersion, maxVersion, tracking.maxBlocks, tracking.playerVersion, maxVersion, tracking.maxPlayers, out int nBlocksLeft, out int nPlayersLeft, out MinecraftVersion lastBlockUsedVersion, out MinecraftVersion lastPlayerUsedVersion, blockData, playerData); //information needed to calculate the ask for next request var response = new InformOfChunkChangeResponse() { actorID = this.Id, availableBlocks = nBlocksLeft, availablePlayers = nPlayersLeft, lastPlayersVersion = lastPlayerUsedVersion, lastBlockVersion = lastBlockUsedVersion }; //bring all new observers up to the same place as everyone else, but this might not be everything if (associate.needInitObservers.Count > 0) { GatherChangesAndUpdateObservers(associate.needInitObservers.ToArray(), MinecraftVersion.minValue, response.lastBlockVersion, int.MaxValue, MinecraftVersion.minValue, response.lastPlayersVersion, int.MaxValue, out nBlocksLeft, out nPlayersLeft, out lastBlockUsedVersion, out lastPlayerUsedVersion, blockData, playerData); } return(response); }