Example #1
0
        internal static void InitDefaultContent()
        {
            const string VirtualContentPath    = ContentProvider.VirtualContentPath + "DrawTechnique:";
            const string ContentDir_SmoothAnim = VirtualContentPath + "SmoothAnim:";

            const string ContentPath_Solid     = VirtualContentPath + "Solid";
            const string ContentPath_Mask      = VirtualContentPath + "Mask";
            const string ContentPath_Add       = VirtualContentPath + "Add";
            const string ContentPath_Alpha     = VirtualContentPath + "Alpha";
            const string ContentPath_SharpMask = VirtualContentPath + "SharpAlpha";
            const string ContentPath_Multiply  = VirtualContentPath + "Multiply";
            const string ContentPath_Light     = VirtualContentPath + "Light";
            const string ContentPath_Invert    = VirtualContentPath + "Invert";
            const string ContentPath_Picking   = VirtualContentPath + "Picking";

            const string ContentPath_SmoothAnim_Solid    = ContentDir_SmoothAnim + "Solid";
            const string ContentPath_SmoothAnim_Mask     = ContentDir_SmoothAnim + "Mask";
            const string ContentPath_SmoothAnim_Add      = ContentDir_SmoothAnim + "Add";
            const string ContentPath_SmoothAnim_Alpha    = ContentDir_SmoothAnim + "Alpha";
            const string ContentPath_SmoothAnim_Multiply = ContentDir_SmoothAnim + "Multiply";
            const string ContentPath_SmoothAnim_Light    = ContentDir_SmoothAnim + "Light";
            const string ContentPath_SmoothAnim_Invert   = ContentDir_SmoothAnim + "Invert";

            ContentProvider.AddContent(ContentPath_Solid, new DrawTechnique(BlendMode.Solid));
            ContentProvider.AddContent(ContentPath_Mask, new DrawTechnique(BlendMode.Mask));
            ContentProvider.AddContent(ContentPath_Add, new DrawTechnique(BlendMode.Add));
            ContentProvider.AddContent(ContentPath_Alpha, new DrawTechnique(BlendMode.Alpha));
            ContentProvider.AddContent(ContentPath_Multiply, new DrawTechnique(BlendMode.Multiply));
            ContentProvider.AddContent(ContentPath_Light, new DrawTechnique(BlendMode.Light));
            ContentProvider.AddContent(ContentPath_Invert, new DrawTechnique(BlendMode.Invert));

            ContentProvider.AddContent(ContentPath_Picking, new DrawTechnique(BlendMode.Mask, ShaderProgram.Picking));
            ContentProvider.AddContent(ContentPath_SharpMask, new DrawTechnique(BlendMode.Alpha, ShaderProgram.SharpAlpha));

            ContentProvider.AddContent(ContentPath_SmoothAnim_Solid, new DrawTechnique(BlendMode.Solid, ShaderProgram.SmoothAnim, VertexType_C1P3T4A1));
            ContentProvider.AddContent(ContentPath_SmoothAnim_Mask, new DrawTechnique(BlendMode.Mask, ShaderProgram.SmoothAnim, VertexType_C1P3T4A1));
            ContentProvider.AddContent(ContentPath_SmoothAnim_Add, new DrawTechnique(BlendMode.Add, ShaderProgram.SmoothAnim, VertexType_C1P3T4A1));
            ContentProvider.AddContent(ContentPath_SmoothAnim_Alpha, new DrawTechnique(BlendMode.Alpha, ShaderProgram.SmoothAnim, VertexType_C1P3T4A1));
            ContentProvider.AddContent(ContentPath_SmoothAnim_Multiply, new DrawTechnique(BlendMode.Multiply, ShaderProgram.SmoothAnim, VertexType_C1P3T4A1));
            ContentProvider.AddContent(ContentPath_SmoothAnim_Light, new DrawTechnique(BlendMode.Light, ShaderProgram.SmoothAnim, VertexType_C1P3T4A1));
            ContentProvider.AddContent(ContentPath_SmoothAnim_Invert, new DrawTechnique(BlendMode.Invert, ShaderProgram.SmoothAnim, VertexType_C1P3T4A1));

            Solid      = ContentProvider.RequestContent <DrawTechnique>(ContentPath_Solid);
            Mask       = ContentProvider.RequestContent <DrawTechnique>(ContentPath_Mask);
            Add        = ContentProvider.RequestContent <DrawTechnique>(ContentPath_Add);
            Alpha      = ContentProvider.RequestContent <DrawTechnique>(ContentPath_Alpha);
            Multiply   = ContentProvider.RequestContent <DrawTechnique>(ContentPath_Multiply);
            Light      = ContentProvider.RequestContent <DrawTechnique>(ContentPath_Light);
            Invert     = ContentProvider.RequestContent <DrawTechnique>(ContentPath_Invert);
            Picking    = ContentProvider.RequestContent <DrawTechnique>(ContentPath_Picking);
            SharpAlpha = ContentProvider.RequestContent <DrawTechnique>(ContentPath_SharpMask);

            SmoothAnim_Solid    = ContentProvider.RequestContent <DrawTechnique>(ContentPath_SmoothAnim_Solid);
            SmoothAnim_Mask     = ContentProvider.RequestContent <DrawTechnique>(ContentPath_SmoothAnim_Mask);
            SmoothAnim_Add      = ContentProvider.RequestContent <DrawTechnique>(ContentPath_SmoothAnim_Add);
            SmoothAnim_Alpha    = ContentProvider.RequestContent <DrawTechnique>(ContentPath_SmoothAnim_Alpha);
            SmoothAnim_Multiply = ContentProvider.RequestContent <DrawTechnique>(ContentPath_SmoothAnim_Multiply);
            SmoothAnim_Light    = ContentProvider.RequestContent <DrawTechnique>(ContentPath_SmoothAnim_Light);
            SmoothAnim_Invert   = ContentProvider.RequestContent <DrawTechnique>(ContentPath_SmoothAnim_Invert);
        }
