Exemplo n.º 1
0
        internal static int ClearOldEntries(ClientMain game, long maxAge)
        {
            ClientPlatformAbstract platform = game.GetType().GetField("Platform", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public).GetValue(game) as ClientPlatformAbstract;
            var invalidEntries = MeshRefs.Where(pair => !pair.Value.IsValid(maxAge));

            foreach (var entry in invalidEntries)
            {
                platform.DeleteMesh(entry.Value.Value);
                MeshRefs.Remove(entry.Key);
            }
            return(invalidEntries.Count());
        }
Exemplo n.º 2
0
        private static MeshRef GenerateMesh(ClientMain game, string meshId, ItemStack stack)
        {
            MeshRef         meshRef = null;
            UnloadableShape shape   = new UnloadableShape();

            if (stack.Item.Shape?.Base != null)
            {
                shape.Load(game, new AssetLocationAndSource(stack.Item.Shape.Base));
            }
            if (shape.Textures == null)
            {
                shape.Textures = new Dictionary <string, AssetLocation>();
            }
            if (shape.AttachmentPointsByCode == null)
            {
                shape.AttachmentPointsByCode = new Dictionary <string, AttachmentPoint>();
            }
            Item item = new Item();

            item.Textures = new Dictionary <string, CompositeTexture>();

            foreach (ItemstackAttribute attr in stack.Attributes.GetOrAddTreeAttribute("toolparts").Values)
            {
                ItemStack partstack = attr.GetValue() as ItemStack;
                IToolPart part      = partstack.Item as IToolPart;
                if (part != null)
                {
                    if (part.TinkerProps?.ProvidedTextures == null)
                    {
                        partstack.Item.Textures.ToList().ForEach(kp =>
                        {
                            shape.Textures[kp.Key] = kp.Value.Base;
                            item.Textures[kp.Key]  = kp.Value;
                        });
                        UnloadableShape tmp = new UnloadableShape();
                        if (!tmp.Load(game, new AssetLocationAndSource(partstack.Item.Shape.Base)))
                        {
                            continue;
                        }


                        ShapeElement slot = shape.GetElementByName(part.TinkerProps.PartType);

                        if (slot != null)
                        {
                            slot.Children = slot.Children.Concat(tmp.CloneElements()[0].Children).ToArray();
                        }

                        if (tmp.AttachmentPointsByCode != null)
                        {
                            tmp.AttachmentPointsByCode.ToList().ForEach(kp => shape.AttachmentPointsByCode[kp.Key] = kp.Value);
                        }
                    }
                    else
                    {
                        part.TinkerProps.ProvidedTextures.ToList().ForEach(kp =>
                        {
                            shape.Textures[kp.Key] = kp.Value;
                            item.Textures[kp.Key]  = new CompositeTexture()
                            {
                                Base = kp.Value.Clone()
                            };
                        });
                    }
                }
            }

            ShapeTesselatorManager  manager    = game.GetType().GetField("TesselatorManager", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public).GetValue(game) as ShapeTesselatorManager;
            ItemTextureAtlasManager blockAtlas = game.GetType().GetField("ItemAtlasManager", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public).GetValue(game) as ItemTextureAtlasManager;
            ClientPlatformAbstract  platform   = game.GetType().GetField("Platform", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public).GetValue(game) as ClientPlatformAbstract;

            if (manager != null && blockAtlas != null && platform != null)
            {
                TextureSource       source  = new TextureSource(game, blockAtlas.Size, item);
                var                 field   = manager.Tesselator.GetType().GetField("meta", BindingFlags.Instance | BindingFlags.NonPublic);
                var                 oldMeta = field.GetValue(manager.Tesselator) as TesselationMetaData;
                TesselationMetaData meta    = oldMeta.Clone();
                meta.texSource    = source;
                meta.withJointIds = false;
                MeshData meshData;
                manager.TLTesselator.Value.TesselateShape((Shape)shape, out meshData, new Vec3f(), new Vec3f(), meta);
                meshRef          = platform.UploadMesh(meshData);
                MeshRefs[meshId] = new AccessLifetime <MeshRef>(meshRef);
            }
            return(meshRef);
        }