Esempio n. 1
0
        public void Render(IGameContext gameContext, IRenderContext renderContext)
        {
#if PLATFORM_WINDOWS
            Microsoft.Xna.Framework.Graphics.GraphicsDebugMessage message;

            if (renderContext.GraphicsDevice.GraphicsDebug != null)
            {
                while (renderContext.GraphicsDevice.GraphicsDebug.TryDequeueMessage(out message))
                {
                    switch (message.Severity)
                    {
                    case "Corruption":
                    case "Error":
                        _consoleHandle.LogError("DX11 ({0}) ({1}, {2}): {3}", message.Severity, message.Category, message.IdName, message.Message);
                        break;

                    case "Warning":
                        _consoleHandle.LogWarning("DX11 ({0}) ({1}, {2}): {3}", message.Severity, message.Category, message.IdName, message.Message);
                        break;

                    case "Information":
                        _consoleHandle.LogDebug("DX11 ({0}) ({1}, {2}): {3}", message.Severity, message.Category, message.IdName, message.Message);
                        break;
                    }
                }
            }
#endif
        }
Esempio n. 2
0
        private void FlushLogs()
        {
            var logs = _logShipping.GetAndFlushLogs();

            foreach (var l in logs)
            {
                switch (l.LogLevel)
                {
                case ConsoleLogLevel.Debug:
                    _consoleHandle.LogDebug(l.Message);
                    break;

                case ConsoleLogLevel.Info:
                    _consoleHandle.LogInfo(l.Message);
                    break;

                case ConsoleLogLevel.Warning:
                    _consoleHandle.LogWarning(l.Message);
                    break;

                case ConsoleLogLevel.Error:
                    _consoleHandle.LogError(l.Message);
                    break;
                }
            }
        }
 public override Task<LogResponse> LogError(LogRequest request, ServerCallContext context)
 {
     return Task.Run(() =>
     {
         _consoleHandle.LogError(request.Message);
         return Task.FromResult(_logResponse);
     });
 }
Esempio n. 4
0
        public async Task <List <RecentProject> > GetRecentProjects(IRenderContext renderContext)
        {
            var recentProjectsFile = Path.Combine(_editorUserDataPathProvider.GetPath().FullName, "RecentProjects.txt");
            var recentProjectPaths = new List <string>();

            if (!File.Exists(recentProjectsFile))
            {
                return(new List <RecentProject>());
            }

            using (var reader = new StreamReader(recentProjectsFile))
            {
                while (!reader.EndOfStream)
                {
                    var dir = (await reader.ReadLineAsync()).Trim();
                    if (Directory.Exists(dir) && File.Exists(Path.Combine(dir, "Build", "Module.xml")))
                    {
                        recentProjectPaths.Add(dir);
                    }
                }
            }

            return(recentProjectPaths.Select(path =>
            {
                var document = new XmlDocument();
                document.Load(Path.Combine(path, "Build", "Module.xml"));
                var name = document.SelectSingleNode("/Module/Name").InnerText.Trim();

                var thumbnailPath = Path.Combine(path, "Build", "Editor", "Thumbnail.png");
                Texture2D tex = null;
                if (File.Exists(thumbnailPath))
                {
                    try
                    {
                        using (var stream = new FileStream(thumbnailPath, FileMode.Open, FileAccess.Read))
                        {
                            tex = Texture2D.FromStream(renderContext.GraphicsDevice, stream);
                            _loadedTextures.Add(tex);
                        }
                    }
                    catch (Exception ex)
                    {
                        // Ignore invalid thumbnails.
                        _consoleHandle.LogError(ex);
                    }
                }

                return new RecentProject
                {
                    Name = name,
                    Path = path,
                    Thumbnail = tex
                };
            }).ToList());
        }