Example #2
0
        internal static void InitDefaultContent()
        {
            const string VirtualContentPath            = ContentProvider.VirtualContentPath + "Material:";
            const string ContentPath_SolidWhite        = VirtualContentPath + "SolidWhite";
            const string ContentPath_InvertWhite       = VirtualContentPath + "InvertWhite";
            const string ContentPath_DualityIcon       = VirtualContentPath + "DualityIcon";
            const string ContentPath_DualityIconB      = VirtualContentPath + "DualityIconB";
            const string ContentPath_DualityLogoBig    = VirtualContentPath + "DualityLogoBig";
            const string ContentPath_DualityLogoMedium = VirtualContentPath + "DualityLogoMedium";
            const string ContentPath_DualityLogoSmall  = VirtualContentPath + "DualityLogoSmall";
            const string ContentPath_Checkerboard      = VirtualContentPath + "Checkerboard";

            ContentProvider.AddContent(ContentPath_SolidWhite, new Material(DrawTechnique.Solid, ColorRgba.White));
            ContentProvider.AddContent(ContentPath_InvertWhite, new Material(DrawTechnique.Invert, ColorRgba.White));
            ContentProvider.AddContent(ContentPath_DualityIcon, new Material(DrawTechnique.Mask, ColorRgba.White, Texture.DualityIcon));
            ContentProvider.AddContent(ContentPath_DualityIconB, new Material(DrawTechnique.Mask, ColorRgba.White, Texture.DualityIconB));
            ContentProvider.AddContent(ContentPath_DualityLogoBig, new Material(DrawTechnique.Alpha, ColorRgba.White, Texture.DualityLogoBig));
            ContentProvider.AddContent(ContentPath_DualityLogoMedium, new Material(DrawTechnique.Alpha, ColorRgba.White, Texture.DualityLogoMedium));
            ContentProvider.AddContent(ContentPath_DualityLogoSmall, new Material(DrawTechnique.Alpha, ColorRgba.White, Texture.DualityLogoSmall));
            ContentProvider.AddContent(ContentPath_Checkerboard, new Material(DrawTechnique.Solid, ColorRgba.White, Texture.Checkerboard));

            SolidWhite        = ContentProvider.RequestContent <Material>(ContentPath_SolidWhite);
            InvertWhite       = ContentProvider.RequestContent <Material>(ContentPath_InvertWhite);
            DualityIcon       = ContentProvider.RequestContent <Material>(ContentPath_DualityIcon);
            DualityIconB      = ContentProvider.RequestContent <Material>(ContentPath_DualityIconB);
            DualityLogoBig    = ContentProvider.RequestContent <Material>(ContentPath_DualityLogoBig);
            DualityLogoMedium = ContentProvider.RequestContent <Material>(ContentPath_DualityLogoMedium);
            DualityLogoSmall  = ContentProvider.RequestContent <Material>(ContentPath_DualityLogoSmall);
            Checkerboard      = ContentProvider.RequestContent <Material>(ContentPath_Checkerboard);
        }
Example #3
0
        internal static void InitDefaultContent()
        {
            const string VirtualContentPath            = ContentProvider.VirtualContentPath + "Texture:";
            const string ContentPath_DualityIcon       = VirtualContentPath + "DualityIcon";
            const string ContentPath_DualityIconB      = VirtualContentPath + "DualityIconB";
            const string ContentPath_DualityLogoBig    = VirtualContentPath + "DualityLogoBig";
            const string ContentPath_DualityLogoMedium = VirtualContentPath + "DualityLogoMedium";
            const string ContentPath_DualityLogoSmall  = VirtualContentPath + "DualityLogoSmall";
            const string ContentPath_White             = VirtualContentPath + "White";
            const string ContentPath_Checkerboard      = VirtualContentPath + "Checkerboard";

            ContentProvider.AddContent(ContentPath_DualityIcon, new Texture(Pixmap.DualityIcon));
            ContentProvider.AddContent(ContentPath_DualityIconB, new Texture(Pixmap.DualityIconB));
            ContentProvider.AddContent(ContentPath_DualityLogoBig, new Texture(Pixmap.DualityLogoBig));
            ContentProvider.AddContent(ContentPath_DualityLogoMedium, new Texture(Pixmap.DualityLogoMedium));
            ContentProvider.AddContent(ContentPath_DualityLogoSmall, new Texture(Pixmap.DualityLogoSmall));
            ContentProvider.AddContent(ContentPath_White, new Texture(Pixmap.White));
            ContentProvider.AddContent(ContentPath_Checkerboard, new Texture(
                                           Pixmap.Checkerboard,
                                           SizeMode.Default,
                                           TextureMagFilter.Nearest,
                                           TextureMinFilter.Nearest,
                                           TextureWrapMode.Repeat,
                                           TextureWrapMode.Repeat));

            DualityIcon       = ContentProvider.RequestContent <Texture>(ContentPath_DualityIcon);
            DualityIconB      = ContentProvider.RequestContent <Texture>(ContentPath_DualityIconB);
            DualityLogoBig    = ContentProvider.RequestContent <Texture>(ContentPath_DualityLogoBig);
            DualityLogoMedium = ContentProvider.RequestContent <Texture>(ContentPath_DualityLogoMedium);
            DualityLogoSmall  = ContentProvider.RequestContent <Texture>(ContentPath_DualityLogoSmall);
            White             = ContentProvider.RequestContent <Texture>(ContentPath_White);
            Checkerboard      = ContentProvider.RequestContent <Texture>(ContentPath_Checkerboard);
        }
