internal static void Save(string path, Scene scene, TextureManager textureManager)
 {
     // Create a big string as the xml data 
     StringBuilder saveData = new StringBuilder();
     saveData.AppendLine("<gamedata>");
     {
         // Save the texture data (at some point associate with scene / when used)
         saveData.AppendLine("\t<texturedata>");
         {
             foreach (var textureEntry in textureManager)
             {
                 saveData.AppendFormat("\t\t<entry key=\"{0}\" value=\"{1}\" />\n",
                     textureEntry.Key, textureEntry.Value.Path);
             }
         }
         saveData.AppendLine("\t</texturedata>");
         // Save the scene
         saveData.AppendLine("\t<scenedata>");
         {
             // there's only one scene
             SaveScene(scene, 2, saveData);
         }
         saveData.AppendLine("\t</scenedata>");
     }
     saveData.AppendLine("</gamedata>");
     System.IO.File.WriteAllText(path, saveData.ToString());
 }
        private static void SaveScene(Scene scene, int indentLevel, StringBuilder xmlData)
        {
            xmlData.AppendLine(new string('\t', indentLevel) + "<scene>");
            {
                indentLevel++;
                xmlData.AppendLine(new string('\t', indentLevel) + "<navmesh>");
                {
                    indentLevel++;
                    SaveNavMeshPolygons(scene.NavMesh, indentLevel, xmlData);
                    SaveNavMeshLinks(scene.NavMesh, indentLevel, xmlData);
                    indentLevel--;
                }
                xmlData.AppendLine(new string('\t', indentLevel) + "</navmesh>");
                indentLevel--;

                indentLevel++;
                xmlData.AppendLine(new string('\t', indentLevel) + "<layers>");
                {
                    indentLevel++;
                    foreach (Layer layer in scene.Layers)
                    {
                        xmlData.AppendFormat(new string('\t', indentLevel) +
                            "<layer name=\"{0}\" textureid=\"{1}\" />",
                            layer.Name, layer.TextureId);

                    }
                    indentLevel--;
                }
                xmlData.AppendLine(new string('\t', indentLevel) + "</layers>");
                indentLevel--;
            }
            xmlData.AppendLine(new string('\t', indentLevel) + "</scene>");
        }
Exemple #3
0
        protected override void OnLoad(EventArgs e)
        {
            VSync = VSyncMode.On;

            scene = new Scene();

            CreateShaders();

            // Other state
            GL.Enable(EnableCap.DepthTest);
            GL.ClearColor(System.Drawing.Color.Black);
            GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
        }
 private static void LoadNavMesh(XmlTextReader xmlReader, Scene scene)
 {
     xmlReader.MoveToContent();
     while (xmlReader.Read())
     {
         if ("polygons" == xmlReader.Name)
         {
             LoadPolygons(xmlReader, scene.NavMesh);
         }
         else if ("links" == xmlReader.Name)
         {
             LoadLinks(xmlReader, scene.NavMesh);
         }
         else if ("navmesh" == xmlReader.Name)
         {
             return;
         }
     }
 }
 private static void LoadLayers(XmlTextReader xmlReader, Scene scene, TextureManager textureManager)
 {
     xmlReader.MoveToContent();
     while (xmlReader.Read())
     {
         if ("layer" == xmlReader.Name)
         {
             string name = xmlReader.GetAttribute("name");
             string textureId = xmlReader.GetAttribute("textureid");
             Layer layer = new Layer(name);
             layer.SetImage(textureManager.Get(textureId));
             scene.AddLayer(layer);
         }
         else if ("layers" == xmlReader.Name)
         {
             return;
         }
     }
 }
 private static void LoadSingleScene(XmlTextReader xmlReader, Scene scene, TextureManager textureManager)
 {
     xmlReader.MoveToContent();
     while (xmlReader.Read())
     {
         if ("navmesh" == xmlReader.Name)
         {
             LoadNavMesh(xmlReader, scene);
         }
         else if ("layers" == xmlReader.Name)
         {
             LoadLayers(xmlReader, scene, textureManager);
         }
         else if ("scene" == xmlReader.Name)
         {
             return;
         }
     }
 }
 private static void LoadSceneData(XmlTextReader xmlReader, Scene scene, TextureManager textureManager)
 {
     xmlReader.MoveToContent();
     while (xmlReader.Read())
     {
         if ("scene" == xmlReader.Name)
         {
             LoadSingleScene(xmlReader, scene, textureManager);
         }
         else if ("sceendata" == xmlReader.Name)
         {
             // Closing tag so jump out.
             return;
         }
     }
 }
 internal static void Open(string path, Scene scene, TextureManager textureManager, Layers layers)
 {
     XmlTextReader xmlReader = new System.Xml.XmlTextReader(path);
     xmlReader.MoveToContent();  // Jumps into top level header
     while (xmlReader.Read())
     {
         if ("texturedata" == xmlReader.Name)
         {
             LoadTextureData(xmlReader, textureManager);
         }
         else if("scenedata" == xmlReader.Name)
         {
             LoadSceneData(xmlReader, scene, textureManager);
         }
     }
     layers.RefreshLayerContent(scene.Layers);
 }
Exemple #9
0
 public static void LoadScene(string scene)
 {
     if (scenes.ContainsKey(scene))
     {
         current = scenes[scene];
     }
     else {
         string error = "The scene " + scene + " does not exist";
         System.Diagnostics.Debug.Assert(false, error);
     }
 }