Пример #1
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main(string[] args)
        {
            string xgcFile;
            if (args.Length < 1)
            {
                throw new Exception(@"Command line argument should be xgc file like: C:\src\xgc3\xgc3\GameEditor.xgc");
            }
            else
            {
                xgcFile = args[0];
            }

            GameManager gm = new GameManager();

            Compiler compiler = new Compiler();
            compiler.OpenXml(new FileInfo(xgcFile));

            // IN MEMORY...compiler.CompileClasses(gm );
            // TO DLL
            try
            {
                compiler.CompileClassesToDll(gm, xgcFile + ".dll", true);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Environment.Exit(1);
                return;
            }

            Console.WriteLine("Compilation successful.");
            Environment.Exit(0);
            return;
        }
Пример #2
0
        /// <summary>
        /// PASS#1: Convert all classes in XML into C# code.
        /// Read all classes from XML and generate C# code for classes that do not have an assembly attribute
        /// </summary>
        /// <returns></returns>
        public void CompileClasses(GameManager gm)
        {
            // TODO: This seems so lame.
            gm.SymbolTable.AddClassSymbol( new Symbol("Application", "xgc3.RuntimeEnv.Application", "xgc3.Core.Instance"));

            StringBuilder csharp = new StringBuilder();

            // Start of file
            csharp.Append(makeheader());

            csharp.Append(CompileChildClasses(m_doc.DocumentElement, gm, "xgc3.Core.BaseInstanceClass"));

            // End of file
            csharp.Append(makefooter());

            #if !XBOX360
            try
            {
                CompileClasses(csharp.ToString());
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            #endif
        }
Пример #3
0
 public XgcGameComponent(Game game, GameManager gm)
     : base(game)
 {
     // TODO: Construct any child components here
     IsJustStarted = true;
     IsJustEnded = false;
 }
Пример #4
0
 /// <summary>
 /// Texture is lazy loaded, when needed.
 /// </summary>
 /// <param name="gm"></param>
 /// <returns></returns>
 public Texture2D GetTexture(GameManager gm)
 {
     if (Texture != null)
     {
         return this.Texture;
     }
     Texture = gm.Game.Content.Load<Texture2D>(this.AssetName);
     return this.Texture;
 }
Пример #5
0
        public void BuildSymbolTable(GameManager gm)
        {
            System.Diagnostics.Debug.WriteLine("BuildSymboldTable");
            // TODO: This seems so lame.
            gm.SymbolTable.AddClassSymbol( new Symbol("Application", "xgc3.RuntimeEnv.Application", "xgc3.Core.Instance"));

            // Ignore the generated CS code, and don't compile into a DLL.
            // But we DO want the gm.symbolTable generated.
            CompileChildClasses(m_doc.DocumentElement, gm, "xgc3.Core.BaseInstanceClass");
            CompileChildInstance(m_doc.DocumentElement, null, gm, "xgc3.Generated", 0);
        }
Пример #6
0
        /// <summary>
        /// Instantiate and hookup all instances.
        /// </summary>
        /// <param name="gm"></param>
        /// <param name="st"></param>
        /// <param name="rot"></param>
        public void LoadInstances(GameManager mgr)
        {
            // Create a new style sheet manager for this loader.
            m_styleSheetManager = new StyleSheetManager();

            if (m_doc.DocumentElement.Name != "Application")
            {
                throw new Exceptions.CompileException("Expected 'Application' as root of code");
            }

            // Load the application node and all it's children.
            LoadNode(null, m_doc.DocumentElement, mgr, null, 0);
        }
Пример #7
0
        // The include tag is left there, but INSIDE the include tag is all the included content.
        private void LoadAllChildren(Instance parentInstance, XmlNode parentNode, GameManager gm, string parentClassName)
        {
            // Algo...
            // Traverse entire tree...
            //   If <tagname> is one of "class", "include", "library", or "application" ignore it.
            //   If <tagname> is in symbol table, then create instance of it. Add all children to parent.
            //   If <tagname> is EVENT, METHOD, or ATTR
            //   If <tagname> is not in symbol table, then error.
            int uniqueIndex = 0;
            foreach (XmlNode childNode in parentNode.ChildNodes)
            {
                LoadNode(parentInstance, childNode, gm, parentClassName, uniqueIndex);
                uniqueIndex++;
            }

            return;
        }
Пример #8
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main(string[] args)
        {
            try
            {
                string xgcFile;
                if (args.Length < 1)
                {
                    xgcFile = "GameEditor.xgc.dll";
                    //throw new Exception( @"Command line argument should be compiled dll game file like: C:\src\xgc3\xgc3\GameEditor.xgc.dll");
                }
                else
                {
                    xgcFile = args[0];
                }

                GameManager gm = new GameManager();

                using (XnaGame game = new XnaGame(gm))
                {
                    gm.Game = game;

                    // Create the symbol table. IGNORE the cscript generation... because the script was already
                    //  compiled to a DLL by the XGCC compiler.
                    Compiler compiler = new Compiler();
                    compiler.OpenXml(new FileInfo(xgcFile));
                    compiler.BuildSymbolTable(gm);

                    // Read in XML and flatten out any includes.
                    Loader loader = new Loader();
                    loader.OpenXml(new FileInfo(xgcFile));

                    loader.LoadInstances(gm);

                    // This will create first room and all instances it needs.
                    //compiler.Run(compiler);
                    game.GotoRoom(gm.RunningObjectTable.GetInstance("Editor") as Room, gm); // TODO: First room?

                    game.Run();

                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Application failure: " + ex.Message);
            }
        }
Пример #9
0
        public XgcGame( GameManager gm)
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";

            // Create all game components.
            FontManagerComponent fm = new FontManagerComponent(this);
            this.Components.Add( fm);
            this.Services.AddService(typeof(IFontManager), fm);

            this.Components.Add(new FpsCounterComponent(this));

            this.Components.Add(new MousePointerComponent(this));

            MouseInputComponent mim = new MouseInputComponent(this);
            this.Components.Add(mim);
            this.Services.AddService(typeof(IMouseInputManager), mim);

            XgcGameComponent xgc = new XgcGameComponent(this, gm);
            this.Components.Add( xgc);
            GameComponent = xgc;
        }
Пример #10
0
        public XnaGame( GameManager gm)
        {
            System.Diagnostics.Debug.WriteLine("XnaGame constructor");
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";

            // Create all game components.
            FontManagerComponent fm = new FontManagerComponent(this);
            this.Components.Add( fm);
            this.Services.AddService(typeof(IFontManager), fm);

            #if !XBOX360
            this.Components.Add(new MousePointerComponent(this));

            MouseInputComponent mim = new MouseInputComponent(this);
            this.Components.Add(mim);
            this.Services.AddService(typeof(IMouseInputManager), mim);
            #endif

            XgcGameComponent xgc = new XgcGameComponent(this, gm);
            this.Components.Add( xgc);
            GameComponent = xgc;
        }
Пример #11
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <param name="typeName"></param>
        /// <param name="gm">Populate every instance with a call back to this top-level-object.</param>
        /// <returns></returns>
        public Instance Construct(string id, string typeName, GameManager gm)
        {
            string fulltypename;
            try
            {
                fulltypename = m_symbols[typeName].FullClassName;
            }
            catch (Exception)
            {
                throw new Exceptions.CompileException("Unknown type: {0}",  typeName);
            }
            try
            {
                // Problems instantiating flower 4
                //MAYBE I NEED A PUBLIC CONSTRUCTOR.
                // Also fails: Assembly.Load("GameEditor.xgc, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"); //
                Assembly asm = Assembly.LoadFrom( "GameEditor.xgc.dll"); // TODO - Use passed in name.
                 object oo = asm.CreateInstance(fulltypename);
                 Instance bi = oo as Instance;

#if LOAD_WITH_CSSCRIPT
                else
                {
                    // Generated classes must be instantiated this way.
                    bi = (Instance)m_helper.CreateObject(fulltypename);
                }
#endif
                if (bi != null)
                {
                    bi.Name = id;
                    bi.GameMgr = gm;
                    bi.IsJustCreated = true;
                    bi.ChildrenType = m_symbols[typeName].ChildrenType;

                    // TODO: Set defaults on all properties from class here.

                }

                return bi;
            }
            catch (Exception ex)
            {
                throw new Exceptions.CompileException( ex.Message);
                //"Only types that inherit from Instance can be constructed. ID={0} Type={1}", id, typeName);
            }

        }
Пример #12
0
        /// <summary>
        /// PASS#2: Some instances have handlers and other code that needs to be compiled. Do that here.
        /// </summary>
        /// <param name="gm"></param>
        /// <param name="?"></param>
        public void CompileInstances( GameManager gm)
        {
            StringBuilder csharp = new StringBuilder();

            // Start of file
            csharp.Append(makeheader());

            csharp.Append( CompileChildInstance(m_doc.DocumentElement, null, gm, "xgc3.Generated", 0 ));

            // End of file
            csharp.Append(makefooter());

            #if !XBOX360
            CompileClasses( m_using.ToString() + csharp.ToString());
            #endif
        }
Пример #13
0
        /// <summary>
        /// Classes can be nested, so we need to reurse
        /// </summary>
        /// <param name="parentNode"></param>
        private string CompileChildInstances( XmlNode parentNode, GameManager gm, string parentClassName )
        {
            StringBuilder csharp = new StringBuilder();

            XmlNodeList childNodes = parentNode.ChildNodes;
            if (childNodes != null)
            {
                int uniqueIndex = 0;
                foreach (XmlNode node in childNodes)
                {
                    csharp.Append( CompileChildInstance(node, parentNode, gm, parentClassName, uniqueIndex));
                    uniqueIndex++;
                }
            }
            return csharp.ToString();
        }
Пример #14
0
        private string CompileChildInstance(XmlNode node, XmlNode parentNode, GameManager gm, string parentClassName, int uniqueIndex )
        {
            StringBuilder csharp = new StringBuilder();

            if (node.Name == "Attribute")
            {
                string name = GetInstanceId(node, parentClassName, uniqueIndex);
                if (name == parentNode.Name)
                {
                    throw new Exceptions.CompileException("Attribute name cannot be same as class: " + name);
                }
                string type = GetRequiredAttribute(node, "Type");
                string defaultValue = GetOptionalAttribute(node, "DefaultValue", null);
                if ( defaultValue != null && (type == "string" || type == "String"))
                {
                    defaultValue = "\"" + defaultValue + "\"";
                }
                string protection = GetOptionalAttribute(node, "Protection", "public"); // Public/Private/Protected
                bool isConstant = GetOptionalAttribute(node, "Constant", false);
                if (defaultValue == null)
                {
                    if (isConstant)
                    {
                        throw new Exceptions.CompileException("Constant attribute missing default value");
                    }
                    csharp.Append(String.Format("{0} {1} {2};\r\n", protection, type, name));
                }
                else
                {
                    // Special handling for default value
                    if (!isConstant)
                    {
                        csharp.Append(String.Format("{0} {1} {2} = \"{3}\";\r\n", protection, type, name, defaultValue));
                    }
                    else
                    {
                        csharp.Append(String.Format("{0} const {1} {2} = \"{3}\";\r\n", protection, type, name, defaultValue));
                    }
                }
            }
            else if (node.Name == "Resource")
            {
                // Resoures are constant and one-per-class (static).
                string name = GetInstanceId(node, parentClassName, uniqueIndex);
                if (name == parentNode.Name)
                {
                    throw new Exceptions.CompileException("Resource name cannot be same as class: " + name);
                }
                string type = GetRequiredAttribute(node, "Type");
                string assetName = GetRequiredAttribute(node, "AssetName");

                // public const static ResourceSprite X = new ResourceSprite( "X", "XXX");
                csharp.Append(String.Format("static public xgc3.Resources.{0}Resource {1} = new xgc3.Resources.{2}Resource( \"{3}\", \"{4}\");", type, name, type, name, assetName));

            }
            else if (node.Name == "Event")
            {
                // TODO: At compile-time, how can I tell that I already have an event with the same name defined
                //  in the base class? You'll see error in CODE compilation, but I'd like to give the user a better warning.
                // I think what I need to do is make a data structure that keeps track of all classes created, and what
                //  attributes, events, and methods each has. Then check against that.
                // Another way is to indicate the line of XML that generated each line of code, so I can point back to it later.

                string name = GetInstanceId(node, parentClassName, uniqueIndex);
                string code = node.InnerText;
                csharp.Append(String.Format("private void On_{0}( xgc3.Core.Instance self, xgc3.Core.Instance other, String extra)\r\n", name));
                csharp.Append("{" + code + "}\r\n");
                csharp.Append(String.Format("public event EventDelegate {0};\r\n", name));
                csharp.Append(String.Format("public void Raise_{0}(Instance self, Instance other, string extra)\r\n", name));
                csharp.Append("\t{ if (" + name + " != null) { " + name + "(self, other, extra); }}\r\n");

                // TODO: Need to += when creating instance.
            }
            else if (node.Name == "Handler")
            {
                string name = GetInstanceId(node, parentClassName, uniqueIndex);
                string code = node.InnerText;
                csharp.Append(String.Format("private new void On_{0}( xgc3.Core.Instance selfInstance, xgc3.Core.Instance other, String extra)\r\n", name));

                // Generate code for local var, self, which is a typesafe version of selfInstance.
                // self, also happens to be the safe as "this".
                string fixedParentClassName = parentClassName.Replace("+", ".");
                csharp.Append("{ " + fixedParentClassName + " self = selfInstance as " + fixedParentClassName + ";" + code + "}\r\n");

                // TODO: Need to += when creating instance.

            }
            else if (node.Name == "Method")
            {
                string name = GetInstanceId(node, parentClassName, uniqueIndex);
                string args = GetOptionalAttribute(node, "Args", "");
                string returns = GetOptionalAttribute(node, "Returns", "void");
                string code = node.InnerText;
                csharp.Append(String.Format("public {0} {1}( " + args + ")\r\n", returns, name));
                csharp.Append("{ " + code + "}\r\n");
            }
            else if (node.Name == "Using")
            {
                // using namespace
                string ns = GetRequiredAttribute(node, "Namespace");

                // Prepend the USING statement at top of file.
                m_using.Append("using " + ns + ";\r\n");
            }
            else if ((node.Name != "Class") && (node.Name != "Include") && node.Name != "Library" && node.Name != "#comment")
            {
                // This is an instance
                XmlNode classNode = node;

                string name = GetInstanceId(node, parentClassName, uniqueIndex);
                string className = classNode.Name; // _ makes unique, so class for instance doesn't conflict with instance.
                string fullBaseClass = gm.SymbolTable.LookupFullTypeName(className); // Not full base class name.

                string uniqueClassName = className + "_" + name;

                string fullClassName;
                if (node.Name == "Application") // TODO
                {
                    // Special naming for first level.
                    fullClassName = parentClassName + "." + uniqueClassName;
                }
                else
                {
                    fullClassName = parentClassName + "+" + uniqueClassName;
                }

                // "Clones" allows you to inherit from an instance.
                string clones = GetOptionalAttribute(classNode, "Clones", null);
                if (clones != null)
                {
                    // How can I lookup an instance to find out what its class is?
                    fullBaseClass = gm.SymbolTable.LookupFullTypeNameOfInstance(clones);

                    // When cloning a class, the typename in our symbol table is the one used for creation using reflection.
                    //  We will be generating new code, so we need to change the + to .
                    fullBaseClass = fullBaseClass.Replace("+", ".");
                }

                // Keep track of all symbols
                // Make a unique name for class -- there could be two classes with same type but different names.
                gm.SymbolTable.AddClassSymbol(new Symbol(fullClassName, fullClassName, fullBaseClass));

                // So we can lookup the class of an instance (kinda like ROT, but compile time).
                // Used for clones.
                gm.SymbolTable.AddClassInstanceName(name, fullClassName);

                // start of class
                csharp.Append("public class " + uniqueClassName + " : " + fullBaseClass + " { \r\n");

                // Need an empty PUBLIC constructor for COMPACT FRAMEWORK on XBOX -- Nope.
                csharp.Append("public " + uniqueClassName + "() {}\r\n");

                // Recurse for nested instances
                csharp.Append(CompileChildInstances(node, gm, fullClassName));

                // End of class
                csharp.Append("}\r\n");

            }
            else
            {
                // Recurse for nested instances
                if ((node.Name != "Class"))
                {
                    csharp.Append(CompileChildInstances(node, gm, parentClassName));
                }
            }

            return csharp.ToString();
        }
Пример #15
0
        /// <summary>
        /// Classes can be nested, so we need to reurse
        /// </summary>
        /// <param name="parentNode"></param>
        private string CompileChildClasses( XmlNode parentNode, GameManager gm, string parentClassName)
        {
            StringBuilder csharp = new StringBuilder();

            XmlNodeList childNodes = parentNode.ChildNodes;
            if (childNodes != null)
            {

                foreach (XmlNode node in childNodes)
                {
                    if (node.Name == "Class")
                    {
                        XmlNode classNode = node;

                        Symbol symbol = Symbol.Parse(classNode);

                        // GetRequiredAttribute(classNode, "Name");
                        // GetOptionalAttribute(classNode, "CodeBehind", null); // Return NULL if none.
                        // GetOptionalAttribute(classNode, "ChildrenType", null); // Return NULL if none.

                        string clones = symbol.Clones; // GetOptionalAttribute(classNode, "Clones", null);
                        if (clones != null)
                        {
                            System.Diagnostics.Debug.WriteLine("'Clones' attribute not implemented. Skipping class.");
                            continue;
                        }

                        if (symbol.CodeBehind == null)
                        {

                            //baseClass = symbol.BaseClass; // GetRequiredAttribute(classNode, "BaseClass");

                            // Add namespace.
                            symbol.FullBaseClassName = gm.SymbolTable.LookupFullTypeName(symbol.BaseClass);
                            symbol.FullClassName = "xgc3.Generated." + symbol.Name; // st.LookupFullTypeName(className);

                            // start of class
                            csharp.Append("public class " + symbol.Name + " : " + symbol.FullBaseClassName + " { \r\n");

                            // Generate a constructor that attaches on all the events and handlers, as we go along
                            // LIKE:
                            // public Sprite()
                            //{
                            //    this.Draw += On_Draw;
                            //    this.Create += On_Create;
                            //    this.Destroy += On_Destroy;
                            //}
                            StringBuilder constructor = new StringBuilder("public " + symbol.Name + "() { \r\n");

                            // Add attribute
                            // Example <Attribute Name="Title" Type="String" />
                            XmlNodeList attributeNodes = classNode.SelectNodes("Attribute");
                            foreach (XmlNode attributeNode in attributeNodes)
                            {
                                string name = GetRequiredAttribute(attributeNode, "Name");
                                string protection = GetOptionalAttribute(attributeNode, "Protection", "public"); // Public, Private, Protected
                                bool isConstant = GetOptionalAttribute(attributeNode, "Constant", false);
                                if( name == symbol.Name)
                                {
                                    throw new Exceptions.CompileException( "Attribute name cannot be same as class: " + name);
                                }
                                string type = GetRequiredAttribute(attributeNode, "Type");

                                string defaultValue = GetOptionalAttribute(attributeNode, "DefaultValue", null);
                                if (defaultValue != null && (type == "string" || type == "String"))
                                {
                                    defaultValue = "\"" + defaultValue + "\"";
                                }

                                if (defaultValue == null)
                                {
                                    if (isConstant)
                                    {
                                        throw new Exceptions.CompileException("Constant attribute missing default value");
                                    }
                                    csharp.Append(String.Format("{0} {1} {2};\r\n", protection, type, name));
                                }
                                else
                                {
                                    if (!isConstant)
                                    {
                                        csharp.Append(String.Format("{0} {1} {2} = {3};\r\n", protection, type, name, defaultValue));
                                    }
                                    else
                                    {
                                        csharp.Append(String.Format("{0} const {1} {2} = {3};\r\n", protection, type, name, defaultValue));
                                    }
                                }
                            }

                            XmlNodeList resourceNodes = classNode.SelectNodes("Resource");
                            foreach (XmlNode resourceNode in resourceNodes)
                            {
                                // Resources are constant and one-per-class (static).
                                string name = GetRequiredAttribute(resourceNode, "Name");
                                if (name == parentNode.Name)
                                {
                                    throw new Exceptions.CompileException("Resource name cannot be same as class: " + name);
                                }
                                string type = GetRequiredAttribute(resourceNode, "Type");
                                string assetName = GetRequiredAttribute(resourceNode, "AssetName");

                                // public const static ResourceSprite X = new ResourceSprite( "X", "XXX");
                                csharp.Append(String.Format("static public xgc3.Resources.{0}Resource {1} = new xgc3.Resources.{2}Resource( \"{3}\", \"{4}\");", type, name, type, name, assetName));
                            }

                            XmlNodeList eventNodes = classNode.SelectNodes("Event");
                            foreach (XmlNode eventNode in eventNodes)
                            {
                                string name = GetRequiredAttribute(eventNode, "Name");
                                string code = eventNode.InnerText;
                                csharp.Append(emitDebugLine(eventNode));
                                csharp.Append(String.Format("public void On_{0}( xgc3.Core.Instance self, xgc3.Core.Instance other, String extra)\r\n", name));
                                csharp.Append("{" + code + "}\r\n");
                                csharp.Append(String.Format("public event EventDelegate {0};\r\n", name));
                                csharp.Append(String.Format("public void Raise_{0}(Instance self, Instance other, string extra)\r\n", name));
                                csharp.Append("\t{ if (" + name + " != null) { " + name+"(self, other, extra); }}\r\n");

                                // TODO: Need to += when creating instance.

                                constructor.Append( string.Format("this.{0} += On_{1};\r\n", name, name));
                            }

                            XmlNodeList methodNodes = classNode.SelectNodes("Method");
                            foreach (XmlNode methodNode in methodNodes)
                            {
                                string name = GetRequiredAttribute(methodNode, "Name");
                                string code = methodNode.InnerText;
                                string args = GetOptionalAttribute(methodNode, "Args", "");
                                string returns = GetOptionalAttribute(methodNode, "Returns", "void");
                                csharp.Append(emitDebugLine(methodNode));
                                csharp.Append(String.Format("public {0} {1}(" + args + ")\r\n", returns, name));
                                csharp.Append("{" + code + "}\r\n");
                            }

                            XmlNodeList handlerNodes = classNode.SelectNodes("Handler");
                            foreach (XmlNode handlerNode in handlerNodes)
                            {
                                string name = GetRequiredAttribute(handlerNode, "Name");
                                string code = handlerNode.InnerText;
                                csharp.Append(String.Format("private void On_{0}( xgc3.Core.Instance selfInstance, xgc3.Core.Instance other, String extra)\r\n", name));

                                // Generate code for local var, self, which is a typesafe version of selfInstance.
                                // self, also happens to be the safe as "this".
                                string fixedFullClassName = symbol.FullClassName.Replace("+", ".");
                                csharp.Append("{ " + fixedFullClassName + " self = selfInstance as " + fixedFullClassName + ";" + code + "}\r\n");

                                constructor.Append( string.Format("this.{0} += On_{1};\r\n", name, name));
                            }

                            constructor.Append("}\r\n");

                            // Recurse for nested classes
                            csharp.Append(CompileChildClasses(node, gm, symbol.FullClassName));

                            csharp.Append(constructor);

                            // End of class
                            csharp.Append("}\r\n");

                        }
                        else
                        {
                            UnallowedAttribute(classNode, "BaseClass");

                            if (classNode.ChildNodes.Count > 0)
                            {
                                throw new Exceptions.CompileException("Classes with 'CodeBehind' attribute cannot declare attributes, events, or methods");
                            }
                            // Class already exists in this project. No code behind needs to be generated.

                            // Figure out the BaseClass automatically...
                            Assembly assembly = Assembly.Load("xgc3dll");

                            // Get all Types available in the assembly in an array
                            symbol.FullBaseClassName = assembly.GetType(symbol.CodeBehind + "." + symbol.Name).BaseType.ToString();
                            if (symbol.FullBaseClassName == "System.Object")
                            {
                                // Special handler for root object.
                                symbol.FullBaseClassName = null;
                            }

                            symbol.FullClassName = symbol.CodeBehind + "." + symbol.Name;
                        }

                        // Keep track of all symbols
                        //if (childrenType != null)
                        //{
                        //    childrenType = gm.SymbolTable.GetType(childrenTypeName);
                        //}
                        gm.SymbolTable.AddClassSymbol( symbol );
                    }
                    else
                    {
                        // Recurse for classes nested in instances, etc.
                        csharp.Append(CompileChildClasses(node, gm, parentClassName));
                    }

                }
            }

            return csharp.ToString();
        }
Пример #16
0
 /// <summary>
 /// Set the current room.
 /// </summary>
 /// <param name="room"></param>
 /// <param name="symTable"></param>
 public void GotoRoom(Room room, GameManager gm)
 {
     Room = room;
     GameMgr = gm;
 }
Пример #17
0
        private void LoadNode(Instance parentInstance, XmlNode childNode, GameManager gm, string parentClassName, int uniqueIndex)
        {
            // skip comments
            if (childNode.NodeType == XmlNodeType.Comment)
            {
                return;
            }

            switch (childNode.Name)
            {
                case "Event":
                    {
                        // There should be a method on the script class with
                        // the name:
                        // instance.GetType().ToString() + "_" + name;
                        string name = GetInstanceId(childNode, parentClassName, uniqueIndex);
                        parentInstance.AddEventHandler(name);
                        break;

                    }
                case "Handler":
                    {
                        string name = GetInstanceId(childNode, parentClassName, uniqueIndex);
                        parentInstance.AddEventHandler(name);
                        break;
                    }
                case "Attribute":
                    {
                        // Add all attributes for instance.
                        //string name = GetRequiredAttribute(node, "Name");
                        //string t = GetRequiredAttribute(node, "Type");
                        //parentInstance.SetProperty(attr.Name, attr.Value);
                        break;
                    }
                case "Class":
                case "Method":
                case "Using":
                case "Resource":
                    // Skip
                    break;
                case "Include":
                    {
                        // Skip over these structural nodes.
                        if (childNode.HasChildNodes)
                        {
                            // Recurse
                            LoadAllChildren(parentInstance, childNode, gm, parentClassName);
                        }
                        break;
                    }
                case "Library":
                    // Skip over these structural nodes.
                    if (childNode.HasChildNodes)
                    {
                        // Recurse
                        LoadAllChildren(parentInstance, childNode, gm, parentClassName);
                    }
                    break;
                default:
                    {
                        string instanceId = GetInstanceId(childNode, parentClassName, uniqueIndex);

                        // Recurse
                        string nestClassName;
                        if (parentClassName == null)
                        {
                            // Yuck! Special case for constructing root object.
                            nestClassName = "xgc3.Generated." + childNode.Name + "_" + instanceId;
                        }
                        else
                        {
                            nestClassName = parentClassName + "+" + childNode.Name + "_" + instanceId;
                        }
                        Instance instance = gm.SymbolTable.Construct(instanceId, nestClassName, gm);

                        if (instance != null)
                        {
                            // Keep track of it by ID for quick lookup.
                            gm.RunningObjectTable.AddInstance(instance);

                            instance.Parent = parentInstance;

                            // Add instance to parent (root has no parent).
                            if (parentInstance != null)
                            {
                                if ( instance.ChildrenType != null)
                                {
                                    if ( !instance.GetType().IsSubclassOf( instance.ChildrenType))
                                    {
                                        throw new Exceptions.RuntimeEnvException("Unexpected child type. Expected: " + instance.ChildrenType.ToString());
                                    }
                                }

                                parentInstance.Children.Add(instanceId, instance);
                            }

                            // Set all properties on node.
                            foreach (XmlAttribute attr in childNode.Attributes)
                            {
                                instance.SetProperty(attr.Name, attr.Value);
                            }

                            if (childNode.HasChildNodes)
                            {
                                LoadAllChildren(instance, childNode, gm, nestClassName);
                            }
                        }
                        else
                        {
                            Console.WriteLine("Could not load instance of: " + nestClassName);
                        }

                        // If new styles found, add them to the stylsheet manager
                        if (childNode.Name == "StyleSheet")
                        {
                            StyleSheet sh = instance as StyleSheet;
                            m_styleSheetManager.AddStyleSheet(sh);
                        }

                        // Apply style sheet to just loaded instance.
                        m_styleSheetManager.ApplyStyleCascadeToInstance(instance);

                        //instance.Raise_Load(instance, null, null);
                    }

                    break;

                }
        }
Пример #18
0
        /// <summary>
        /// Convert code into a DLL.
        /// </summary>
        /// <param name="code"></param>
        /// <param name="outputDllName"></param>
        /// <param name="bDebug"></param>
        public void CompileClassesToDll( GameManager gm, string outputDllName, bool bDebug)
        {
            // TODO: This seems so lame.
            gm.SymbolTable.AddClassSymbol( new Symbol("Application", "xgc3.RuntimeEnv.Application", "xgc3.Core.Instance"));

            StringBuilder csharp = new StringBuilder();

            // Start of file
            csharp.Append(makeheader());

            csharp.Append(CompileChildClasses(m_doc.DocumentElement, gm, "xgc3.Core.BaseInstanceClass"));

            // Pass #2.
            csharp.Append(CompileChildInstance(m_doc.DocumentElement, null, gm, "xgc3.Generated", 0));

            // End of file
            csharp.Append(makefooter());

            #if !XBOX360
            try
            {
                string intermediateFile = outputDllName + ".cs";
                using (FileStream fs = new FileStream(intermediateFile, FileMode.Create))
                {
                    using (TextWriter writer = new StreamWriter(fs))
                    {
                        writer.Write(m_using.ToString() + csharp.ToString());

                    }
                }
                string[] assy = new string[] { @"c:\Program Files\Microsoft XNA\XNA Game Studio\v2.0\References\Windows\x86\Microsoft.Xna.Framework.dll",
                    @"c:\Program Files\Microsoft XNA\XNA Game Studio\v2.0\References\Windows\x86\Microsoft.Xna.Framework.Game.dll"};
                CSScript.Compile(intermediateFile, outputDllName, bDebug, assy);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            #endif
        }