Example #4
0
        internal static void InitDefaultContent()
        {
            const string VirtualContentPath = ContentProvider.VirtualContentPath + "AudioData:";
            const string ContentPath_Beep   = VirtualContentPath + "Beep";

            ContentProvider.AddContent(ContentPath_Beep, new AudioData(DefaultContent.Beep));

            Beep = ContentProvider.RequestContent <AudioData>(ContentPath_Beep);
        }
Example #5
0
        internal static void InitDefaultContent()
        {
            const string VirtualContentPath = ContentProvider.VirtualContentPath + "Sound:";
            const string ContentPath_Beep   = VirtualContentPath + "Beep";

            ContentProvider.AddContent(ContentPath_Beep, new Sound(AudioData.Beep));

            Beep = ContentProvider.RequestContent <Sound>(ContentPath_Beep);
        }
Example #6
0
        public override bool ApplyNameToPath(out string conflictingPath)
        {
            conflictingPath = null;
            if (this.ReadOnly)
            {
                return(false);
            }

            string oldPath               = this.NodePath;
            string oldDirName            = Path.GetFileName(oldPath);
            string newPathBase           = oldPath.Remove(oldPath.Length - oldDirName.Length, oldDirName.Length);
            string newPath               = newPathBase + this.Text;
            bool   equalsCaseInsensitive = newPath.ToUpper() == oldPath.ToUpper();

            if (Directory.Exists(newPath) && !equalsCaseInsensitive)
            {
                conflictingPath = newPath;
                return(false);
            }

            try
            {
                if (equalsCaseInsensitive)
                {
                    // As Windows doesn't properly apply renames that change character casing
                    // and nothing else, we'll do a two-step rename using a temp path.
                    string tempPath = newPath + "_sSJencn83rhfSHhfn3ns456omvmvs28fndDN84ns";
                    Directory.Move(oldPath, tempPath);
                    Directory.Move(tempPath, newPath);
                }
                else
                {
                    Directory.Move(oldPath, newPath);
                }
            }
            catch (Exception e)
            {
                Logs.Editor.WriteError("Error moving directory from '{0}' to '{1}': {2}", oldPath, newPath, e);
                return(false);
            }

            // Between performing the move event and it being received by the FileEventManager there will be a
            // short window of inconsistency where the existing Resource is still registered under its old name
            // but the file is already renamed to the new name. To prevent loading the Resource twice, we'll pre-register
            // it under its new name.
            foreach (ResourceNode resNode in this.NodesDeep.OfType <ResourceNode>())
            {
                if (resNode.ResLink.ResWeak != null)
                {
                    ContentProvider.AddContent(resNode.NodePath.Replace(oldPath, newPath), resNode.ResLink.ResWeak);
                }
            }

            this.NodePath = newPath;
            return(true);
        }
