コード例 #1
0
    private void NetChunkLoadedForClient(object[] args)
    {
        // Called on server when finished loading a chunk from file, to send to a player.
        string     data   = (string)args[0];
        int        chunkX = (int)args[1];
        int        chunkY = (int)args[2];
        GameObject player = (GameObject)args[3];

        int index = GetChunkIndex(chunkX, chunkY);

        if (AnyPendingOperationsFor(index))
        {
            // Merge the loaded data with any pending operations.
            string merged = ChunkIO.Merge(data, PendingOperations[index], ChunkSize, true);

            // Compress again using RLE.
            float  eff;
            string compressed = ChunkIO.RLE(merged, out eff);

            // Apply back to the data.
            data = compressed;
        }

        // Send to client.
        Msg_SendChunk msg = new Msg_SendChunk()
        {
            Data = data, ChunkX = chunkX, ChunkY = chunkY, Layer = Name
        };

        // Send the data to the client using the server.
        NetworkServer.SendToClientOfPlayer(player, (short)MessageTypes.SEND_CHUNK_DATA, msg);
    }
コード例 #2
0
ファイル: Player.cs プロジェクト: Epicguru/NotQuiteDead
    private void ReceivedChunkData(NetworkMessage message)
    {
        // Called when receiving a chunk from the server.
        Msg_SendChunk msg = message.ReadMessage <Msg_SendChunk>();

        World.Instance.TileMap.GetLayer(msg.Layer).RecievedNetChunk(msg.Data, msg.ChunkX, msg.ChunkY);
    }
コード例 #3
0
    private void NetChunkMade(object[] args)
    {
        // Called when a player requests a chunk from the server, then the server posts an event that leads here.
        bool worked = (bool)args[0];

        if (!worked)
        {
            Debug.LogError("Net chunk creation failed, unknown error.");
            return;
        }

        string     data   = (string)args[1];
        int        chunkX = (int)args[2];
        int        chunkY = (int)args[3];
        GameObject player = (GameObject)args[4];

        Msg_SendChunk msg = new Msg_SendChunk()
        {
            Data = data, ChunkX = chunkX, ChunkY = chunkY, Layer = Name
        };

        // Send the data to the client using the server.
        NetworkServer.SendToClientOfPlayer(player, (short)MessageTypes.SEND_CHUNK_DATA, msg);
    }