void Load(string DefFile) { string[] Lines = File.ReadAllLines(DefFile); RelativeSpawns = new List <Vector3>(); foreach (var L in Lines) { string[] Args = L.Trim().Split(' '); switch (Args[0].ToLower()) { case "model": WorldModel = Importers.Load <Model>(Args[1]); break; case "spawn": RelativeSpawns.Add(new Vector3(Args[1].ParseToFloat(), Args[2].ParseToFloat(), Args[3].ParseToFloat())); break; default: GConsole.WriteLine("Invalid world argument: {0}", L); break; } } if (WorldModel == null) { throw new Exception("World model was not loaded"); } }
/// <summary> /// Parse a simple command with one parameter and no flags. /// </summary> /// <param name="line">Input line.</param> /// <param name="command">Command to parse.</param> /// <param name="parameter">Out paremeter parsed from input.</param> /// <returns>Result of the parsing. /// Possible result types are Success, WrongCommand, MissingParam and ParsingFailure. /// See ParsingResult.</returns> public static ParsingResult ParseSimpleCommandWithOneParameter(string line, ICommand command, out string parameter) { parameter = ""; string remainder = ""; var result = ParseSimpleCommandBody(line, command, out remainder); if (result.Type == ParsingResultType.SuccessReachedEnd) { result.Type = ParsingResultType.MissingParam; GConsole.WriteLine(-1.0f, Resources.text.MissingParam, command.Name()); return(result); } if (result.Type != ParsingResultType.Success) { return(result); } var paramResult = TryTextParam(remainder); if (paramResult.WasSuccessful == false || paramResult.Remainder.AtEnd == false) { GConsole.WriteLine(Resources.text.FailureParsingRequiredParam, command.Name()); result.Type = ParsingResultType.ParsingFailure; return(result); } parameter = paramResult.Value; result.Type = ParsingResultType.Success; return(result); }
Material ConvertMaterial(AssimpMaterial M) { Material Mat = new Material(); if (M.HasColorDiffuse) { Mat.DiffuseColor = new Vector4(M.ColorDiffuse.R, M.ColorDiffuse.G, M.ColorDiffuse.B, M.ColorDiffuse.A); } if (M.HasTextureDiffuse) { string TexName = ("content/textures/" + M.TextureDiffuse.FilePath).NormalizeFilePath(); Mat.Name = TexName; if (File.Exists(TexName)) { Mat.Diffuse = Importers.Load <Texture>(TexName); Mat.Diffuse.SetWrap(OpenGL.Gl.REPEAT); Mat.Diffuse.SetFilter(OpenGL.Gl.LINEAR_MIPMAP_LINEAR, OpenGL.Gl.NEAREST); Mat.Diffuse.GenerateMipmap(); } else { GConsole.WriteLine("Unknown texture: {0}", TexName); } } return(Mat); }
internal void ParseLine(string line) { ParsingResult result = new ParsingResult(); foreach (var command in KnownCommands) { result = command.Parse(line); if (result.Type == ParsingResultType.Success || result.Type == ParsingResultType.SuccessReachedEnd || result.Type == ParsingResultType.ParsingFailure || result.Type == ParsingResultType.MissingParam) { break; } } if (result.Type == ParsingResultType.WrongCommand) { string command = line; var parsingResult = ParsingHelpers.TryAnyCommandBody(line); if (parsingResult.WasSuccessful && parsingResult.Value.Length > 0) { command = parsingResult.Value; } GConsole.WriteLine(GConsole.ColorifyText(1, String.Format(Resources.text.UnknownCommand, command))); } }
private static void InitPatches() { // Don't need to try running the loop if the list is null or there aren't any files in it. if (options.PatchFiles == null || options.PatchFiles.Count < 1) { return; } for (int i = 0; i < options.PatchFiles.Count; i++) { ILumpContainer container = null; string file = options.PatchFiles [i]; if (File.Exists(file)) { if (ZipLumpContainer.CheckContainer(file)) { container = new ZipLumpContainer(file); } } if (container != null) { GConsole.WriteLine(" Adding \"{0}\", {1} lumps", file, container.Count); LumpManager.AddContainer(container); } else { throw new FatalError(string.Format("Could not identify patch {0}. Stopping execution.", file)); } } }
public void PrintManPage() { GConsole.WriteLine(-1.0f, "{0} {1}", GConsole.ColorifyText(1, Resources.text.ManHeaderIntro), GConsole.ColorifyText(1, Name())); GConsole.WriteLine(-1.0f, GConsole.ColorifyText(1, Resources.text.ManHeaderName)); GConsole.WriteLine(-1.0f, "\t{0}", GConsole.ColorifyText(0, Name())); GConsole.WriteLine(-1.0f, GConsole.ColorifyText(1, Resources.text.ManHeaderSynopsis)); GConsole.WriteLine(-1.0f, "\t{0}", GConsole.ColorifyText(0, Name())); GConsole.WriteLine(-1.0f, GConsole.ColorifyText(1, Resources.text.ManHeaderDescription)); GConsole.WriteLine(-1.0f, GConsole.ColorifyText(1, Resources.text.ListMan)); GConsole.WriteLine(-1.0f, " "); }
/// <summary> /// Parse a simple command with flags and no paramters. /// </summary> /// <param name="line">Input line.</param> /// <param name="command">Command to parse.</param> /// <param name="flags">Out Flags containted in the input line. See BoolFlag.</param> /// <returns>Result of the parsing. /// Possible result types are Success, WrongCommand and ParsingFailure. /// See ParsingResult.</returns> public static ParsingResult ParseSimpleCommandWithFlags(string line, ICommand command, out IEnumerable <BoolFlag> flags) { string remainder = ""; var resultFlags = new List <BoolFlag>(); flags = resultFlags; var result = ParseSimpleCommandBody(line, command, out remainder); // Flags are optional if (result.Type == ParsingResultType.SuccessReachedEnd) { result.Type = ParsingResultType.Success; return(result); } var flagsResult = ParsingHelpers.TryFlags(remainder); if (flagsResult.WasSuccessful == false || flagsResult.Remainder.AtEnd == false) { GConsole.WriteLine(Resources.text.FailureParsingFlags, remainder, command.Name()); result.Type = ParsingResultType.ParsingFailure; return(result); } var parsedFlags = flagsResult.Value.ToList(); foreach (var flag in command.GetFlags()) { if (flag.FindInList(ref parsedFlags)) { resultFlags.Add(flag); } } flags = resultFlags; if (parsedFlags.Count > 0) { GConsole.WriteLine(Resources.text.UnknownFlags, String.Join(",", parsedFlags), command.Name()); result.Type = ParsingResultType.ParsingFailure; return(result); } result.Type = ParsingResultType.Success; return(result); }
public override void Load() { AddButton("Exit", () => Engine.CreateYesNoPrompt("Exit Program?", () => Environment.Exit(0)).Center((Engine.Window.WindowSize / 2))); AddButton("Stop", RealSenseCamera.Stop); AddButton("Start", RealSenseCamera.Start); Engine.Camera3D.SetPerspective(Engine.Window.WindowSize, (90.0f).ToRad(), NearClip, 100); LegShader = new ShaderProgram(new ShaderStage(ShaderType.VertexShader, "content/shaders/leg.vert"), new ShaderStage(ShaderType.FragmentShader, "content/shaders/leg.frag")); VertsMesh = new Mesh3D(); VertsMesh.PrimitiveType = PrimitiveType.Points; VertsMesh.SetVertices(new Vertex3()); // Variables Sparse = ConVar.Register(nameof(Sparse).ToLower(), 0); // 3 LegLength = ConVar.Register(nameof(LegLength).ToLower(), 100.0f); // 1.0f LegWidth = ConVar.Register(nameof(LegWidth).ToLower(), 100.0f); // 0.5f PickDistance = ConVar.Register(nameof(PickDistance).ToLower(), 1.0f); PickSize = ConVar.Register(nameof(PickSize).ToLower(), 0.01f); // 0.025f PickSampleNum = ConVar.Register(nameof(PickSampleNum).ToLower(), 10); // 10 ConCmd.Register("list", (Argv) => { GConsole.WriteLine(Sparse); GConsole.WriteLine(LegLength); GConsole.WriteLine(LegWidth); GConsole.WriteLine(PickDistance); GConsole.WriteLine(PickSize); GConsole.WriteLine(PickSampleNum); }); Thread PollingThread = new Thread(() => { while (true) { RealSenseCamera.PollForFrames(OnPointCloud: OnPointCloud); Thread.Sleep(0); } }); PollingThread.IsBackground = true; PollingThread.Start(); Engine.Camera3D.Position = new Vector3(0, 0, -1); Engine.Camera3D.LookAt(Vector3.Zero); Engine.Camera3D.Position = new Vector3(0, 0, -NearClip); }
public ParsingResult Parse(string line) { string parameter = ""; var result = ParsingHelpers.ParseSimpleCommandWithOneParameter(line, this, out parameter); if (result.Type == ParsingResultType.Success) { if (GConsole.Instance.Commands.FindMan(parameter) == false) { if (GConsole.Instance.Keywords.FindMan(parameter) == false) { GConsole.WriteLine(GConsole.ColorifyText(1, String.Format(Resources.text.UnknownCommandOrKeywordForMan, parameter))); } } } return(result); }
public override void Load() { FontTest = new MSDFFont("content/fonts/Hack.ttf"); CrosshairTex = Importers.Load <Texture>("content/textures/crosshair_default.png"); /*MSDF = new ShaderProgram(new ShaderStage(ShaderType.VertexShader, "content/shaders/default.vert"), * new ShaderStage(ShaderType.FragmentShader, "content/shaders/msdf.frag"));*/ Ply = new Player(); Engine.SpawnEntity(Ply); GameWorld = new World("content/maps/sandbox.txt"); Ply.Position = GameWorld.RelativeSpawns.FirstOrDefault(); Engine.SpawnEntity(GameWorld); GConsole.RegisterCommand("getcam", () => { GConsole.WriteLine("Pos: " + Ply.Position.ToString()); }); }
public void PrintManPage() { GConsole.WriteLine(-1.0f, "{0} {1}", GConsole.ColorifyText(1, Resources.text.ManHeaderIntro), GConsole.ColorifyText(0, Name())); GConsole.WriteLine(-1.0f, GConsole.ColorifyText(1, Resources.text.ManHeaderName)); GConsole.WriteLine(-1.0f, "\t{0}", GConsole.ColorifyText(1, Name())); GConsole.WriteLine(-1.0f, GConsole.ColorifyText(1, Resources.text.ManHeaderSynopsis)); GConsole.WriteLine(-1.0f, "\t{0} {1}", GConsole.ColorifyText(0, Name()), GConsole.ColorifyText(ConsoleColor.Black, GConsole.Settings.Higlights[0].Foreground, "command")); GConsole.WriteLine(-1.0f, GConsole.ColorifyText(1, Resources.text.ManHeaderDescription)); foreach (var line in Resources.text.ManMan.Split(new string[] { Environment.NewLine }, StringSplitOptions.None)) { GConsole.WriteLine(-1.0f, line); } GConsole.WriteLine(-1.0f, " "); }
public ParsingResult Parse(string line) { var result = ParsingHelpers.ParseSimpleCommand(line, this); if (result.Type == ParsingResultType.Success) { GConsole.WriteLine(-1.0f, "{0} {1} {2}", GConsole.ColorifyText(1, "Currently available commands follow. You can use"), GConsole.ColorifyText(0, Resources.text.ManCommandName), GConsole.ColorifyText(1, "to learn more about them.")); foreach (var command in GConsole.Instance.Commands) { if (command.Available() == true) { GConsole.WriteLine(-1.0f, "\t{0}", GConsole.ColorifyText(0, command.Name())); } } } return(result); }
/*void UpdateCamera(Camera C) { * UniformMatrix4f("View", C.View); * UniformMatrix4f("Project", C.Projection); * }*/ public override void Bind() { if (Camera.ActiveCamera == null) { throw new Exception("No active camera"); } bool Dirty = false; bool Errors = false; foreach (var SS in ShaderStages) { if (SS.WatchHandle) { SS.WatchHandle.Reset(); Dirty = true; if (!SS.Compile(out string Err)) { Errors = true; GConsole.WriteLine(Err); } } } if (Dirty && !Errors) { Link(); } SetModelMatrix(Matrix4.Identity); Uniform2f("Viewport", Camera.ActiveCamera.ViewportSize); UniformMatrix4f("View", Camera.ActiveCamera.View); UniformMatrix4f("Project", Camera.ActiveCamera.Projection); Gl.UseProgram(ID); }
/// <summary> /// Parse a command with parameters and flags. /// </summary> /// <param name="line">Input line.</param> /// <param name="command">Command to parse.</param> /// <param name="hasRequiredParams">Whether the command has at least on required parameters.</param> /// <returns>Result of the parsing. /// Possible result types are Success, WrongCommand, MissingParam and ParsingFailure. /// It splits all the parameters by space into ParsingResult.Parameters. /// See ParsingResult.</returns> public static ParsingResult ParseCommand(string line, ICommand command, bool hasRequiredParams) { string remainder = ""; var result = ParseSimpleCommandBody(line, command, out remainder); if (result.Type == ParsingResultType.SuccessReachedEnd) { if (hasRequiredParams == true) { result.Type = ParsingResultType.MissingParam; GConsole.WriteLine(-1.0f, Resources.text.MissingParam, command.Name()); return(result); } else { result.Type = ParsingResultType.Success; return(result); } } if (result.Type != ParsingResultType.Success) { return(result); } var paramResult = TryTextParam(remainder); if (paramResult.WasSuccessful == false && hasRequiredParams == true) { GConsole.WriteLine(Resources.text.FailureParsingRequiredParam, command.Name()); result.Type = ParsingResultType.ParsingFailure; return(result); } string parameters = paramResult.Value.TrimEnd(); result.Parameters = parameters.Split(new char[] { ' ', '\t' }).ToList(); if (paramResult.Remainder.AtEnd == true) { result.Type = ParsingResultType.Success; return(result); } remainder = remainder.Substring(paramResult.Remainder.Position - 1).TrimEnd(); var flagsResult = ParsingHelpers.TryFlags(remainder); if (flagsResult.WasSuccessful == false || flagsResult.Remainder.AtEnd == false) { GConsole.WriteLine(Resources.text.FailureParsingFlags, remainder, command.Name()); result.Type = ParsingResultType.ParsingFailure; return(result); } var parsedFlags = flagsResult.Value.ToList(); foreach (var flag in command.GetFlags()) { if (flag.FindInList(ref parsedFlags)) { result.Flags.Add(flag); } } if (parsedFlags.Count > 0) { GConsole.WriteLine(Resources.text.UnknownFlags, String.Join(",", parsedFlags), command.Name()); result.Type = ParsingResultType.ParsingFailure; return(result); } result.Type = ParsingResultType.Success; return(result); }
public static void Run(string [] args) { long ticDelta = 0, renderDelta = 0; double fpsTime; if (closing) { return; } if (!CommandLine.Parser.Default.ParseArguments(args, options)) { GConsole.WriteLine("Fatal error: There was an error reading the argument list"); Console.Read(); return; } try { /*Data.UDMF.UDMFParser udmfParser = new Data.UDMF.UDMFParser (); * udmfParser.Setup (); * * using (var reader = new StreamReader ("TEXTMAP.txt")) * udmfParser.Parse (reader); * * Console.ReadKey (); * return;*/ GConsole.WriteLine("Core: Loading engine.PK3"); ZipLumpContainer container = null; string engPK3File = Path.GetFullPath(Path.Combine(Constants.ProgDir, @"engine.pk3")); if (File.Exists(engPK3File)) { if (ZipLumpContainer.CheckContainer(engPK3File)) { container = new ZipLumpContainer(engPK3File); } } if (container == null) { throw new FatalError(String.Format("Could not load engine.PK3. Stopping execution.")); } GConsole.WriteLine(" engine.PK3, {0} lumps", container.Count); LumpManager.AddContainer(container); GConsole.WriteLine("Core: Initializing patches"); InitPatches(); GConsole.WriteLine("Core: Generating fixed-point Sin/Cos/Atan LUTs"); FixedMath.GenerateTables(); GConsole.WriteLine("Core: Initializing video"); RenderEngine = OpenTkRenderer.Default; RenderEngine.Initialize(800, 600, false); RenderEngine.OnFocusChange += Renderer_OnFocusChange; GConsole.WriteLine("Core: Initializing playsim"); Ticker = new Ticker(); Ticker.Initialize(); GConsole.WriteLine("Core: Starting game loop"); ticClock.Reset(); ticClock.Start(); renderClock.Reset(); renderClock.Start(); while (true) { if (closing) { return; } if (ticClock.ElapsedMilliseconds >= Constants.MsecsPerTic) { ticDelta = ticClock.ElapsedMilliseconds; ticClock.Restart(); Ticker.Update(ticDelta); Input.ClearTotals(); } Input.UpdateInput(); renderDelta = renderClock.ElapsedMilliseconds; renderClock.Restart(); fpsClock.Restart(); RenderEngine.Render(renderDelta); fpsTime = fpsClock.ElapsedMilliseconds; if (RenderEngine.IsUsable()) { RenderEngine.WindowTitle = String.Format("Frame time: {0} ms", fpsTime); } } } catch (FatalError err) { DisposeResources(); GConsole.WriteLine(err.Message); Console.ReadKey(); } catch (VeryFatalError err) { DisposeResources(); GConsole.WriteLine(err.Message); Console.ReadKey(); } }