Example #7
0
        [Test] public void AddRemoveContent()
        {
            Pixmap resource = new Pixmap();
            string alias    = "Foo";


            // Register the new resource with the provider
            ContentProvider.AddContent(alias, resource);

            // Expect it to be registered and show up in all relevant API calls
            Assert.IsTrue(ContentProvider.HasContent(alias));
            Assert.AreSame(resource, ContentProvider.RequestContent <Pixmap>(alias).Res);
            Assert.AreSame(resource, ContentProvider.RequestContent(alias).Res);
            CollectionAssert.Contains(ContentProvider.GetLoadedContent <Pixmap>(), (ContentRef <Pixmap>)resource);

            // Expect it to not show up in specialized API calls that have nothing to do with the registered resource
            CollectionAssert.DoesNotContain(ContentProvider.GetDefaultContent <Pixmap>(), (ContentRef <Pixmap>)resource);
            CollectionAssert.DoesNotContain(ContentProvider.GetAvailableContent <Pixmap>(), (ContentRef <Pixmap>)resource);

            // Expect the resource itself to reference back to its new primary path
            Assert.AreEqual(alias, resource.Path);
            Assert.IsFalse(resource.IsRuntimeResource);


            // Un-register the new resource, but don't dispose it
            ContentProvider.RemoveContent(alias, false);

            // Expect the resource to still be valid
            Assert.IsFalse(resource.Disposed);

            // Expect it to no longer show up in any of the relevant API calls
            Assert.IsFalse(ContentProvider.HasContent(alias));
            Assert.IsNull(ContentProvider.RequestContent <Pixmap>(alias).Res);
            Assert.IsNull(ContentProvider.RequestContent(alias).Res);
            CollectionAssert.DoesNotContain(ContentProvider.GetLoadedContent <Pixmap>(), (ContentRef <Pixmap>)resource);

            // Expect the resource itself to no longer back-reference to its former path
            Assert.IsNull(resource.Path);
            Assert.IsTrue(resource.IsRuntimeResource);


            // Re-register the resource, and immediately unregister-dispose it afterwards
            ContentProvider.AddContent(alias, resource);
            ContentProvider.RemoveContent(alias, true);

            // Expect the resource to be disposed and no longer show up in API calls
            Assert.IsTrue(resource.Disposed);
            Assert.IsFalse(ContentProvider.HasContent(alias));
            Assert.IsNull(ContentProvider.RequestContent <Pixmap>(alias).Res);
            Assert.IsNull(ContentProvider.RequestContent(alias).Res);
            CollectionAssert.DoesNotContain(ContentProvider.GetLoadedContent <Pixmap>(), (ContentRef <Pixmap>)resource);

            // Expect the resource path to remain unchanged, in order to allow reload-recovery
            Assert.AreEqual(alias, resource.Path);
            Assert.IsFalse(resource.IsRuntimeResource);
        }
        private static void RestoreTemporaryData(WorkerInterface workInterface, Stream strScene, Stream strData)
        {
            StreamReader strDataReader = new StreamReader(strData);
            string       scenePath     = strDataReader.ReadLine();

            workInterface.MainForm.Invoke((Action)(() => workInterface.TempScene = Resource.Load <Scene>(strScene, scenePath)));
            if (!workInterface.TempScene.IsRuntimeResource)
            {
                // Register the reloaded Scene in the ContentProvider, if it wasn't just a temporary one.
                workInterface.MainForm.Invoke((Action)(() => ContentProvider.AddContent(scenePath, workInterface.TempScene)));
            }
        }
 private void RetrieveResources()
 {
     if (!this.bigFont.IsAvailable)
     {
         Font bigFontRes = new Font();
         bigFontRes.Family  = System.Drawing.FontFamily.GenericSansSerif.Name;
         bigFontRes.Size    = 32;
         bigFontRes.Kerning = true;
         bigFontRes.ReloadData();
         ContentProvider.AddContent(bigFont.Path, bigFontRes);
     }
 }
Example #10
0
        internal static void InitDefaultContent()
        {
            const string VirtualContentPath     = ContentProvider.VirtualContentPath + "VertexShader:";
            const string ContentPath_Minimal    = VirtualContentPath + "Minimal";
            const string ContentPath_SmoothAnim = VirtualContentPath + "SmoothAnim";

            ContentProvider.AddContent(ContentPath_Minimal, new VertexShader(DefaultRes.MinimalVert));
            ContentProvider.AddContent(ContentPath_SmoothAnim, new VertexShader(DefaultRes.SmoothAnimVert));

            Minimal    = ContentProvider.RequestContent <VertexShader>(ContentPath_Minimal);
            SmoothAnim = ContentProvider.RequestContent <VertexShader>(ContentPath_SmoothAnim);
        }
Example #11
0
        internal static void InitDefaultContent()
        {
            const string VirtualContentPath     = ContentProvider.VirtualContentPath + "Sound:";
            const string ContentPath_Beep       = VirtualContentPath + "Beep";
            const string ContentPath_DroneLoop  = VirtualContentPath + "DroneLoop";
            const string ContentPath_LogoJingle = VirtualContentPath + "LogoJingle";

            ContentProvider.AddContent(ContentPath_Beep, new Sound(AudioData.Beep));
            ContentProvider.AddContent(ContentPath_DroneLoop, new Sound(AudioData.DroneLoop));
            ContentProvider.AddContent(ContentPath_LogoJingle, new Sound(AudioData.LogoJingle));

            Beep       = ContentProvider.RequestContent <Sound>(ContentPath_Beep);
            DroneLoop  = ContentProvider.RequestContent <Sound>(ContentPath_DroneLoop);
            LogoJingle = ContentProvider.RequestContent <Sound>(ContentPath_LogoJingle);
        }
