Exemplo n.º 1
0
        static void HandleMeshMessage(PacketBuffer packet, NetworkReader reader, Dictionary <ulong, Resource> resources)
        {
            uint meshId = 0;

            // Peek the mesh ID.
            meshId = packet.PeekUInt32(PacketHeader.Size);

            Resource   resource;
            SimpleMesh mesh = null;

            // If it exists, make sure it's a mesh.
            if (resources.TryGetValue(ResourceUtil.UniqueKey(new PlaceholderMesh(meshId)), out resource))
            {
                Assert.Equal((ushort)RoutingID.Mesh, resource.TypeID);
                mesh = (SimpleMesh)resource;
            }

            switch (packet.Header.MessageID)
            {
            case (int)MeshMessageType.Invalid:
                Assert.True(false, "Invalid mesh message sent");
                break;

            case (int)MeshMessageType.Destroy:
                Assert.NotNull(mesh);
                resources.Remove(mesh.UniqueKey());
                break;

            case (int)MeshMessageType.Create:
                // Create message. Should not already exists.
                Assert.Null(mesh);//, "Recreating existing mesh.");
                mesh = new SimpleMesh(meshId);
                Assert.True(mesh.ReadCreate(reader));
                resources.Add(mesh.UniqueKey(), mesh);
                break;

            // Not handling these messages.
            case (int)MeshMessageType.Redefine:
            case (int)MeshMessageType.Finalise:
                break;

            default:
                Assert.NotNull(mesh);
                mesh.ReadTransfer(packet.Header.MessageID, reader);
                break;
            }
        }