/// <summary> /// Run or debug the currently active tab. /// </summary> /// <param name="s"></param> /// <param name="ev"></param> private void toolBtnRunDebug_Click(object s, EventArgs ev) { // if no tab page is selected nothing needs to be compiled if (SelectedTab == null) return; CompiledEditor = (CodeEditor)SelectedTab.Controls[0]; // save code toolBtnSave_Click(s, null); // clear scene and output output.Rows.Clear(); glControl.ClearScene(); glControl.RemoveEvents(); // get include directory var includeDir = (SelectedTab.FilePath != null ? Path.GetDirectoryName(SelectedTab.FilePath) : Directory.GetCurrentDirectory()) + Path.DirectorySeparatorChar; // get code text form tab page // generate debug information? var debugging = s == toolBtnDbg; // COMPILE THE CURRENTLY SELECTED FILE var root = Compiler.Compile(SelectedTab.FilePath); // INSTANTIATE THE CLASS WITH THE SPECIFIED ARGUMENTS (collect all errors) var ex = root.Catch(x => glControl.AddObject(x, debugging)).ToArray(); // add events to the end of the event list glControl.AddEvents(); glControl.MouseUp += new MouseEventHandler(glControl_MouseUp); // show errors var exc = from x in ex where x is CompileException || x.InnerException is CompileException select (x is CompileException ? x : x.InnerException) as CompileException; var err = from x in exc from y in x select y; var line = from x in err select x.Line; err.ForEach(line, (e, l) => AddOutputItem(includeDir, e.File, l + 1, e.Msg)); // underline all debug errors var ranges = line.Select(x => new[] { CompiledEditor.Lines[x].Position, CompiledEditor.Lines[x].EndPosition }); CompiledEditor.ClearIndicators(CodeEditor.DebugIndicatorIndex); CompiledEditor.AddIndicators(CodeEditor.DebugIndicatorIndex, ranges); // SHOW SCENE glControl.Render(); // add externally created textures to the scene var existing = glControl.Scene.Values.ToArray(); GLImage.FindTextures(existing).ForEach(x => glControl.Scene.Add(x.name, x)); // add externally created buffers to the scene GLBuffer.FindBuffers(existing).ForEach(x => glControl.Scene.Add(x.name, x)); // UPDATE DEBUG DATA comboBuf.Items.Clear(); comboImg.Items.Clear(); comboProp.Items.Clear(); glControl.Scene.Where(x => x.Value is GLBuffer).ForEach(x => comboBuf.Items.Add(x.Value)); glControl.Scene.Where(x => x.Value is GLImage).ForEach(x => comboImg.Items.Add(x.Value)); glControl.Scene.Where(x => x.Value is GLInstance).ForEach(x => comboProp.Items.Add(x.Value)); // UPDATE DEBUG INFORMATION IF NECESSARY if (debugging) UpdateDebugListView(CompiledEditor); }