Example #12
0
        public override bool ApplyNameToPath(out string conflictingPath)
        {
            conflictingPath = null;
            if (this.ReadOnly)
            {
                return(false);
            }

            string oldPath               = this.NodePath;
            string oldDirName            = Path.GetFileName(oldPath);
            string newPathBase           = oldPath.Remove(oldPath.Length - oldDirName.Length, oldDirName.Length);
            string newPath               = newPathBase + this.Text;
            bool   equalsCaseInsensitive = newPath.ToUpper() == oldPath.ToUpper();

            if (Directory.Exists(newPath) && !equalsCaseInsensitive)
            {
                conflictingPath = newPath;
                return(false);
            }

            if (equalsCaseInsensitive)
            {
                string tempPath = newPath + "_sSJencn83rhfSHhfn3ns456omvmvs28fndDN84ns";
                Directory.Move(oldPath, tempPath);
                Directory.Move(tempPath, newPath);
            }
            else
            {
                Directory.Move(oldPath, newPath);
            }

            // Between performing the move event and it being received by the FileEventManager there will be a
            // short window of inconsistency where the existing Resource is still registered under its old name
            // but the file is already renamed to the new name. To prevent loading the Resource twice, we'll pre-register
            // it under its new name.
            foreach (ResourceNode resNode in this.NodesDeep.OfType <ResourceNode>())
            {
                if (resNode.ResLink.ResWeak != null)
                {
                    ContentProvider.AddContent(resNode.NodePath.Replace(oldPath, newPath), resNode.ResLink.ResWeak);
                }
            }

            this.NodePath = newPath;
            return(true);
        }
Example #13
0
        internal static void InitDefaultContent()
        {
            const string VirtualContentPath     = ContentProvider.VirtualContentPath + "FragmentShader:";
            const string ContentPath_Minimal    = VirtualContentPath + "Minimal";
            const string ContentPath_Picking    = VirtualContentPath + "Picking";
            const string ContentPath_SmoothAnim = VirtualContentPath + "SmoothAnim";
            const string ContentPath_SharpMask  = VirtualContentPath + "SharpAlpha";

            ContentProvider.AddContent(ContentPath_Minimal, new FragmentShader(DefaultRes.MinimalFrag));
            ContentProvider.AddContent(ContentPath_Picking, new FragmentShader(DefaultRes.PickingFrag));
            ContentProvider.AddContent(ContentPath_SmoothAnim, new FragmentShader(DefaultRes.SmoothAnimFrag));
            ContentProvider.AddContent(ContentPath_SharpMask, new FragmentShader(DefaultRes.SharpAlphaFrag));

            Minimal    = ContentProvider.RequestContent <FragmentShader>(ContentPath_Minimal);
            Picking    = ContentProvider.RequestContent <FragmentShader>(ContentPath_Picking);
            SmoothAnim = ContentProvider.RequestContent <FragmentShader>(ContentPath_SmoothAnim);
            SharpAlpha = ContentProvider.RequestContent <FragmentShader>(ContentPath_SharpMask);
        }
Example #14
0
        internal static void InitDefaultContent()
        {
            const string VirtualContentPath       = ContentProvider.VirtualContentPath + "Material:";
            const string ContentPath_SolidWhite   = VirtualContentPath + "SolidWhite";
            const string ContentPath_SolidBlack   = VirtualContentPath + "SolidBlack";
            const string ContentPath_InvertWhite  = VirtualContentPath + "InvertWhite";
            const string ContentPath_Checkerboard = VirtualContentPath + "Checkerboard";

            ContentProvider.AddContent(ContentPath_SolidWhite, new Material(DrawTechnique.Solid, ColorRgba.White));
            ContentProvider.AddContent(ContentPath_SolidBlack, new Material(DrawTechnique.Solid, ColorRgba.Black));
            ContentProvider.AddContent(ContentPath_InvertWhite, new Material(DrawTechnique.Invert, ColorRgba.White));
            ContentProvider.AddContent(ContentPath_Checkerboard, new Material(DrawTechnique.Solid, ColorRgba.White, Texture.Checkerboard));

            SolidWhite   = ContentProvider.RequestContent <Material>(ContentPath_SolidWhite);
            SolidBlack   = ContentProvider.RequestContent <Material>(ContentPath_SolidBlack);
            InvertWhite  = ContentProvider.RequestContent <Material>(ContentPath_InvertWhite);
            Checkerboard = ContentProvider.RequestContent <Material>(ContentPath_Checkerboard);
        }
Example #15
0
        [Test] public void AddOverwritesContent()
        {
            Pixmap resourceA = new Pixmap();
            Pixmap resourceB = new Pixmap();
            string alias     = "Foo";

            // Register both first and second resource on the same alias
            ContentProvider.AddContent(alias, resourceA);
            ContentProvider.AddContent(alias, resourceB);

            // Expect the first resource to be disposed, and the second to be properly registered
            Assert.IsTrue(resourceA.Disposed);
            Assert.AreEqual(alias, resourceA.Path);
            Assert.IsTrue(ContentProvider.HasContent(alias));
            Assert.AreSame(resourceB, ContentProvider.RequestContent <Pixmap>(alias).Res);
            Assert.AreSame(resourceB, ContentProvider.RequestContent(alias).Res);
            CollectionAssert.Contains(ContentProvider.GetLoadedContent <Pixmap>(), (ContentRef <Pixmap>)resourceB);
        }
