示例#1
0
    public static void blockUpdate(BlockEvent e)
    {
        for (int i = 0; i < e.updates.Length; i++)
        {

            int x2 = e.updates[i].x / chunkSize;
            int y2 = e.updates[i].y / chunkSize;

            int x3 = e.updates[i].x % chunkSize;
            int y3 = e.updates[i].y % chunkSize;

            if (!chunks.ContainsKey(x2 + y2 * Width))
                return;

            if (e.fromServer && e.updates[i].by == OmniLocal.LocalID)
            {
                instance.toRemove.Clear();
                for (int j = 0; j < instance.toValidate.Count; j++)
                {
                    if (instance.toValidate[j].x == e.updates[i].x && instance.toValidate[j].y == e.updates[i].y)
                    {
                        instance.toRemove.Add(instance.toValidate[j]);
                        continue;
                    }
                }
                for (int k = 0; k < instance.toRemove.Count; k++)
                {
                    instance.toValidate.Remove(instance.toRemove[k]);
                }

            }

            e.updates[i].handle();

            if(!e.fromServer)
            if(e.updates[i].by == OmniLocal.LocalID)
            if (Network.isClient)
                instance.toValidate.Add(e.updates[i]);

        }
    }
示例#2
0
    public void OmniUpdate(float delta)
    {
        for (int i = 0; i < OmniTerrain.activeChunks.Count; i++)
        {
            if (OmniTerrain.activeChunks[i].rebuildMesh)
            {
                OmniTerrain.activeChunks[i].GenMesh(1);
                OmniTerrain.activeChunks[i].rebuildMesh = false;
            }
        }

        if (terrainUpdates.Count > 0)
        {

            BlockEvent e = new BlockEvent(OmniWorld.tick, terrainUpdates.ToArray());
            OmniEvents.AddEvent(e);

            if (OmniWorld.isDebugging)
                Debug.Log("tUpdates: " + terrainUpdates.Count + " : " + e.updates[0].x + "," + e.updates[0].y);

            terrainUpdates.Clear();
        }

        bool flag = false;
        for (int i = 0; i < toValidate.Count; i++)
        {
            toValidate[i].counter++;
            if (toValidate[i].counter > OmniWorld.localDelay * 2)
            {
                flag = true;
                break;
            }
        }
        if (flag)
        {
            toValidate.Clear();
            for (int i = 0; i < OmniTerrain.activeChunks.Count; i++)
            {
                RChunkEvent e = new RChunkEvent(OmniWorld.tick);
                e.x = (int)OmniTerrain.activeChunks[i].pos.x / OmniTerrain.chunkSize;
                e.y = (int)OmniTerrain.activeChunks[i].pos.y / OmniTerrain.chunkSize;
                e.player = Network.player;
                OmniEvents.AddEvent(e);
            }

        }
    }