Click here to Skip to main content
11,412,833 members (73,505 online)
Click here to Skip to main content
Articles » Multimedia » DirectX » Games » Downloads
Add your own
alternative version

Game Engine

, 20 Nov 2009 CPL
A game engine first prototype
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using MTV3D65;
using System.Xml;
using System.Windows.Forms;


namespace gefx
{
    public  class SaveScene
    {
       public  void WriteMain(string Path, string Name)
        {
            TextWriter tw = new StreamWriter(Path + Name );

            

            tw.Close();
        }

       public void WriteUnitsMesh(string Path, string Name, cUnit Units)
       {
           TextWriter tw = new StreamWriter(Path + Name);

           

           


           
           tw.Close();

       }



       //public void WriteTerrein(string Path, string Name, ref Terrain t, ref Watter w, ref SkyBox sky)
       //{

       //    TextWriter tw = new StreamWriter(Path + Name);

       //    tw.WriteLine(DateTime.Now);
       //    tw.WriteLine("<TEREN>");
       //    tw.WriteLine("HMAPA=" + t.Hmapa );
       //    tw.WriteLine("GT=" + t.TGround);
       //    tw.WriteLine("ET=" + t.TEnvT);
       //    tw.WriteLine("AT=" + t.TAlfa);
       //    tw.WriteLine("</TEREN>");
       //    tw.WriteLine("<SKY>");
       //    tw.WriteLine("Back=" + sky.TSkyBack  ); // 8
       //    tw.WriteLine("Front=" +sky.TSkyFront  );
       //    tw.WriteLine("Up=" + sky.TSkyTop  );
       //    tw.WriteLine("Down=" + sky.TSkyBottom  );
       //    tw.WriteLine("Front=" + sky.TSkyFront  );
       //    tw.WriteLine("Left=" + sky.TSkyLeft );
       //    tw.WriteLine("Right=" + sky.TSkyRight );
       //    tw.WriteLine("</SKY>");
       //    tw.WriteLine("<WATER>");
       //    tw.WriteLine("WATERT=" + w.TTexture); // 17
       //    tw.WriteLine("</WATER>");


       //    tw.Close();
       //}

       public string RelativeToP;

       private string ToRelative(string absolutePath, string relativeTo)
       {
           string[] absoluteDirectories = absolutePath.Split('\\');
           string[] relativeDirectories = relativeTo.Split('\\');

           //Get the shortest of the two paths
           int length = absoluteDirectories.Length < relativeDirectories.Length ? absoluteDirectories.Length : relativeDirectories.Length;

           //Use to determine where in the loop we exited
           int lastCommonRoot = -1;
           int index;

           //Find common root
           for (index = 0; index < length; index++)
               if (absoluteDirectories[index] == relativeDirectories[index])
                   lastCommonRoot = index;
               else
                   break;

           //If we didn't find a common prefix then throw
           //if (lastCommonRoot == -1)
               //throw new ArgumentException("Paths do not have a common base");

           //Build up the relative path
           StringBuilder relativePath = new StringBuilder();

           //Add on the ..
           for (index = lastCommonRoot + 1; index < absoluteDirectories.Length; index++)
               if (absoluteDirectories[index].Length > 0)
                   relativePath.Append("..\\");

           //Add on the folders
           for (index = lastCommonRoot + 1; index < relativeDirectories.Length - 1; index++)
               relativePath.Append(relativeDirectories[index] + "\\");
           relativePath.Append(relativeDirectories[relativeDirectories.Length - 1]);

           return relativePath.ToString();
       }