Example #16
0
        internal static void InitDefaultContent()
        {
            const string VirtualContentPath     = ContentProvider.VirtualContentPath + "ShaderProgram:";
            const string ContentPath_Minimal    = VirtualContentPath + "Minimal";
            const string ContentPath_Picking    = VirtualContentPath + "Picking";
            const string ContentPath_SmoothAnim = VirtualContentPath + "SmoothAnim";
            const string ContentPath_SharpMask  = VirtualContentPath + "SharpAlpha";

            ContentProvider.AddContent(ContentPath_Minimal, new ShaderProgram(VertexShader.Minimal, FragmentShader.Minimal));
            ContentProvider.AddContent(ContentPath_Picking, new ShaderProgram(VertexShader.Minimal, FragmentShader.Picking));
            ContentProvider.AddContent(ContentPath_SmoothAnim, new ShaderProgram(VertexShader.SmoothAnim, FragmentShader.SmoothAnim));
            ContentProvider.AddContent(ContentPath_SharpMask, new ShaderProgram(VertexShader.Minimal, FragmentShader.SharpAlpha));

            Minimal    = ContentProvider.RequestContent <ShaderProgram>(ContentPath_Minimal);
            Picking    = ContentProvider.RequestContent <ShaderProgram>(ContentPath_Picking);
            SmoothAnim = ContentProvider.RequestContent <ShaderProgram>(ContentPath_SmoothAnim);
            SharpAlpha = ContentProvider.RequestContent <ShaderProgram>(ContentPath_SharpMask);
        }
Example #17
0
        [Test] public void TransformHierarchyPrefabSceneBug(bool childPrefab)
        {
            // Tests for https://github.com/AdamsLair/duality/issues/53

            string  prefabName = "TestPrefab";
            string  parentName = "Parent";
            string  childName  = "Child";
            Vector3 parentPos  = new Vector3(100, 0, 0);
            Vector3 childPos   = new Vector3(200, 0, 0);

            // Create object hierarchy as described
            Scene      scene  = new Scene();
            GameObject parent = new GameObject(parentName);

            parent.AddComponent <Transform>();
            parent.Transform.Pos = parentPos;
            GameObject child = new GameObject(childName, parent);

            child.AddComponent <Transform>();
            child.Transform.Pos = childPos;
            scene.AddObject(parent);

            // Create a Prefab from this hierarchy, make it available and link to it
            Prefab prefab = new Prefab(childPrefab ? child : parent);

            ContentProvider.AddContent(prefabName, prefab);
            (childPrefab ? child : parent).LinkToPrefab(prefab);

            // Save the Scene and reload it
            using (MemoryStream stream = new MemoryStream())
            {
                scene.Save(stream);
                stream.Position = 0;
                scene           = Resource.Load <Scene>(stream);
            }

            // Gather new object references
            parent = scene.FindGameObject(parentName);
            child  = scene.FindGameObject(childName);

            // Check if positions are correct
            Assert.AreEqual(parentPos, parent.Transform.Pos);
            Assert.AreEqual(childPos, child.Transform.Pos);
        }
Example #18
0
        internal static void InitDefaultContent()
        {
            const string VirtualContentPath = ContentProvider.VirtualContentPath + "Texture:";

            const string ContentPath_White        = VirtualContentPath + "White";
            const string ContentPath_Checkerboard = VirtualContentPath + "Checkerboard";

            ContentProvider.AddContent(ContentPath_White, new Texture(Pixmap.White, keepPixmapDataResident: true));
            ContentProvider.AddContent(ContentPath_Checkerboard, new Texture(
                                           Pixmap.Checkerboard,
                                           SizeMode.Default,
                                           TextureMagFilter.Nearest,
                                           TextureMinFilter.Nearest,
                                           TextureWrapMode.Repeat,
                                           TextureWrapMode.Repeat,
                                           keepPixmapDataResident: true));

            White        = ContentProvider.RequestContent <Texture>(ContentPath_White);
            Checkerboard = ContentProvider.RequestContent <Texture>(ContentPath_Checkerboard);
        }
Example #19
0
        [Test] public void RenameContent()
        {
            Pixmap resource = new Pixmap();
            string aliasA   = "Foo";
            string aliasB   = "Bar";

            // Register the resource with one alias, then rename it to use another
            ContentProvider.AddContent(aliasA, resource);
            ContentProvider.RenameContent(aliasA, aliasB);

            // Expect the resource to use the second alias only, and the first to be unused
            Assert.AreEqual(aliasB, resource.Path);
            Assert.IsTrue(ContentProvider.HasContent(aliasB));
            Assert.AreSame(resource, ContentProvider.RequestContent <Pixmap>(aliasB).Res);
            Assert.AreSame(resource, ContentProvider.RequestContent(aliasB).Res);
            Assert.IsFalse(ContentProvider.HasContent(aliasA));
            Assert.IsNull(ContentProvider.RequestContent <Pixmap>(aliasA).Res);
            Assert.IsNull(ContentProvider.RequestContent(aliasA).Res);
            CollectionAssert.Contains(ContentProvider.GetLoadedContent <Pixmap>(), (ContentRef <Pixmap>)resource);
        }
Example #20
0
        private static void RestoreTemporaryData(WorkerInterface workInterface, Stream strScene, Stream strData)
        {
            StreamReader strDataReader = new StreamReader(strData);

            // Read back current scene path, account for Write/ReadLine transforming
            // null values into an empty string.
            string scenePath = strDataReader.ReadLine();

            if (string.IsNullOrEmpty(scenePath))
            {
                scenePath = null;
            }

            workInterface.MainForm.Invoke((Action)(() => workInterface.TempScene = Resource.Load <Scene>(strScene, scenePath)));
            if (!workInterface.TempScene.IsRuntimeResource)
            {
                // Register the reloaded Scene in the ContentProvider, if it wasn't just a temporary one.
                workInterface.MainForm.Invoke((Action)(() => ContentProvider.AddContent(scenePath, workInterface.TempScene)));
            }
        }
