Lots of progress on rendering textures.

This commit is contained in:
2020-06-05 23:49:45 -05:00
parent 23597f02b1
commit 1c4ca6c97b
47 changed files with 620 additions and 246 deletions

View File

@@ -1,9 +1,9 @@
using System;
using System.Collections;
using System.Collections.Generic;
using SlatedGameToolkit.Tools.System.Interaction;
using SlatedGameToolkit.Tools.CommandSystem.Interaction;
namespace SlatedGameToolkit.Tools.System
namespace SlatedGameToolkit.Tools.CommandSystem
{
public class CommandMap : ICollection<IInvocable>, IDisposable {
Dictionary<string, IInvocable> invocations;

View File

@@ -1,22 +1,19 @@
using System;
using SlatedGameToolkit.Tools.System.Interaction;
using SlatedGameToolkit.Tools.CommandSystem.Interaction;
namespace SlatedGameToolkit.Tools.System
namespace SlatedGameToolkit.Tools.CommandSystem
{
public class CommandProcessor
{
private string generalHelpMessage;
CommandMap commandMap;
/// <summary>
/// The general help is the string that is printed when the input is not understood.
/// {input} in the string is replaced with the user input.
/// </summary>
/// <param name="generalHelp"></param>
/// <param name="commands"></param>
public CommandProcessor(string generalHelp, CommandMap commands) {
public CommandProcessor(CommandMap commands) {
this.commandMap = commands;
this.generalHelpMessage = generalHelp;
}
public void Process(IInteractable interactable) {
string message = interactable.Listen();
@@ -27,11 +24,12 @@ namespace SlatedGameToolkit.Tools.System
if (invocable != null) {
string[] args = new string[splitMessage.Length - 1];
Array.Copy(splitMessage, 1, args, 0, splitMessage.Length - 1);
if (invocable.Execute(interactable, args)) {
return;
if (!invocable.Execute(interactable, args)) {
interactable.Tell(string.Format("The command \"{0}\" was recognized, but arguments were incorrect. Please refer to Please type \"help {0}\" for more information.", invocation));
}
return;
}
interactable.Tell(generalHelpMessage.Replace("{input}", invocation));
interactable.Tell(string.Format("The input \"{0}\" was not understood. Please type \"help\" for more information.", invocation));
}
}
}

View File

@@ -0,0 +1,14 @@
using System;
using System.Runtime.Serialization;
namespace SlatedGameToolkit.Tools.CommandSystem.Exceptions
{
[Serializable]
public class FatalUsageException : Exception
{
public FatalUsageException() { }
public FatalUsageException(string message) : base(message) { }
public FatalUsageException(string message, Exception inner) : base(message, inner) { }
protected FatalUsageException(SerializationInfo info, StreamingContext context) : base(info, context) { }
}
}

View File

@@ -1,7 +1,7 @@
using System;
using SlatedGameToolkit.Tools.System.Interaction;
using SlatedGameToolkit.Tools.CommandSystem.Interaction;
namespace SlatedGameToolkit.Tools.System
namespace SlatedGameToolkit.Tools.CommandSystem
{
public interface IInvocable : IDisposable
{

View File

@@ -1,6 +1,6 @@
using System;
namespace SlatedGameToolkit.Tools.System.Interaction
namespace SlatedGameToolkit.Tools.CommandSystem.Interaction
{
public class ConsoleInteraction : IInteractable
{

View File

@@ -1,4 +1,4 @@
namespace SlatedGameToolkit.Tools.System.Interaction
namespace SlatedGameToolkit.Tools.CommandSystem.Interaction
{
public interface IInteractable
{

View File

@@ -0,0 +1,30 @@
using System;
using SlatedGameToolkit.Tools.CommandSystem.Exceptions;
namespace SlatedGameToolkit.Tools.CommandSystem.Interaction
{
public class SingleConsoleInteraction : IInteractable
{
private bool interacted;
private string oneTime;
public SingleConsoleInteraction(string oneTime) {
this.oneTime = oneTime;
}
public string Listen()
{
if (interacted) throw new FatalUsageException("Command attempted to request for more information. This generally occurs if the command being ran requires more user input.");
interacted = true;
return oneTime;
}
public void Separate()
{
Console.WriteLine();
}
public void Tell(string message)
{
Console.WriteLine(message);
}
}
}

View File

@@ -1,8 +1,8 @@
using SlatedGameToolkit.Framework;
using SlatedGameToolkit.Framework.StateSystem;
using SlatedGameToolkit.Tools.System;
using SlatedGameToolkit.Tools.System.Interaction;
using SlatedGameToolkit.Tools.Utilities.GraphicalPlayground;
using SlatedGameToolkit.Tools.CommandSystem;
using SlatedGameToolkit.Tools.CommandSystem.Interaction;
using SlatedGameToolkit.Tools.Utilities.Playground;
namespace SlatedGameToolkit.Tools.Commands
{

View File

@@ -1,7 +1,7 @@
using System;
using System.Text;
using SlatedGameToolkit.Tools.System;
using SlatedGameToolkit.Tools.System.Interaction;
using SlatedGameToolkit.Tools.CommandSystem;
using SlatedGameToolkit.Tools.CommandSystem.Interaction;
namespace SlatedGameToolkit.Tools.Commands
{

View File

@@ -0,0 +1,42 @@
using System.Reflection;
using SlatedGameToolkit.Framework;
using SlatedGameToolkit.Tools.CommandSystem;
using SlatedGameToolkit.Tools.CommandSystem.Interaction;
namespace SlatedGameToolkit.Tools.Commands
{
public class ListEmbeddedResourcesCommand : IInvocable
{
private string[] invokers = new string[] {"GetEmbedded"};
public void Dispose()
{
}
public bool Execute(IInteractable interactable, string[] args)
{
Assembly assembly = Assembly.GetAssembly(typeof(GameEngine));
string[] embeddedFiles = assembly.GetManifestResourceNames();
interactable.Tell("Loaded embedded files:");
foreach (string fileName in embeddedFiles)
{
interactable.Tell(fileName);
}
return true;
}
public string getDescription()
{
return "Returns a list of embedded resources in the given assembly.";
}
public string[] GetInvokers()
{
return invokers;
}
public string getUsage(string arg)
{
return "Usage: \"GetEmbedded\" to retrieve a list of embedded files in the framework and tools.";
}
}
}

View File

@@ -1,5 +1,5 @@
using SlatedGameToolkit.Tools.System;
using SlatedGameToolkit.Tools.System.Interaction;
using SlatedGameToolkit.Tools.CommandSystem;
using SlatedGameToolkit.Tools.CommandSystem.Interaction;
namespace SlatedGameToolkit.Tools.Commands
{

View File

@@ -1,36 +1,43 @@
using System;
using System.Reflection;
using System.Text;
using SlatedGameToolkit.Tools.Commands;
using SlatedGameToolkit.Tools.System;
using SlatedGameToolkit.Tools.System.Interaction;
using SlatedGameToolkit.Tools.CommandSystem;
using SlatedGameToolkit.Tools.CommandSystem.Interaction;
namespace SlatedGameToolkit.Tools
{
class Program
{
static private bool running;
static private bool live;
static void Main(string[] args)
{
CommandMap commands = new CommandMap();
commands.Add(new StopCommand());
commands.Add(new HelpCommand(commands));
commands.Add(new ListEmbeddedResourcesCommand());
commands.Add(new GraphicalPlaygroundCommand());
CommandProcessor processor = new CommandProcessor("The command \"{input}\" was not understood. Please type \"help\" for more information.", commands);
CommandProcessor processor = new CommandProcessor(commands);
AssemblyName name = Assembly.GetExecutingAssembly().GetName();
ConsoleInteraction consoleInteracter = new ConsoleInteraction("Tools");
consoleInteracter.Tell(String.Format("{0} Version: {1}", name.Name, name.Version));
consoleInteracter.Tell("Welcome to SlatedGameToolkit.Tools! These tools are meant for the developers using the SlatedGameToolkit. Type \"help\" for a list of things this tool can currently do.");
running = true;
while (running) {
consoleInteracter.Separate();
processor.Process(consoleInteracter);
IInteractable interactable = (args.Length > 0 ? (IInteractable) new SingleConsoleInteraction(string.Join(' ', args)) : (IInteractable) new ConsoleInteraction("Tools"));
interactable.Tell(String.Format("{0} Version: {1}", name.Name, name.Version));
if (args.Length > 0) {
interactable.Tell("Running in one time use mode.");
processor.Process(interactable);
} else {
interactable.Tell("Welcome to SlatedGameToolkit.Tools! These tools are meant for the developers using the SlatedGameToolkit. Type \"help\" for a list of things this tool can currently do.");
live = true;
while (live) {
interactable.Separate();
processor.Process(interactable);
}
}
consoleInteracter.Tell("Exiting tool.");
interactable.Tell("Exiting tool.");
commands.Dispose();
}
public static void Stop() {
running = false;
live = false;
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

View File

@@ -11,4 +11,7 @@
<Description>A tool to help with developing a game using SlatedGameToolkit.</Description>
</PropertyGroup>
<ItemGroup>
<Content Include="Resources/**"/>
</ItemGroup>
</Project>

View File

@@ -1,18 +1,25 @@
using System;
using System.Drawing;
using System.Numerics;
using SlatedGameToolkit.Framework.Exceptions;
using SlatedGameToolkit.Framework.Graphics.Programs;
using SlatedGameToolkit.Framework.Graphics.Render;
using SlatedGameToolkit.Framework.Graphics.Shaders;
using SlatedGameToolkit.Framework.Graphics.Textures;
using SlatedGameToolkit.Framework.Graphics.Window;
using SlatedGameToolkit.Framework.Loader;
using SlatedGameToolkit.Framework.StateSystem;
using SlatedGameToolkit.Framework.StateSystem.States;
namespace SlatedGameToolkit.Tools.Utilities.GraphicalPlayground
namespace SlatedGameToolkit.Tools.Utilities.Playground
{
public class MainState : IState
{
private WindowContext window;
private GLShaderProgram program;
private Camera2D camera;
private Renderer renderer;
private Texture texture;
private Sprite2D sprite;
public WindowContext CurrentWindow { get { return window;}}
@@ -30,6 +37,9 @@ namespace SlatedGameToolkit.Tools.Utilities.GraphicalPlayground
public void Deinitialize()
{
window.Dispose();
program.Dispose();
texture.Dispose();
renderer.Dispose();
}
public string getName()
@@ -37,14 +47,24 @@ namespace SlatedGameToolkit.Tools.Utilities.GraphicalPlayground
return "main state";
}
public void Initialize(Manager manager)
public void Initialize(StateManager manager)
{
window = new WindowContext("SlatedGameToolkit Playground");
renderer = new Renderer();
camera = new Camera2D();
camera.Width = window.WindowBoundaries.Width;
camera.Height = window.WindowBoundaries.Height;
camera.Position = new Vector2(camera.Width / 2, camera.Height / 2);
program = new GLShaderProgram(new NormalVertexShader(), new NormalFragmentShader());
renderer = new Renderer(camera, program);
texture = new TextureLoader("Resources/Playground/yhdnbgnc.png").Load();
sprite = new Sprite2D(texture, Color.White);
}
public void Render(double delta)
{
OpenGLErrorException.CheckGLErrorStatus();
renderer.Queue(sprite, Matrix4x4.Identity);
renderer.Render();
}
public void Update(double delta)