       public void WriteTerrein(string Path, ref Terrain t, ref Watter w, ref SkyBox sky,ref Clouds Oblaci,ref Fog Magla)
       {

           TextWriter tw = new StreamWriter(Path);

           //RelativeToP = Directory.GetDirectoryRoot(Path);

           RelativeToP = Directory.GetCurrentDirectory();

           
           tw.WriteLine(DateTime.Now);
           tw.WriteLine("<TEREN>");
           tw.WriteLine("HMAPA=" + ToRelative( RelativeToP,t.Hmapa) );
           tw.WriteLine("GT=" + ToRelative( RelativeToP,t.TGround) );
           tw.WriteLine("ET=" + ToRelative(RelativeToP,t.TEnvT ) );
           tw.WriteLine("AT=" + ToRelative(RelativeToP,t.TAlfa));
           tw.WriteLine("</TEREN>");
           tw.WriteLine("<SKY>");
           tw.WriteLine("Back=" + ToRelative(RelativeToP,sky.TSkyBack)); // 8
           tw.WriteLine("Front=" + ToRelative(RelativeToP,sky.TSkyFront));
           tw.WriteLine("Up=" + ToRelative(RelativeToP,sky.TSkyTop));
           tw.WriteLine("Down=" + ToRelative(RelativeToP,sky.TSkyBottom));
           tw.WriteLine("Front=" + ToRelative(RelativeToP,sky.TSkyFront));
           tw.WriteLine("Left=" + ToRelative(RelativeToP,sky.TSkyLeft));
           tw.WriteLine("Right=" + ToRelative(RelativeToP,sky.TSkyRight));
           tw.WriteLine("</SKY>");
           tw.WriteLine("<WATER>");
           tw.WriteLine("WATERT=" + ToRelative(RelativeToP,w.TTexture)); // 17
           tw.WriteLine("</WATER>");


           tw.WriteLine("<CLOUDS>");
           tw.WriteLine("CLOUDTEXTURE=" + ToRelative(RelativeToP,Oblaci.CloudsTextureEX )); // 19
           tw.WriteLine("ALTITUDE=" + Oblaci.Altitude.ToString()); // 20

           tw.WriteLine("Width=" + Oblaci.Width.ToString()); // 21
           tw.WriteLine("Height=" + Oblaci.Height.ToString()); // 22

           tw.WriteLine("SPEED=" + Oblaci.Speed.ToString() ); // 23

           tw.WriteLine("</CLOUDS>"); // 24


           tw.WriteLine("<FOG>");
           tw.WriteLine("CR=" + Magla.Colors.r.ToString () ); // 26
           tw.WriteLine("CG=" + Magla.Colors.g.ToString()); // 27
           tw.WriteLine("CB=" + Magla.Colors.b.ToString()); // 28
           tw.WriteLine("DEST=" + Magla.GustocaMagle.ToString ()); // 29
   

           tw.WriteLine("</FOG>"); // 24


           tw.Close();
       }
       //public void WriteTerrein(string Path, ref Terrain t, ref Watter w, ref SkyBox sky)
       //{

       //    TextWriter tw = new StreamWriter(Path);

       //    tw.WriteLine(DateTime.Now);
       //    tw.WriteLine("<TEREN>");
       //    tw.WriteLine("HMAPA=" + t.Hmapa);
       //    tw.WriteLine("GT=" + t.TGround);
       //    tw.WriteLine("ET=" + (t.TEnvT));
       //    tw.WriteLine("AT=" + (t.TAlfa));
       //    tw.WriteLine("</TEREN>");
       //    tw.WriteLine("<SKY>");
       //    tw.WriteLine("Back=" + (sky.TSkyBack)); // 8
       //    tw.WriteLine("Front=" + (sky.TSkyFront));
       //    tw.WriteLine("Up=" + (sky.TSkyTop));
       //    tw.WriteLine("Down=" + (sky.TSkyBottom));
       //    tw.WriteLine("Front=" + (sky.TSkyFront));
       //    tw.WriteLine("Left=" + (sky.TSkyLeft));
       //    tw.WriteLine("Right=" + (sky.TSkyRight));
       //    tw.WriteLine("</SKY>");
       //    tw.WriteLine("<WATER>");
       //    tw.WriteLine("WATERT=" + (w.TTexture)); // 17
       //    tw.WriteLine("</WATER>");