Example #21
0
        [Test] public void DisposeRemovesContent()
        {
            Pixmap resource = new Pixmap();
            string alias    = "Foo";

            // Register the new resource with the provider
            ContentProvider.AddContent(alias, resource);

            // Dispose the resource
            resource.Dispose();

            // Expect the resource to be disposed and no longer show up in API calls
            Assert.IsTrue(resource.Disposed);
            Assert.IsFalse(ContentProvider.HasContent(alias));
            Assert.IsNull(ContentProvider.RequestContent <Pixmap>(alias).Res);
            Assert.IsNull(ContentProvider.RequestContent(alias).Res);
            CollectionAssert.DoesNotContain(ContentProvider.GetLoadedContent <Pixmap>(), (ContentRef <Pixmap>)resource);

            // Expect the resource path to remain unchanged, in order to allow reload-recovery
            Assert.AreEqual(alias, resource.Path);
        }
Example #22
0
        [Test] public void RemoveContentTree()
        {
            Pixmap resource1 = new Pixmap();
            Pixmap resource2 = new Pixmap();
            Pixmap resource3 = new Pixmap();
            string dirA      = "Foo";
            string dirB      = "Bar";
            string alias1    = dirA + "/" + "Resource1";
            string alias2    = dirA + "/" + "Resource2";
            string alias3    = dirB + "/" + "Resource3";

            // Register all resources, then remove one of their directories
            ContentProvider.AddContent(alias1, resource1);
            ContentProvider.AddContent(alias2, resource2);
            ContentProvider.AddContent(alias3, resource3);
            ContentProvider.RemoveContentTree(dirA, true);

            // Expect the resources from the removed directory to be disposed, but not any other resource
            Assert.AreEqual(alias1, resource1.Path);
            Assert.AreEqual(alias2, resource2.Path);
            Assert.AreEqual(alias3, resource3.Path);
            Assert.IsFalse(ContentProvider.HasContent(alias1));
            Assert.IsFalse(ContentProvider.HasContent(alias2));
            Assert.IsTrue(ContentProvider.HasContent(alias3));
            Assert.IsNull(ContentProvider.RequestContent <Pixmap>(alias1).Res);
            Assert.IsNull(ContentProvider.RequestContent <Pixmap>(alias2).Res);
            Assert.AreSame(resource3, ContentProvider.RequestContent <Pixmap>(alias3).Res);
            Assert.IsNull(ContentProvider.RequestContent(alias1).Res);
            Assert.IsNull(ContentProvider.RequestContent(alias2).Res);
            Assert.AreSame(resource3, ContentProvider.RequestContent(alias3).Res);
            Assert.IsFalse(ContentProvider.HasContent(alias1));
            Assert.IsFalse(ContentProvider.HasContent(alias2));
            Assert.IsTrue(ContentProvider.HasContent(alias3));
            CollectionAssert.DoesNotContain(ContentProvider.GetLoadedContent <Pixmap>(), (ContentRef <Pixmap>)resource1);
            CollectionAssert.DoesNotContain(ContentProvider.GetLoadedContent <Pixmap>(), (ContentRef <Pixmap>)resource2);
            CollectionAssert.Contains(ContentProvider.GetLoadedContent <Pixmap>(), (ContentRef <Pixmap>)resource3);
        }
Example #23
0
        [Test] public void RenameContentTree()
        {
            Pixmap resource1 = new Pixmap();
            Pixmap resource2 = new Pixmap();
            string dirA      = "Foo";
            string dirB      = "Bar";

            // Let's choose some tricky path names that would break when doing a path-unaware string replace
            string alias1A = PathOp.Combine(dirA, "Foo", "Resource1");
            string alias2A = PathOp.Combine(dirA, "Bar", "Resource2");
            string alias1B = PathOp.Combine(dirB, "Foo", "Resource1");
            string alias2B = PathOp.Combine(dirB, "Bar", "Resource2");

            // Register the resources with their first alias, then rename their directory
            ContentProvider.AddContent(alias1A, resource1);
            ContentProvider.AddContent(alias2A, resource2);
            ContentProvider.RenameContentTree(dirA, dirB);

            // Expect the resources to use their second alias only, and the first to be unused
            Assert.AreEqual(alias1B, resource1.Path);
            Assert.AreEqual(alias2B, resource2.Path);
            Assert.IsTrue(ContentProvider.HasContent(alias1B));
            Assert.IsTrue(ContentProvider.HasContent(alias2B));
            Assert.AreSame(resource1, ContentProvider.RequestContent <Pixmap>(alias1B).Res);
            Assert.AreSame(resource2, ContentProvider.RequestContent <Pixmap>(alias2B).Res);
            Assert.AreSame(resource1, ContentProvider.RequestContent(alias1B).Res);
            Assert.AreSame(resource2, ContentProvider.RequestContent(alias2B).Res);
            Assert.IsFalse(ContentProvider.HasContent(alias1A));
            Assert.IsFalse(ContentProvider.HasContent(alias2A));
            Assert.IsNull(ContentProvider.RequestContent <Pixmap>(alias1A).Res);
            Assert.IsNull(ContentProvider.RequestContent <Pixmap>(alias2A).Res);
            Assert.IsNull(ContentProvider.RequestContent(alias1A).Res);
            Assert.IsNull(ContentProvider.RequestContent(alias2A).Res);
            CollectionAssert.Contains(ContentProvider.GetLoadedContent <Pixmap>(), (ContentRef <Pixmap>)resource1);
            CollectionAssert.Contains(ContentProvider.GetLoadedContent <Pixmap>(), (ContentRef <Pixmap>)resource2);
        }
