Exemplo n.º 1
0
        public static void Init(ZApplication app)
        {
            defaultMaterial = new Material(null);
            GUIMaterial = new Material(null);
            GUIMaterial.Lighting = false;            
            defaultTexture = new Texture(null);
            defaultFont = new Font(null);

            GL.MatrixMode(All.MODELVIEW);
          
            GL.Enable(All.DEPTH_TEST);           

            //Enable Light
            //Use default position
            GL.Enable(All.LIGHTING);
            GL.Enable(All.LIGHT0);

            //Use glColor to color materials. 
            //This eliminates the need to set ambient and diffuse separately.
            GL.Enable(All.COLOR_MATERIAL);
            GL.ColorMaterial(All.FRONT_AND_BACK, All.AMBIENT_AND_DIFFUSE);

            //glMaterialfv(GL_FRONT, GL_SPECULAR, Specular);
            //glMaterialf(GL_FRONT, GL_SHININESS, LowShininess);         

            // IMPORTANT: Otherwise light will arise with scaled vectors, e.g. with Scale=0.1 then it will be too bright
            // This is because gl scales the normals with glScale
            //GL.Enable(All.NORMALIZE);

            var shape = new UnitQuad();
            unitQuad = new Mesh(null) { Name = "UnitQuad" };            
            unitQuad.CreateVBO(shape);

            defaultMaterial.Apply(null);            
        }
Exemplo n.º 2
0
        public static ZApplication Load(XmlDocument xmlDocument, ZTreeView treeView)
        {
            _treeView = treeView;
            if (treeView != null) treeView.Nodes.Clear();            

            ZApplication app = new ZApplication();            
            _unresolved = new List<Unresolved>();

            XmlNode rootElement = xmlDocument.DocumentElement;
            if (rootElement != null)
            {                
                if (treeView != null)                
                    ProcessNode(app, null, treeView.Nodes, rootElement);
                else
                    ProcessNode(app, null, null, rootElement);
            }
            foreach(var unres in _unresolved)
            {
                ZComponent target = ZComponent.App.Find(unres.value);
                if (target != null)                                   
                    unres.prop.SetValue(unres.comp, target);                
                else
                    Console.WriteLine("Unresolved field: {0} - {1}", unres.prop.FieldType.Name, unres.value);
            }
            _unresolved.Clear();
            if (treeView != null)
            {
                treeView.xmlDocument = xmlDocument;
                treeView.ExpandAll();
                treeView.Invalidate();
            }

            return app;
        }
Exemplo n.º 3
0
        /// <summary>Creates a 800x600 window with the specified title.</summary>
        public Standalone(ZApplication _app)
            : base(_app.Width, _app.Height, _app.Mode, _app.Title)
        {
            app = _app;
            app.frame = this;
            VSync = app.VSync;
            this.Title = app.Title;

            Keyboard.KeyDown += Keyboard_KeyDown;
            Keyboard.KeyUp += Keyboard_KeyUp;
            Mouse.ButtonDown += Mouse_ButtonDown;
            Mouse.ButtonUp += Mouse_ButtonUp;
            Mouse.Move += Mouse_Move;
            Mouse.WheelChanged += Mouse_WheelChanged;
        }
Exemplo n.º 4
0
        // This is used for on-the-fly code compilation (similar to an incremental build)
        internal ZApplication RecompileApplication(XmlDocument xmlDoc, Dictionary<XmlNode, string> nodeMap, ZApplication oldApp)
        {
            if (xmlDoc == null || oldApp == null) return null;
            
            string code = GenerateCodeFromXml(xmlDoc, false, false, nodeMap);

            var res = BuildAssembly("dummy", code, true);
            if (res.Errors.HasErrors)
            {
                return null;
            }
            else
            {
//                 foreach (Model gameObj in project.app.modelList)
//                 {
//                     Console.WriteLine("GO found: {0} - {1} Proto: {2} {3}", gameObj.GetType().Name, gameObj.Name, gameObj.Prototype.ToString(), gameObj.GUID);                
//                 }


                // If there weren't any errors, create an instance of "CustomGame"
                var type = res.CompiledAssembly.GetType("ZGE.CustomGame");
                var app = (ZApplication) Activator.CreateInstance(type);
                if (app != null)
                {                      
                    ZComponent.App = app;  // Just to make sure
                    MethodInfo mi = type.GetMethod("RestoreComponents");
                    if (mi != null)
                    {                        
                        mi.Invoke(app, new object[] { oldApp });
                        Console.WriteLine("ZApplication recompiled, components updated.");
                    }
                    else
                        Console.WriteLine("The \"RestoreComponents\" method is missing, components cannot be updated :(");

                    return app;                   

                    /*foreach (var pair in codeMap)
                    {                        
                        MethodInfo mi = type.GetMethod(pair.Value);
                        if (mi != null)
                        {
                            // Bind generated methods to the corresponding code components
                            Console.WriteLine("Setting callback: " + pair.Value);
                            pair.Key.callback = (ZCode.ModelMethod) Delegate.CreateDelegate(typeof(ZCode.ModelMethod), behavior, mi);
                        }
                    }*/                    
                }
                else
                    Console.WriteLine("Recompiled ZApplication cannot be instantiated :(");
            }
            return null;
        }        
Exemplo n.º 5
0
 private void closeProject(bool fullClear)
 {
     Application.Idle -= Application_Idle;
     SelectedComponent = null;
     if (fullClear) this.Text = DefaultFormTitle;
     sceneTreeView.Nodes.Clear();
     //sceneTreeView.Invalidate();
     xmlTree.Nodes.Clear();
     xmlTree.Invalidate();
     if (fullClear)
     {
         project = null;
         xmlTree.SetProject(null);
     }
     else
         project.ClearCode();
     app = null;
     ZComponent.App = null;
     codeBox.Text = "";
     codeBox.Refresh();
     SetCodeLabels(null);
     // TODO: All resources should be released at this point / verify finalizers!
 }
Exemplo n.º 6
0
        internal void SetApplication(bool fullClear)
        {
            app = project.app;
            if (app != null)
            {
                SetFormTitle();
                app.Scene.CollectionChanged -= Scene_CollectionChanged;
                app.Scene.CollectionChanged += Scene_CollectionChanged;

                if (fullClear)
                {
                    glControl1.VSync = (app.VSync == VSyncMode.On);
                    Application.Idle -= Application_Idle;
                    Application.Idle += Application_Idle;
                }                
            }            
        }
Exemplo n.º 7
0
        public bool RecompileApplication(CodeGenerator codeGen, ZTreeView treeView)
        {
            if (xmlDoc == null || app == null) return false;
            ZApplication newApp = codeGen.RecompileApplication(xmlDoc, nodeMap, app);
            if (newApp != null)
            {
                app = newApp;
                
                //if (treeView != null) FillTreeView(treeView);

                return true;
            }
            return false;
        }
Exemplo n.º 8
0
 public void BuildApplication(CodeGenerator codeGen)
 {
     if (xmlDoc == null) return;
     app = codeGen.CreateApplication(xmlDoc, true);
     if (app != null) app.Load(); // load the app to create its components
     nodeMap = codeGen.nodeMap;  // we need the GUIDs in the nodeMap for recompilation
 }
Exemplo n.º 9
0
 public void Reset(ZTreeView treeView, CodeGenerator codeGen)
 {
     app = null;
     BuildApplication(codeGen);
     if (treeView != null) FillTreeView(treeView);
 }