Esempio n. 5
0
        private void LogExceptions(string name, Exception e)
        {
            var aggregateException = e as AggregateException;

            if (aggregateException != null)
            {
                foreach (var ie in aggregateException.InnerExceptions)
                {
                    LogExceptions(name, ie);
                }
            }
            else
            {
                _consoleHandle.LogError(name + ": " + e.Message);
            }
        }
        public GenericToolbarEntry[] GetToolbarItems()
        {
            if (_updateMenuItems == null || _updateMenuItems.IsCompleted)
            {
                _updateMenuItems = Task.Run(async() =>
                {
                    var items = new List <GenericToolbarEntry>();
                    foreach (var ext in _extensionManager.Extensions)
                    {
                        var toRemove = new List <WeakReference <Extension.Extension> >();
                        if (_ignoredExtensions.Any(x =>
                        {
                            Extension.Extension oext;
                            if (x.TryGetTarget(out oext))
                            {
                                return(oext == ext);
                            }
                            else
                            {
                                toRemove.Add(x);
                            }
                            return(false);
                        }))
                        {
                            continue;
                        }
                        _ignoredExtensions.RemoveAll(toRemove.Contains);

                        var client = ext.GetClient <Grpc.ExtensionHost.ToolbarEntries.ToolbarEntriesClient>();
                        RepeatedField <Grpc.ExtensionHost.GenericToolbarItem> rawItems;
                        try
                        {
                            var result = await client.GetToolbarItemsAsync(new Grpc.ExtensionHost.GetToolbarItemsRequest());
                            rawItems   = result.ToolbarItems;
                        }
                        catch (Exception ex)
                        {
                            _consoleHandle.LogError(ex);
                            _ignoredExtensions.Add(new WeakReference <Extension.Extension>(ext));
                            continue;
                        }
                        items.AddRange(rawItems.Select(y =>
                        {
                            ToolbarClickHandler clickCallback = e =>
                            {
                                Task.Run(async() =>
                                {
                                    try
                                    {
                                        await client.ToolbarItemClickedAsync(new Grpc.ExtensionHost.ToolbarItemClickedRequest {
                                            ToolbarId = y.Id
                                        });
                                    }
                                    catch (Exception ex)
                                    {
                                        _consoleHandle.LogError(ex);
                                    }
                                });
                            };
                            return(new GenericToolbarEntry(y.Id, y.Icon, y.Toggled, y.Enabled, clickCallback, null));
                        }));
                    }
                    _menuItems = items.ToArray();
                    await Task.Delay(1000);
                });
            }

            return(_menuItems);
        }
 public void LogError(string messageFormat)
 {
     _realImpl.LogError(messageFormat);
 }
        public void Update(IGameContext gameContext, IUpdateContext updateContext)
        {
            if (_requiresDelaySync && _gameHostClient != null)
            {
                SendTexturesToGameHost();
                _requiresDelaySync = false;
            }

            if (_projectManager.Project == null ||
                _projectManager.Project.DefaultGameBinPath == null)
            {
                return;
            }

            if (!_projectManager.Project.DefaultGameBinPath.Exists)
            {
                return;
            }

            if (_process == null ||
                _process.HasExited ||
                // TODO: Use file watcher...
                (_executingFile != null && _executingFile.LastWriteTimeUtc != new FileInfo(_executingFile.FullName).LastWriteTimeUtc) ||
                _shouldDebug ||
                _shouldRestart)
            {
                var extHostPath      = Path.Combine(new FileInfo(Assembly.GetExecutingAssembly().Location).DirectoryName, "Protogame.Editor.GameHost.exe");
                var processStartInfo = new ProcessStartInfo
                {
                    FileName  = extHostPath,
                    Arguments =
                        (_shouldDebug ? "--debug " : "") +
                        "--track " + Process.GetCurrentProcess().Id +
                        " --editor-url " + _grpcServer.GetServerUrl() +
                        " --assembly-path \"" + _projectManager.Project.DefaultGameBinPath.FullName + "\"",
                    WorkingDirectory       = _projectManager.Project.DefaultGameBinPath.DirectoryName,
                    UseShellExecute        = false,
                    RedirectStandardOutput = true,
                    RedirectStandardError  = true,
                    CreateNoWindow         = true
                };
                // Update last write time.
                _baseDirectory = _projectManager.Project.DefaultGameBinPath.DirectoryName;
                _executingFile = new FileInfo(_projectManager.Project.DefaultGameBinPath.FullName);
                _shouldDebug   = false;
                _shouldRestart = false;
                if (_process != null)
                {
                    try
                    {
                        _process.EnableRaisingEvents = false;
                        _process.Kill();
                    }
                    catch { }
                    _consoleHandle.LogDebug("Game host process was killed for reload: {0}", _projectManager.Project.DefaultGameBinPath.FullName);
                    _process         = null;
                    _channel         = null;
                    _gameHostClient  = null;
                    _loadedGameState = null;
                    // The process may have exited mid-draw, which could keep a texture locked.  Destroy
                    // the textures and recreate them to ensure they're not locked.
                    _sharedRendererHost.DestroyTextures();
                }
                _process         = Process.Start(processStartInfo);
                _process.Exited += (sender, e) =>
                {
                    _consoleHandle.LogWarning("Game host process has unexpectedly quit: {0}", _projectManager.Project.DefaultGameBinPath.FullName);
                    _process         = null;
                    _channel         = null;
                    _gameHostClient  = null;
                    _loadedGameState = null;
                    // The process may have exited mid-draw, which could keep a texture locked.  Destroy
                    // the textures and recreate them to ensure they're not locked.
                    _sharedRendererHost.DestroyTextures();
                };
                _process.OutputDataReceived += (sender, e) =>
                {
                    if (e.Data == null)
                    {
                        return;
                    }
                    if (_channel != null)
                    {
                        _consoleHandle.LogDebug(e.Data);
                        return;
                    }

                    var editorGrpcServer = _grpcServer.GetServerUrl();
                    _consoleHandle.LogDebug("Editor gRPC server is {0}", editorGrpcServer);

                    var url = e.Data?.Trim();
                    _consoleHandle.LogDebug("Creating gRPC channel on {0}...", url);
                    _channel           = new Channel(url, ChannelCredentials.Insecure);
                    _gameHostClient    = new GameHostServerClient(_channel);
                    _requiresDelaySync = true;

                    if (_runAfterRestart)
                    {
                        _gameHostClient?.SetPlaybackMode(new SetPlaybackModeRequest
                        {
                            Playing = true
                        });

                        _runAfterRestart = false;
                    }
                };
                _process.ErrorDataReceived += (sender, e) =>
                {
                    if (e.Data != null)
                    {
                        _consoleHandle.LogError(e.Data);
                    }
                };
                _process.EnableRaisingEvents = true;
                _process.BeginErrorReadLine();
                _process.BeginOutputReadLine();
            }
        }
Esempio n. 9
0
 public void Error(string message)
 {
     _consoleHandle.LogError(message);
 }
 public void LogError(string messageFormat)
 {
     _consoleHandle.LogError(messageFormat);
 }