Example #24
0
 private void AddTempContent(string path, Resource res)
 {
     ContentProvider.AddContent(path, res);
     localTempContent.Add(res);
 }
Example #25
0
        private static void PerformPluginReload(ref WorkerInterface workInterface, ref bool fullRestart)
        {
            Stream strScene;
            Stream strData;

            string tempDir       = Path.Combine(Path.GetTempPath(), "Duality");
            string tempScenePath = Path.Combine(tempDir, "ReloadPluginBackup" + Scene.FileExt);
            string tempDataPath  = Path.Combine(tempDir, "ReloadPluginBackup.dat");

            if (!Directory.Exists(tempDir))
            {
                Directory.CreateDirectory(tempDir);
            }

            if (!workInterface.RecoverMode)
            {
                // No full restart scheduled? Well, check if it should be!
                if (!fullRestart)
                {
                    fullRestart = workInterface.ReloadSched.Any(asmFile => asmFile.EndsWith(".editor.dll", StringComparison.InvariantCultureIgnoreCase) || !DualityApp.IsLeafPlugin(asmFile));
                }

                if (fullRestart)
                {
                    strScene = File.Create(tempScenePath);
                    strData  = File.Create(tempDataPath);
                }
                else
                {
                    strScene = new MemoryStream(1024 * 1024 * 10);
                    strData  = new MemoryStream(512);
                }

                // Save current data
                Log.Editor.Write("Saving data...");
                StreamWriter strDataWriter = new StreamWriter(strData);
                strDataWriter.WriteLine(Scene.CurrentPath);
                strDataWriter.Flush();
                workInterface.MainForm.Invoke((Action) delegate()
                {
                    // Save all data
                    DualityEditorApp.SaveAllProjectData();
                    Scene.Current.Save(strScene);
                });
                workInterface.Progress += 0.4f;
                Thread.Sleep(20);

                if (!fullRestart)
                {
                    // Reload core plugins
                    Log.Editor.Write("Reloading core plugins...");
                    Log.Editor.PushIndent();
                    int count = workInterface.ReloadSched.Count;
                    while (workInterface.ReloadSched.Count > 0)
                    {
                        string curPath = workInterface.ReloadSched[0];
                        workInterface.MainForm.Invoke((Action <string>)DualityApp.ReloadPlugin, curPath);
                        workInterface.Progress += 0.15f / (float)count;
                        Thread.Sleep(20);

                        string xmlDocFile = curPath.Replace(".dll", ".xml");
                        if (File.Exists(xmlDocFile))
                        {
                            workInterface.MainForm.Invoke((Action <string>)HelpSystem.LoadXmlCodeDoc, xmlDocFile);
                        }
                        workInterface.ReloadSched.RemoveAt(0);
                        workInterface.ReloadDone.Add(curPath);
                        workInterface.Progress += 0.05f / (float)count;
                    }
                    Log.Editor.PopIndent();

                    strScene.Seek(0, SeekOrigin.Begin);
                    strData.Seek(0, SeekOrigin.Begin);
                }
                else
                {
                    strScene.Close();
                    strData.Close();
                    bool debug = System.Diagnostics.Debugger.IsAttached;

                    // Close old form and wait for it to be closed
                    workInterface.Shutdown = true;
                    workInterface.MainForm.Invoke(new CloseMainFormDelegate(CloseMainForm), workInterface.MainForm);
                    while (workInterface.MainForm.Visible)
                    {
                        Thread.Sleep(20);
                    }

                    Process newEditor = Process.Start(Application.ExecutablePath, "recover" + (debug ? " debug" : ""));
                    return;
                }
            }
            else
            {
                strScene = File.OpenRead(tempScenePath);
                strData  = File.OpenRead(tempDataPath);
                workInterface.Progress = 0.6f;
            }

            // Reload data
            Log.Editor.Write("Restoring data...");
            StreamReader strDataReader = new StreamReader(strData);
            string       scenePath     = strDataReader.ReadLine();

            workInterface.TempScene = Resource.Load <Scene>(strScene, scenePath);
            if (!workInterface.TempScene.IsRuntimeResource)
            {
                // Register the reloaded Scene in the ContentProvider, if it wasn't just a temporary one.
                ContentProvider.AddContent(scenePath, workInterface.TempScene);
            }
            strScene.Close();
            strData.Close();

            workInterface.Progress = 1.0f;
            workInterface.Finished = true;
        }