       //    tw.Close();
       //}
       public void LoadTerrein(string File, ref Terrain T, ref Watter w, ref SkyBox sky, 
           ref TVScene Scene,ref TVGlobals Globals,ref  gefxs Eng )
       {
           string [] para = new string[128];
           string line;
           int counter = 0;
           TextReader tr = new StreamReader(File);
           while ((line = tr.ReadLine()) != null)
           {
               para[counter] = line ;
               counter++;
           }
           tr.Close();

           //T.AddHeightMap(para[2].Split(
           string[] p = para[2].Split('=');
           T.AddHeightMap(p[1], ref Scene);

           //Engine.Teren.AddTexture(FName);
           
               string[] t = para[3].Split('=');
               T.AddTexture(t[1]);
          
           string[] t1 = para[4].Split('=');
           
           string[] t2 = para[5].Split('=');
           
           T.AddSplatTexture(t[1], t1[1], t2[1]);

           string[] s1 = para[8].Split ('=');
           string[] s2 = para[9].Split('=');
           string[] s3 = para[10].Split('=');
           string[] s4 = para[11].Split('=');
           string[] s5 = para[12].Split('=');
           string[] s6 = para[13].Split('=');
           string[] s7 = para[14].Split('=');

           //tw.WriteLine("Back=" + sky.TSkyBack  ); // 8
           //tw.WriteLine("Front=" +sky.TSkyFront  );
           //tw.WriteLine("Up=" + sky.TSkyTop  );
           //tw.WriteLine("Down=" + sky.TSkyBottom  );
           //tw.WriteLine("Front=" + sky.TSkyFront  );
           //tw.WriteLine("Left=" + sky.TSkyLeft );
           //tw.WriteLine("Right=" + sky.TSkyRight );
           sky.AddSkyBox(s3[1], s4[1], s6[1], s7[1], s2[1], s1[1], ref Globals);

           string[] w1 = para[17].Split('=');

           if (w1[1] != "no")
           {

               Eng.AddWater(w1[1], T.Land);
           }

           //tw.WriteLine("CLOUDTEXTURE=" + ToRelative(RelativeToP, Oblaci.CloudsTextureEX)); // 19
           //tw.WriteLine("ALTITUDE=" + ToRelative(RelativeToP, Oblaci.Altitude.ToString())); // 20

           //tw.WriteLine("Width=" + ToRelative(RelativeToP, Oblaci.Width.ToString())); // 21
           //tw.WriteLine("Height=" + ToRelative(RelativeToP, Oblaci.Height.ToString())); // 22

           //tw.WriteLine("SPEED=" + ToRelative(RelativeToP, Oblaci.Speed.ToString())); // 23
           string[] c1 = para[20].Split('=');
           string[] c2 = para[21].Split('=');
           string[] c3 = para[22].Split('=');
           string[] c4 = para[23].Split('=');
           string[] c5 = para[24].Split('=');

           Eng.Oblaci.AddClouds(c1[1], 
               System.Convert.ToSingle(c2[1]),
               System.Convert.ToSingle(c3[1]),
               System.Convert.ToSingle(c4[1]), 
               System.Convert.ToSingle(c5[1]));

           //tw.WriteLine("CR=" + Magla.Colors.r.ToString()); // 26
           //tw.WriteLine("CG=" + Magla.Colors.g.ToString()); // 27
           //tw.WriteLine("CB=" + Magla.Colors.b.ToString()); // 28
           //tw.WriteLine("DEST=" + Magla.GustocaMagle.ToString()); // 29

           string[] f1 = para[27].Split('=');
           string[] f2 = para[28].Split('=');
           string[] f3 = para[29].Split('=');
           string[] f4 = para[30].Split('=');

           Eng.Magla.AddFog(new TV_COLOR(System.Convert.ToSingle(f1[1]),
               System.Convert.ToSingle(f2[1]),
               System.Convert.ToSingle(f3[1]),10), System.Convert.ToSingle(f4[1]));


           

       }




       

       

    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Common Public License Version 1.0 (CPL)

Share

About the Author

Member 3873633
Software Developer
Croatia Croatia
Programer

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150427.1 | Last Updated 20 Nov 2009
Article Copyright 2009 by Member 3873633
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid